claude-code - 💡(How to fix) Fix [BUG] cost.total_cost_usd underreports ~66% on Bedrock — cache tokens seems to be not counted for Opus 4.7 via eu.anthropic.* inference profile [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56110Fetched 2026-05-05 05:57:56
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Error Message

Error Messages/Logs

Root Cause

cost.total_cost_usd underreports by ~3× because cache_read and cache_creation tokens appear to not be included in the cost calculation.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

When routed through AWS Bedrock with
CLAUDE_CODE_USE_BEDROCK=1`` and the EU Opus 4.7 inference profile ANTHROPIC_DEFAULT_OPUS_MODEL=eu.anthropic.claude-opus-4-7`

cost.total_cost_usd underreports by ~3× because cache_read and cache_creation tokens appear to not be included in the cost calculation.

What Should Happen?

The output of cost._total_cost_usd accumulation should roughly match the AWS Bedrock bill

Error Messages/Logs

Steps to Reproduce

  1. Configure Claude Code for Bedrock via the env vars above (EU regional inference profile).
  2. Run a session that exercises prompt caching heavily (any long-running agent turn does).
  3. Sum the message.usage values from the session transcript, deduping by message.id (the same logical API call appears 2–3 times as the conversation linearizes through tool turns).
  4. Multiply by published Opus 4.7 rates.
  5. Compare to /cost output and cost.total_cost_usd from the statusline stdin payload.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.126

Platform

AWS Bedrock

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

Related

  • #28168 — similar root cause: hardcoded pricing map misses model IDs (closed, fixed for Sonnet 4.6)
  • #51198 — inverse symptom: admin API reports 100× too high (open)
  • #53371 — similar underreport on direct Anthropic Haiku (closed as dup of #51198)

extent analysis

TL;DR

The issue can be addressed by modifying the cost calculation to include cache_read and cache_creation tokens.

Guidance

  • Review the cost calculation logic to ensure it accounts for all relevant tokens, including cache_read and cache_creation.
  • Compare the published Opus 4.7 rates with the current pricing map to identify potential discrepancies.
  • Investigate the relationship between the Claude Code version (2.1.126) and the pricing map to determine if an update is necessary.
  • Refer to related issues (#28168, #51198, #53371) for potential insights into similar problems and their resolutions.

Example

No code snippet is provided due to the lack of specific implementation details in the issue.

Notes

The issue may be related to a hardcoded pricing map that misses model IDs, as seen in #28168. However, without further information, it's uncertain whether this is the root cause.

Recommendation

Apply a workaround by modifying the cost calculation to include the missing tokens, as this is the most direct approach to addressing the underreporting issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] cost.total_cost_usd underreports ~66% on Bedrock — cache tokens seems to be not counted for Opus 4.7 via eu.anthropic.* inference profile [1 comments, 2 participants]