Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Contributor
|
Closing as superseded: #36762 landed the cacheDetails split with a reconciliation guard and merged today. Thanks for the contribution! |
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.
TLDR
Problem this solves:
How it solves it:
cacheDetailsarray Bedrock returns onTokenUsagecache_creation_token_detailsso the cost calc applies the 1h rate to 1h writesUser Flow
Before: a developer running Claude with a 1-hour prompt cache TTL on the Bedrock Converse path sees cache-write spend that is too low
After: the same request bills each TTL bucket at its own rate
Relevant issues
Fixes #36760
Linear ticket
Type
🐛 Bug Fix
Changes
AmazonConverseConfig._transform_usageonly read the aggregatecacheWriteInputTokensfield, socache_creation_token_detailsstayed unset andcalculate_cache_writing_costbilled the whole cache-write count at the 5-minute rate. Bedrock's ConverseTokenUsageactually returns acacheDetailsarray with a per-TTL breakdown (inputTokensplusttlof5mor1h, sorted 1h first), whichConverseTokenUsageBlockdid not declare, so it was dropped before it reached the transform. This declarescacheDetailson the usage block, adds aConverseCacheDetailBlocktype, and sums the per-TTL buckets intoCacheCreationTokenDetails(ephemeral_5m_input_tokens, ephemeral_1h_input_tokens), the same shape the Anthropic direct provider and Vertex already produce. WhencacheDetailsis absent the split staysNoneand behavior is unchanged.Screenshots / Proof of Fix
Verified against the real
model_costmap at commit 860fa15 (Bedrockanthropic.claude-haiku-4-5: 5m cache-write 1.25e-6, 1h 2e-6), running a Converse usage with a 3000 token 1h write and a 1000 token 5m write through_transform_usagethencompletion_cost:Regression tests in
tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py:test_transform_usage_splits_cache_writes_by_ttl(asserts the 1h/5m split) andtest_transform_usage_without_cache_details_leaves_ttl_split_unset(guards the no-regression path). Both pass; they fail if the parse is removed.Final Attestation