Repository navigation
fix: honor cache_control on system blocks in Anthropic -> Responses bridge - #41426
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…ridge Fixes #41424 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 SummaryThis PR preserves Anthropic system-block cache markers when bridging requests to the Responses API. Marked system prompts now become leading developer messages with explicit prompt-cache breakpoints, while existing explicit breakpoints retain precedence. Focused tests cover system and mid-turn conversion behavior Confidence Score: 5/5The PR appears safe to merge, with the intended cache marker preserved through the existing Responses developer-message path No actionable failure remains. The marker is emitted as the expected plain dictionary, explicit breakpoints retain precedence, and unmarked system prompts keep their existing instructions behavior Important Files Changed
Reviews (1): Last reviewed commit: "fix: honor cache_control on system block..." | Re-trigger Greptile |
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5fafe03. Configure here.
|
Closing: OpenAI already caches the flattened instructions prefix implicitly (warm cached=3532/3535, gpt-5.6-terra), and gpt-4.1 rejects prompt_cache_breakpoint with a 400, regressing older openai/ deployments |
TLDR
Problem this solves:
cache_controlsystem blocks were flattened into ResponsesinstructionsHow it solves it:
cache_controlas an explicit breakpointdevelopermessage ininputwithprompt_cache_breakpointUser Flow
Before: a developer points Claude Code at the proxy for an OpenAI GPT-5.6 deployment served over the Responses API and pays cache-write rates with no cache reads
systemarray whose last block carriescache_control: {"type": "ephemeral"}and a short user turnusageshowscache_creation_input_tokens> 0 andcache_read_input_tokens: 0cache_read_input_tokens: 0, so every turn is billed as a fresh cache writeAfter: the same requests hit the cache on the warm call
cache_controlsystem blockcache_creation_input_tokens> 0 andcache_read_input_tokens: 0cache_read_input_tokens> 0 covering the system promptRelevant issues
Fixes #41424
Affected release
Linear ticket
Resolves LIT-7865
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@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
This session's network policy blocks every LLM provider host and the npm registry, so no live proxy call and no Claude Code run was possible here. The proof below is the reporter's offline reproduction from #41424, run at the merge base and at the tip. A live before/after leg driven from Claude Code against a real Responses deployment still needs to be run before this merges
Shared setup:
repro.pyis the script from the issue body (it builds a/v1/messagesrequest whose system block carries eithercache_controlorprompt_cache_breakpoint, runs it through the bridge, and prints whether the system prompt left asinstructionsor as a developer message)Before (9cd7873)
git checkout 9cd787386 && uv run --no-sync python repro.pyAfter (5fafe03)
git checkout litellm_anthropic_responses_cache_control_alias && uv run --no-sync python repro.pyType
🐛 Bug Fix
Caveats (if any)
High
bedrock_mantledeployment does not reach this bridge at all/v1/messagesonly takes the Anthropic -> Responses bridge forcustom_llm_provider == "openai"bedrock_mantle(and every other provider) goes Anthropic -> chat completions -> Responsesinputkeeps the system message but the Responses config stripscache_control, so cache reads are still zero after this PRprompt_cache_breakpointthrough the chat -> Responses bridge) plus acache_controlalias in that bridge; tracked on LIT-7108Low
prompt_cache_breakpointvalue untouchedttloncache_controlis not forwarded; Responses breakpoints have no ttl fieldFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/cc0d2cb2dd364964bca02e05ea4401a9
Open in Devin Desktop: https://app.devin.ai/desktop/session/cc0d2cb2dd364964bca02e05ea4401a9?variant=devin
Note
Low Risk
Scoped to Anthropic→Responses request translation for system blocks; behavior change only when
cache_controlis present, with tests covering precedence and edge cases.Overview
Treats Anthropic
cache_controlon system text blocks likeprompt_cache_breakpointin the/v1/messages→ Responses API bridge, so cached system prompts are not flattened intoinstructions(which broke prompt cache reads for clients such as Claude Code).A new
_system_block_cache_breakpointhelper prefers an existingprompt_cache_breakpointand otherwise maps anycache_controlmarker to{"mode": "explicit"}. Top-levelsystemarrays with either marker still become a leadingdevelopermessage withprompt_cache_breakpointon the rightinput_textparts; mid-turnsystemmessages get the same mapping.cache_controlis not forwarded on the outbound payload.Tests cover
cache_control→ developer message, explicit breakpoint precedence, and mid-turn system blocks.Reviewed by Cursor Bugbot for commit 5fafe03. Bugbot is set up for automated code reviews on this repo. Configure here.