Skip to content

pricing: price Claude's 1-hour cache writes at 2x input, not 1.25x - #192

Merged
Aaron Li (aaron-jx-li) merged 2 commits into
microsoft:mainfrom
anascherif:pricing/claude-1h-cache-writes
Nov 10, 2026
Merged

Aaron Li (aaron-jx-li) merged 2 commits into
microsoft:mainfrom
anascherif:pricing/claude-1h-cache-writes

Conversation

@anascherif

Copy link
Copy Markdown
Contributor

Fixes #191.

Anthropic bills 5-minute cache writes at 1.25x input and 1-hour cache writes at 2x. Every Claude cache-write token was priced at 1.25x, which understates sessions whose writes go to the 1-hour cache.

  • trace/claude.py: claude_session_usage also returns cache_creation_1h_input_tokens, the sum of each message's cache_creation.ephemeral_1h_input_tokens, capped per message at its cache_creation_input_tokens.
  • pricing.py: effective_tokens prices that share at the table's cache_write_1h (2.0 for Claude). New helper cache_write_1h_tokens reads the flat field or an Anthropic usage object.
  • plugin/accounting.py, plugin/fold.py: carry the share into the priced record and the session ledger, so Claude side calls are priced the same way.

Unchanged: rows without the field, non-Claude models, and the fallback curve.

Tests: tests/test_cache_write_1h.py (12 cases). I ran it with tests/test_ledger.py, tests/test_live_core.py and tests/test_trace.py; all pass. I have not run the full suite or experiments/tests.

Note for the experiments: Claude rows produced after this change that go through claude_session_usage will price 1-hour writes at 2x, so they are not directly comparable to rows recorded before it.

Anthropic bills a cache write by its lifetime: 1.25x input for the 5-minute cache and 2x for the 1-hour one. Every Claude cache-write token was priced at 1.25x, so a session whose writes go to the 1-hour cache (Claude Code on a subscription) was understated.

A message's usage splits its cache writes in cache_creation.ephemeral_1h_input_tokens. The Claude session reader now sums that share as cache_creation_1h_input_tokens, and effective_tokens prices it at the table's cache_write_1h (2.0 on the Claude curve). A row without the field, or a weight table without the entry, is priced exactly as before.
@anascherif

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@aaron-jx-li
Aaron Li (aaron-jx-li) merged commit d3735e1 into microsoft:main Nov 10, 2026
9 checks passed
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.

pricing: Claude's 1-hour cache writes are priced at 1.25x, but billed at 2x

2 participants