[BUG] cost_usage_total metric applies Opus pricing to Sonnet 4.6 model
Bug Description
The claude_code.cost.usage (Prometheus: claude_code_cost_usage_total) metric applies Opus 4.6 pricing ($5/$25 per MTok) to the Sonnet 4.6 model, instead of the correct Sonnet pricing ($3/$15 per MTok). This results in cost estimates ~1.67x higher than actual for Sonnet 4.6.
Version
- Claude Code: 2.1.51 (also confirmed on 2.1.49)
- Platform: Linux (WSL2)
Evidence
1. Mathematical proof from Prometheus data
Running claude-sonnet-4-6 and collecting Prometheus metrics:
claude_code_cost_usage_total{model="claude-sonnet-4-6"} 0.6554
claude_code_token_usage_total{model="claude-sonnet-4-6",type="input"} 15
claude_code_token_usage_total{model="claude-sonnet-4-6",type="output"} 802
claude_code_token_usage_total{model="claude-sonnet-4-6",type="cacheRead"} 176003
claude_code_token_usage_total{model="claude-sonnet-4-6",type="cacheCreation"} 87565
Computing with Opus pricing ($5/$25/$0.50/$6.25 per MTok):
15×5/1M + 802×25/1M + 176003×0.5/1M + 87565×6.25/1M = 0.6554 ← matches reported value
Computing with correct Sonnet pricing ($3/$15/$0.30/$3.75 per MTok):
15×3/1M + 802×15/1M + 176003×0.3/1M + 87565×3.75/1M = 0.3932 ← expected value
2. Root cause in binary
Extracted from the v2.1.51 binary using strings:
Pricing tables:
TEH={inputTokens:3,outputTokens:15,promptCacheWriteTokens:3.75,promptCacheReadTokens:0.3,...} // Sonnet pricing
u2H={inputTokens:5,outputTokens:25,promptCacheWriteTokens:6.25,promptCacheReadTokens:0.5,...} // Opus 4.5/4.6 pricing
Model-to-pricing mapping (xJ$):
xJ$={
[VU(UNH.firstParty)]:TEH, // claude-3-5-sonnet-20241022 → $3/$15 ✓
[VU(GNH.firstParty)]:TEH, // claude-3-7-sonnet-20250219 → $3/$15 ✓
[VU(XIH.firstParty)]:TEH, // claude-sonnet-4-20250514 → $3/$15 ✓
[VU(VNH.firstParty)]:u2H, // claude-sonnet-4-6 → $5/$25 ✗ (should be TEH)
...
}
Sonnet 4 and earlier are correctly mapped to TEH ($3/$15), but Sonnet 4.6 is incorrectly mapped to u2H ($5/$25, which is Opus 4.6 pricing).
Impact
- Prometheus
cost_usage_totalmetric reports 1.67x the actual cost for Sonnet 4.6 - Any monitoring/budgeting tools relying on these metrics are affected
Expected Behavior
claude-sonnet-4-6 should be mapped to TEH (Sonnet pricing: $3/$15/$3.75/$0.30 per MTok), consistent with the official pricing page and consistent with how earlier Sonnet models are mapped.
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗