[Bug] Anthropic reports stale cache-write cost when message_delta updates cache creation #1769
Replies: 1 comment 1 reply
|
Investigated this report and produced a candidate fix, validated on a fork of this repository. Root cause, fix and validation from the working notes:
Diff: awhite0030/prime-agent@main...jules-681529213854070229-72eab51c The change passes |
Uh oh!
There was an error while loading. Please reload this page.
Affected area
AI providers and models
What happened?
The Anthropic provider computes the cache-write rate once from
message_startand reuses it. Whenmessage_deltahas different cache-creation numbers (LiteLLM and other proxies do this),cost.cacheWriteandcost.totaldrift from actual billing. The 1h vs 5m rate gap undercacheRetention: "long"makes that worse.Steps to reproduce
cacheRetention: "long".message_startreport only 5-minute cache writes, thenmessage_deltareport only 1-hour cache writes. This is what some proxies emit.cost.cacheWriteto the 1h rate. It still uses the 5m rate.Expected behavior
Reprice from the latest
event.usage.cache_creationbreakdown onmessage_deltawhen it is present. Keep themessage_startrate when it is not.Prime Agent version
0.7.1 / source as of 2026-08-08
Environment
Reproduced from source. Shows up behind proxies that re-aggregate usage, such as LiteLLM.
Additional context
Original report: #997
Tested patch, closed in the August 15 backlog sweep: #998
All reactions