Skip to content

fix(ai): price anthropic 1h cache writes at 2x input#5738

Merged
mitsuhiko merged 2 commits into
earendil-works:mainfrom
theBucky:fix/anthropic-1h-cache-write-cost
Jun 15, 2026
Merged

fix(ai): price anthropic 1h cache writes at 2x input#5738
mitsuhiko merged 2 commits into
earendil-works:mainfrom
theBucky:fix/anthropic-1h-cache-write-cost

Conversation

@theBucky

@theBucky theBucky commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

refs #5737

pi prices every anthropic cache write at the 5m rate because the provider reads the aggregate cache_creation_input_tokens and drops the 5m/1h split, so 1h writes undercount by 1.6x. this reads ephemeral_1h_input_tokens and charges the 1h slice at 2x base input in calculateCost.

tested: sse-driven test on opus 4.8, a 600k/400k split lands at 7.75 (was 6.25), no-breakdown falls back to 6.25. npm run check and ai tests pass.

theBucky added 2 commits June 15, 2026 07:42
anthropic 1h cache writes were billed at the 5m rate; split the bucket and price the 1h portion correctly

- add optional `Usage.cacheWrite1h` for the 1h-retention subset of `cacheWrite`
- read `cache_creation.ephemeral_1h_input_tokens` from the anthropic `message_start` usage
- in `calculateCost`, charge 1h writes at 2x base input and the rest at the existing 5m `cacheWrite` price
- cover the split and the no-breakdown fallback with an sse-driven test on `claude-opus-4-8`
@theBucky theBucky marked this pull request as ready for review June 14, 2026 23:50
@mitsuhiko mitsuhiko merged commit 0be5bb6 into earendil-works:main Jun 15, 2026
3 checks passed
@mitsuhiko

Copy link
Copy Markdown
Member

Thank you!

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.

2 participants