Show cost breakdown by bucket (input / output / cache read / cache write) on the dashboard#5
Open
ludwigehlert-gif wants to merge 1 commit into
Open
Conversation
Adds totals.cost_breakdown to /api/stats with per-bucket cost (input, output, cache_read, cache_write_5m, cache_write_1h), grouped per (tool, model) so the correct rates are applied. The UI surfaces four new cards — cache read, cache write, output, fresh input — each with its share of the total cost. For Claude Code sessions this makes it obvious that cache reads (re-sending the conversation each turn at 10% input rate) and 1h cache writes dominate the bill, not fresh input or output. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Adds
totals.cost_breakdownto/api/stats— per-bucket cost (input, output, cache_read, cache_write_5m, cache_write_1h) computed by grouping per(tool, model)so each rate fromprices.jsonis applied correctly. The UI surfaces four new cards: cost: cache read, cost: cache write, cost: output, cost: fresh input, each annotated with its share of the total.The motivation: looking at a single "est cost" number, it's not obvious that on long Claude Code sessions ~60% of the bill is cache reads (re-sending the conversation every turn at 10% input rate) and another ~30% is 1h cache writes — fresh input is typically a rounding error and output is ~10%. The breakdown makes this immediately visible.
Test plan
http://127.0.0.1:8732after restarting the server — four new cost cards appear.est costcard.prices.jsonand click recompute prices — the breakdown updates accordingly.🤖 Generated with Claude Code