Conversation
✅ Deploy Preview for theagentrouter ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Anthropic charges different rates to create a cache entry depending on how long it lives: 2x the base input rate for one hour, against 1.25x for five minutes. Responses report the split in usage.cache_creation, but only the combined cache_creation_input_tokens was read, so a cost expression could not tell the two apart and under-charged long-lived cache writes. Adds cache_creation_5m_input_tokens and cache_creation_1h_input_tokens as CEL variables, populated from usage.cache_creation on both the streaming and non-streaming Anthropic paths. Both are 0 when a backend does not report the breakdown, so existing expressions are unaffected. Signed-off-by: lspataroG <lspataro@google.com>
3fb053c to
bd0198f
Compare
|
@theagentrouter/agent-router-maintainers — could someone approve the workflow runs on this PR? For the record, the red Netlify check is expected, not a failure: the deploy status is literally "Deploy Preview canceled". The last push only touched Go files, so nothing under the Locally |
|
Can someone have a look at this please? |
Description
Creating a cache entry is not priced at a single rate. Anthropic charges twice the
base input rate for an entry that lives an hour, against 1.25x for one that lives
five minutes. Responses already report which was used, in
usage.cache_creation,but only the combined
cache_creation_input_tokenswas read — so acostExpressioncannot tell the two apart and under-charges the longer-livedwrites. On cache-heavy clients those writes can be the largest single item on a
bill, so the gap is not a rounding difference.
This adds
cache_creation_5m_input_tokensandcache_creation_1h_input_tokensas CEL variables, populated from
usage.cache_creationon both the streaming andnon-streaming Anthropic paths. They can be used instead of the combined figure:
Nothing changes for existing users: the combined field keeps its meaning, and the
two new variables are
0when a backend does not report the breakdown.Related Issues/PRs (if applicable)
None.
Special notes for reviewers (if applicable)
IsZero()andOverride()were extended to cover the new fields, forconsistency with the existing ones.
cache_creationwith zero values, the fields aremarked as set rather than absent — present-and-zero is a different statement
from not reported. Two existing test fixtures include that block, so their
expectations were updated.
make precommitandgo test ./internal/...pass.