AWS Bedrock Model Cost Tracking Support
Problem Description
Users integrating AgentOps with AWS Bedrock models are encountering cost tracking failures with the warning:
"Unable to calculate cost - This might be because you're using an unrecognized model."
This prevents essential cost monitoring and budget management for production deployments using AWS Bedrock.
User Impact
Affected Users:
Developers using CrewAI with AWS Bedrock LLM integration
Teams making direct AWS Bedrock API calls
Any framework using Bedrock model identifiers
Business Impact:
❌ No visibility into LLM spending for budget management
❌ Blocks production deployments requiring cost monitoring
❌ Affects AgentOps adoption in AWS-centric environments
❌ Forces manual cost calculation workarounds
Current Behavior
Model Example: bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0
Framework: CrewAI with AWS Bedrock LLM integration
Issue: Cost metrics show as $0.00 with warning message instead of calculated costs
Expected Behavior
AgentOps should automatically recognize AWS Bedrock model identifiers and calculate costs based on current Bedrock pricing:
Input tokens: $3.00 per 1M tokens
Output tokens: $15.00 per 1M tokens
Technical Analysis
Current Cost Tracking Architecture
Core Cost Calculation: app/api/agentops/api/models/span_metrics.py line 277
completion_cost = costs .calculate_cost_by_tokens (tokens , self .model_for_cost , direction )
Model Lookup System: Lines 20-24 in span_metrics.py
MODEL_LOOKUP_ALIASES = {
"sonar-pro" : "perplexity/sonar-pro" ,
"sonar" : "perplexity/sonar" ,
}
TokenCost Integration: Uses tokencost library for model pricing data
app/api/agentops/api/event_handlers.py line 6: from tokencost import TOKEN_COSTS
app/opentelemetry-collector/builder/costs/__init__.py: Model cost management
Root Cause
The tokencost library doesn't include AWS Bedrock model naming patterns like:
bedrock/anthropic.claude-3-5-sonnet-*
bedrock/anthropic.claude-3-sonnet-*
bedrock/anthropic.claude-3-haiku-*
Proposed Solutions
1. Extend Model Lookup Aliases (Quick Fix)
Add Bedrock patterns to MODEL_LOOKUP_ALIASES in span_metrics.py:
MODEL_LOOKUP_ALIASES = {
"sonar-pro" : "perplexity/sonar-pro" ,
"sonar" : "perplexity/sonar" ,
# AWS Bedrock mappings
"bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0" : "anthropic/claude-3-5-sonnet-20240620" ,
"bedrock/anthropic.claude-3-sonnet-20240229-v1:0" : "anthropic/claude-3-sonnet-20240229" ,
"bedrock/anthropic.claude-3-haiku-20240307-v1:0" : "anthropic/claude-3-haiku-20240307" ,
}
2. Pattern Matching Support (Recommended)
Implement regex/wildcard pattern matching in model_for_cost property to handle versioned identifiers automatically:
def _resolve_bedrock_model (self , model_name : str ) -> Optional [str ]:
"""Convert Bedrock model names to tokencost equivalents."""
bedrock_patterns = {
r"bedrock/anthropic\.claude-3-5-sonnet-.*" : "anthropic/claude-3-5-sonnet-20240620" ,
r"bedrock/anthropic\.claude-3-sonnet-.*" : "anthropic/claude-3-sonnet-20240229" ,
r"bedrock/anthropic\.claude-3-haiku-.*" : "anthropic/claude-3-haiku-20240307" ,
}
for pattern , mapped_model in bedrock_patterns .items ():
if re .match (pattern , model_name ):
return mapped_model
return None
3. Custom Model Configuration API (Future Enhancement)
Allow users to configure custom model pricing:
agentops .configure_model (
model_name = "bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0" ,
input_cost_per_1k_tokens = 0.003 ,
output_cost_per_1k_tokens = 0.015
)
4. Upstream TokenCost Contribution
Contribute Bedrock model definitions to the tokencost library's model_prices.json.
Implementation Priority
High Priority: Pattern matching support (I want an API Key #2 ) - Handles current and future Bedrock models
Medium Priority: Model lookup aliases (Create enum for session end states and event results #1 ) - Quick fix for immediate relief
Low Priority: Custom configuration API (Python event timing is weird #3 ) - Advanced use cases
Ongoing: Upstream contribution (Sessions are not sent to the dashboard until after end_session #4 ) - Long-term solution
Acceptance Criteria
Related Files
app/api/agentops/api/models/span_metrics.py - Core cost calculation logic
app/api/agentops/api/event_handlers.py - TokenCost integration
app/opentelemetry-collector/builder/costs/__init__.py - Model cost management
docs/v2/integrations/ - Integration documentation
Test Case
# Should calculate costs instead of returning $0.00
model = "bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0"
prompt_tokens = 1000
completion_tokens = 500
expected_prompt_cost = 1000 * 0.000003 # $0.003
expected_completion_cost = 500 * 0.000015 # $0.0075
expected_total_cost = 0.0105
Labels: enhancement, cost-tracking, aws-bedrock, crewai-integration
Priority: High
Effort: Medium
AWS Bedrock Model Cost Tracking Support
Problem Description
Users integrating AgentOps with AWS Bedrock models are encountering cost tracking failures with the warning:
This prevents essential cost monitoring and budget management for production deployments using AWS Bedrock.
User Impact
Affected Users:
Business Impact:
Current Behavior
Model Example:
bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0Framework: CrewAI with AWS Bedrock LLM integration
Issue: Cost metrics show as $0.00 with warning message instead of calculated costs
Expected Behavior
AgentOps should automatically recognize AWS Bedrock model identifiers and calculate costs based on current Bedrock pricing:
Technical Analysis
Current Cost Tracking Architecture
Core Cost Calculation:
app/api/agentops/api/models/span_metrics.pyline 277Model Lookup System: Lines 20-24 in
span_metrics.pyTokenCost Integration: Uses
tokencostlibrary for model pricing dataapp/api/agentops/api/event_handlers.pyline 6:from tokencost import TOKEN_COSTSapp/opentelemetry-collector/builder/costs/__init__.py: Model cost managementRoot Cause
The
tokencostlibrary doesn't include AWS Bedrock model naming patterns like:bedrock/anthropic.claude-3-5-sonnet-*bedrock/anthropic.claude-3-sonnet-*bedrock/anthropic.claude-3-haiku-*Proposed Solutions
1. Extend Model Lookup Aliases (Quick Fix)
Add Bedrock patterns to
MODEL_LOOKUP_ALIASESinspan_metrics.py:2. Pattern Matching Support (Recommended)
Implement regex/wildcard pattern matching in
model_for_costproperty to handle versioned identifiers automatically:3. Custom Model Configuration API (Future Enhancement)
Allow users to configure custom model pricing:
4. Upstream TokenCost Contribution
Contribute Bedrock model definitions to the
tokencostlibrary'smodel_prices.json.Implementation Priority
end_session#4) - Long-term solutionAcceptance Criteria
Related Files
app/api/agentops/api/models/span_metrics.py- Core cost calculation logicapp/api/agentops/api/event_handlers.py- TokenCost integrationapp/opentelemetry-collector/builder/costs/__init__.py- Model cost managementdocs/v2/integrations/- Integration documentationTest Case
Labels:
enhancement,cost-tracking,aws-bedrock,crewai-integrationPriority: High
Effort: Medium