Skip to content

fix(ccusage): add flat pricing for Opus 4.6 / Sonnet 4.6 to fix inflated costs#898

Open
MumuTW wants to merge 1 commit intoryoppippi:mainfrom
MumuTW:fix/opus-1m-pricing
Open

fix(ccusage): add flat pricing for Opus 4.6 / Sonnet 4.6 to fix inflated costs#898
MumuTW wants to merge 1 commit intoryoppippi:mainfrom
MumuTW:fix/opus-1m-pricing

Conversation

@MumuTW
Copy link
Copy Markdown

@MumuTW MumuTW commented Mar 18, 2026

Summary

  • Fixes inflated cost calculation for Claude Opus 4.6 since Claude Code enabled 1M context in v2.1.75
  • Claude Opus 4.6 and Sonnet 4.6 use flat pricing across the full 1M context window — no premium for requests exceeding 200k input tokens (docs)
  • LiteLLM's dataset only has Bedrock entries (anthropic.claude-opus-4-6-v1) which include *_above_200k_tokens tiered pricing fields; when ccusage falls back to substring matching it picks up the Bedrock entry and incorrectly applies tiered pricing
  • Fix: inject entries keyed by the exact Anthropic API model names (claude-opus-4-6, claude-sonnet-4-6) with correct flat pricing so direct lookup succeeds before the substring fallback fires

Test plan

  • All 252 existing ccusage tests pass
  • All 9 internal pricing tests pass
  • Verify with a real Claude Code session that Opus 4.6 costs are no longer inflated

Fixes #891

Summary by CodeRabbit

  • Bug Fixes
    • Improved pricing accuracy for Claude Opus 4.6 and Claude Sonnet 4.6 models when using direct Anthropic API.

…ted costs

Claude Opus 4.6 and Sonnet 4.6 use flat pricing across the full 1M
context window — there is no premium for requests exceeding 200k input
tokens. However, LiteLLM's dataset only contains Bedrock entries
(e.g. `anthropic.claude-opus-4-6-v1`) which include
`*_above_200k_tokens` fields for Bedrock-specific tiered pricing.

When ccusage looks up pricing for `claude-opus-4-6`, the direct lookup
finds no match and the substring fallback picks up the Bedrock entry,
incorrectly applying tiered pricing and inflating costs.

Fix by injecting entries keyed by the exact Anthropic API model names
(`claude-opus-4-6`, `claude-sonnet-4-6`) with correct flat pricing.
Direct lookup now succeeds before the substring fallback fires.

Fixes ryoppippi#891
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af3a6b60-f539-4a93-8b90-9203f389d611

📥 Commits

Reviewing files that changed from the base of the PR and between b81913f and b2de7c8.

📒 Files selected for processing (1)
  • apps/ccusage/src/_macro.ts

📝 Walkthrough

Walkthrough

Introduces flat pricing mappings for direct Anthropic API models (claude-opus-4-6 and claude-sonnet-4-6) and updates the prefetch logic to prioritize these direct API pricing lookups before falling back to Bedrock substring-based pricing resolution.

Changes

Cohort / File(s) Summary
Anthropic API Flat Pricing
apps/ccusage/src/_macro.ts
Added ANTHROPIC_API_FLAT_PRICING mapping for direct Anthropic API models with explicit token costs (input/output/cache) and max token limits; updated prefetchClaudePricing to inject these entries into the filtered dataset to ensure direct API models are resolved before Bedrock pricing fallback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • ryoppippi

Poem

🐰 Hop hop, the prices now align,
Flat and true for Claude's design,
No more Bedrock's weary string,
Direct API gets its pricing!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding flat pricing entries for Opus 4.6 and Sonnet 4.6 models to resolve inflated cost calculation issues.
Linked Issues check ✅ Passed The PR directly addresses issue #891 by implementing flat pricing for Anthropic API models (claude-opus-4-6, claude-sonnet-4-6) to fix inflated cost calculations caused by incorrect tiered-pricing fallback from Bedrock entries.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to fixing the cost calculation issue: introducing ANTHROPIC_API_FLAT_PRICING mapping and updating prefetchClaudePricing to use it, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inflated cost calculation since Opus 1M context enabled in 2.1.75

1 participant