fix(ccusage): add flat pricing for Opus 4.6 / Sonnet 4.6 to fix inflated costs - #898
fix(ccusage): add flat pricing for Opus 4.6 / Sonnet 4.6 to fix inflated costs#898MumuTW wants to merge 1 commit into
Conversation
…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 #891
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughIntroduces first‑party flat pricing entries for specific Anthropic/Claude API models and threads them into the LiteLLM pricing pipeline so direct-model lookups use the injected overrides before existing Bedrock substring-based matching. ChangesClaude flat-pricing overrides
Sequence DiagramsequenceDiagram
participant Macro as apps/ccusage/_macro
participant Fetcher as PricingFetcher
participant Lite as LiteLLMPricingFetcher
participant Cache as Pricing Cache/Store
Macro->>Fetcher: request pricing (prefetchClaudePricing)
Fetcher->>Lite: construct with pricingOverrides (CLAUDE_FIRST_PARTY_FLAT_PRICING)
Lite->>Cache: load or fetch pricing map
Lite->>Lite: applyPricingOverrides(pricingOverrides) -> merged map
Lite->>Cache: cache merged pricing
Lite-->>Fetcher: return pricing (override entries first)
Fetcher-->>Macro: deliver pricing (direct Claude entries present)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
@ccusage/amp
ccusage
@ccusage/codex
@ccusage/mcp
@ccusage/opencode
@ccusage/pi
commit: |
fdec0da to
b2de7c8
Compare
|
Thank you for opening this and for digging into the inflated Opus 4.6 pricing issue. After checking the current Anthropic pricing docs and the latest LiteLLM pricing dataset, I think we should not merge this as-is. LiteLLM now has first-party claude-opus-4-6, claude-opus-4-7, and claude-sonnet-4-6 entries with flat 1M-context pricing, so ccusage should avoid hardcoding those prices locally. Also, this does not apply to every 4.5 model: claude-sonnet-4-5 still has above-200k tier fields in LiteLLM, while the 1M flat long-context pricing is currently documented for Opus 4.7, Opus 4.6, and Sonnet 4.6. I will close this in favour of a narrower PR that relies on LiteLLM first-party flat entries and avoids falling through to provider-specific substring matches where that would select the wrong pricing. Sorry for the churn here, and thanks again for catching the underlying issue. |
|
Closing this in favour of a narrower follow-up PR that relies on LiteLLM first-party flat pricing entries instead of hardcoding model prices in ccusage. |
Summary
anthropic.claude-opus-4-6-v1) which include*_above_200k_tokenstiered pricing fields; when ccusage falls back to substring matching it picks up the Bedrock entry and incorrectly applies tiered pricingclaude-opus-4-6,claude-sonnet-4-6) with correct flat pricing so direct lookup succeeds before the substring fallback firesTest plan
Fixes #891
Summary by CodeRabbit