Repository navigation
fix(bedrock): price 1h Converse cache writes at the 1h rate - #36808
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThe PR maps Bedrock Converse’s per-TTL cache-write usage into LiteLLM’s existing tiered cache-pricing fields.
Confidence Score: 5/5The PR appears safe to merge, with the changed usage fields flowing correctly into existing tiered cache-write pricing. The implementation reconciles known TTL buckets against aggregate cache-write tokens before using the detailed pricing path, preserves aggregate fallback behavior for incomplete data, and exercises the corrected cost calculation with focused tests.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/converse_transformation.py | Parses and validates Bedrock’s per-TTL cache-write breakdown before attaching it to normalized prompt usage. |
| litellm/types/llms/bedrock.py | Adds the optional typed representation of Bedrock Converse cache-detail entries. |
| tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py | Covers TTL splitting, fallback cases, mixed writes, and corrected 1-hour cache-write pricing. |
Reviews (1): Last reviewed commit: "fix(bedrock): price 1h Converse cache wr..." | Re-trigger Greptile
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
cacheDetailscache write breakdownUser Flow
Before: an app that caches a large system prompt with a 1 hour TTL on Bedrock Converse is charged the 5 minute cache write rate, so its LiteLLM spend reads about 37% under what AWS bills
"model": "bedrock-converse-opus-4-8"and an 11.6k token system block carrying"cache_control": {"type": "ephemeral", "ttl": "1h"}"cache_creation_input_tokens": 11632and aprompt_tokens_detailsobject with no per-TTL breakdown at allx-litellm-response-costheader on that response reads0.07288, which is 11632 tokens priced at the 5 minute rate of $6.25/MAfter: the same request is charged the 1 hour rate, so LiteLLM spend lines up with the AWS bill
cache_controlblock"cache_creation_input_tokens": 11630plus a"cache_creation_token_details"object showing"ephemeral_1h_input_tokens": 11630and"ephemeral_5m_input_tokens": 0x-litellm-response-costheader now reads0.11648, matching the 1 hour rate"ttl": "5m"block still comes back at0.07288Relevant issues
Fixes #36760
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Real Bedrock Converse calls against
global.anthropic.claude-opus-4-8in us-east-1, no mocks, real spend. Each run uses a unique nonce inside the cached system prompt so it is a fresh cache write rather than a read. Proxy booted withwhere the config declares one deployment,
bedrock/converse/global.anthropic.claude-opus-4-8in us-east-1Request sent in both runs
Before, at merge base
5f2986a1f3c9c4aee6dec7ac36d02d7ca96110d5$0.07288 is
16*5e-6 + 4*2.5e-5 + 11632*6.25e-6, the 5 minute rate, while the correct 1 hour figure is16*5e-6 + 4*2.5e-5 + 11632*1.0e-5 = 0.11650After, at PR tip
7a42dccbc79b6be0bea5b5a2b4e92f241182874d$0.11648 is
16*5e-6 + 4*2.5e-5 + 11630*1.0e-5, the 1 hour rateSame tip, same script but with
"ttl": "5m", to show 5 minute writes are untouchedIndependent second run at the same tip, and the recorded spend matches the header
The only commit after
7a42dccis aruff formatreflow of one line, no behavior changeA direct boto3
conversecall confirms Bedrock reports the split, including mixed cache points in one request, which the fix maps straight throughType
🐛 Bug Fix
Caveats (if any)
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/2279c9dc9acb461db7a4393ba5ce6d45
Requested by: @mateo-berri