Repository navigation
Fix: price current Claude models and 1-hour cache writes in usage dashboard - #489
Open
anascherif wants to merge 1 commit into
Open
anascherif wants to merge 1 commit into
anascherif wants to merge 1 commit into
Conversation
…hboard The usage dashboard priced any model containing "opus-4" at Opus 4's $15/$75, any containing "sonnet-4" at $3/$15, and every other model at $0. So Opus 4.5-4.8 were charged 3x their real price, and Haiku 4.5/5.5, Opus 5/5.5, Sonnet 5/5.5 and Fable showed no cost at all. It also priced every cache write at the 5-minute rate (1.25x input), but Claude Code writes to the 1-hour cache, billed at 2x input, and its transcripts report the split in usage.cache_creation. Price each model by its family and version, and bill the 1-hour share of the cache writes at the 1-hour rate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Usage Dashboard calculates cost in
calculate_cost(src-tauri/src/commands/usage.rs), and that function only knows two model families. It matches on substrings:opus-4gets Opus 4's $15 / $75;sonnet-4gets $3 / $15;So, with current Claude Code models:
usage.cache_creation.ephemeral_1h_input_tokens.On my own Claude Code history, the dashboard total was $1,168. With this change it is $736:
Approach
model_pricing()reads the family and version out of the model ID and looks them up in a price table. It handles:claude-opus-4-8);claude-sonnet-4-5-20250929);claude-3-5-haiku-20241022);us.anthropic.claude-opus-4-1-20250805-v1:0).The table lists input, output and cache-read prices. Cache-write prices follow Anthropic's multipliers: 1.25x input for 5 minutes, 2x for 1 hour.
UsageDatareadscache_creation.ephemeral_1h_input_tokens.calculate_costcharges that share at the 1-hour rate and the rest at the 5-minute rate. The 1-hour share is capped atcache_creation_input_tokens. Entries without the split are priced as before.Unknown models (for example
<synthetic>) still cost $0, as before.Testing
Added unit tests in
usage.rsfor:I don't have the Tauri build dependencies on this machine. So I ran these tests (6 passed) and
cargo clippy(clean) oncalculate_cost,model_pricingand the tests copied into a standalone crate.rustfmt --checkonusage.rsis clean.Side effects and limitations