Skip to content

Bedrock token amount is different between billing and cloudwatch

0

I am using Bedrock sonnet 4 model at us-east-1 region, and enable cloudwatch log. Using following Logs insights QL and find that the token/price is 3 or 4 times less than billing. Is there are any missing metrics I have to add in Logs insights QL or other reason?

========

fields identity.arn, modelId, input.inputTokenCount, output.outputTokenCount, input.cacheWriteInputTokenCount, input.cacheReadInputTokenCount
| filter ispresent(input.inputTokenCount) and ispresent(output.outputTokenCount)
| stats 
    sum(input.inputTokenCount) as input_tokens, 
    sum(output.outputTokenCount) as output_tokens,
    sum(coalesce(input.cacheWriteInputTokenCount, 0)) as cache_write_tokens,
    sum(coalesce(input.cacheReadInputTokenCount, 0)) as cache_read_tokens,
    
    # Input token cost
    sum(if(strcontains(modelId, 'anthropic.claude-sonnet-4-20250514-v1'), (input.inputTokenCount / 1000) * 0.003, 0)) as input_cost,
    
    # Cache Write token cost
    sum(if(strcontains(modelId, 'anthropic.claude-sonnet-4-20250514-v1'), (coalesce(input.cacheWriteInputTokenCount, 0) / 1000) * 0.003, 0)) as cache_write_cost,
    
    # Cache Read token cost
    sum(if(strcontains(modelId, 'anthropic.claude-sonnet-4-20250514-v1'), (coalesce(input.cacheReadInputTokenCount, 0) / 1000) * 0.0003, 0)) as cache_read_cost,
    
    # Outputtoken cost
    sum(if(strcontains(modelId, 'anthropic.claude-sonnet-4-20250514-v1'), (output.outputTokenCount / 1000) * 0.015, 0)) as output_cost,
    
    # Total cost
    sum(if(strcontains(modelId, 'anthropic.claude-sonnet-4-20250514-v1'), 
        (input.inputTokenCount / 1000) * 0.003 + 
        (output.outputTokenCount / 1000) * 0.015 +
        (coalesce(input.cacheWriteInputTokenCount, 0) / 1000) * 0.003 +
        (coalesce(input.cacheReadInputTokenCount, 0) / 1000) * 0.0003, 0)) as total_cost
    
by modelId, identity.arn
| sort by total_cost desc
2 Answers
0

The token count mismatch you're experiencing between CloudWatch logs and your billing is a common issue with Amazon Bedrock. There are several reasons why your CloudWatch Logs Insights query might be showing token counts and costs that are 3-4 times less than what appears in your billing:

  1. Cumulative vs. Individual Request Counting: CloudWatch logs typically show token counts for individual requests, while billing may reflect cumulative token usage across an entire conversation session, including previous interactions and context.

  2. Session State Management: Bedrock models maintain conversation context through session state, which contributes to higher token counts in billing but may not be fully reflected in CloudWatch logs.

  3. System Prompts and Instructions: The billing may include tokens used for system prompts, instructions, and other internal formatting that aren't visible in the CloudWatch logs.

  4. Different Counting Mechanisms: The token counting algorithms may differ between CloudWatch logs and the billing system.

  5. Missing Metrics: Your query might not be capturing all relevant token metrics. For example, there might be additional token usage related to conversation memory or context management.

To get a more accurate picture, you could:

  • Ensure you're capturing all invocations in your logs query timeframe
  • Check if there are any additional metrics beyond the ones you're already tracking
  • Consider that some token usage might be related to internal processing that isn't exposed in the logs

For accurate billing and usage tracking, it's generally recommended to rely on the AWS Cost Explorer or billing dashboard rather than trying to reconstruct costs from CloudWatch logs alone.
Sources
Token Count Mismatch | AWS re:Post
Improve visibility into Amazon Bedrock usage and performance with Amazon CloudWatch | AWS Machine Learning Blog
How tokens are counted in Amazon Bedrock - Amazon Bedrock

answered 10 days ago
AWS
MODERATOR
reviewed 10 days ago
AWS
EXPERT
reviewed 10 days ago
0

I want to view costs at the AWS role level. As far as I know, Cost Explorer cannot display this level of granularity. Are there any good methods I can use?

answered 4 days ago