Conversation
✅ Deploy Preview for theagentrouter canceled.
|
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>
lspataroG
force-pushed
the
cache-creation-ttl-cost
branch
from
September 11, 2026 10:08
3fb053c to
bd0198f
Compare
Author
|
@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 |
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.
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.