Repository navigation
fix(litellm_proxy): forward tool_config cache_control_injection_points to the downstream proxy - #47570
Conversation
…s to the downstream proxy PR #47394 withheld cache_control_injection_points from the OpenAI SDK extra_body for every provider on that path, which also covers litellm_proxy. The downstream LiteLLM proxy applies the point itself, so litellm_proxy keeps forwarding it while OpenAI and the other OpenAI-compatible providers still never receive it
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@litellm-stampbot |
litellm-stampbot: risk lowApproved at Rules (
Cursor Bugbot: Low Risk at Pushes do not re-run this check. Comment |
|
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 14b1185. Configure here.
kerry-berri
left a comment
There was a problem hiding this comment.
Low risk by rule and by judgement at 14b1185
…s to the downstream proxy (BerriAI#47570) Backport of BerriAI#47570 to stable/1.103.x Cherry-picked from 04e9ed4 (main)
…s to the downstream proxy (BerriAI#47570) PR BerriAI#47394 withheld cache_control_injection_points from the OpenAI SDK extra_body for every provider on that path, which also covers litellm_proxy. The downstream LiteLLM proxy applies the point itself, so litellm_proxy keeps forwarding it while OpenAI and the other OpenAI-compatible providers still never receive it Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47570 to stable/1.106.x Cherry-picked from 04e9ed4 (main)
…s to the downstream proxy (#47570) PR #47394 withheld cache_control_injection_points from the OpenAI SDK extra_body for every provider on that path, which also covers litellm_proxy. The downstream LiteLLM proxy applies the point itself, so litellm_proxy keeps forwarding it while OpenAI and the other OpenAI-compatible providers still never receive it Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 04e9ed4)
…s to the downstream proxy (BerriAI#47570) PR BerriAI#47394 withheld cache_control_injection_points from the OpenAI SDK extra_body for every provider on that path, which also covers litellm_proxy. The downstream LiteLLM proxy applies the point itself, so litellm_proxy keeps forwarding it while OpenAI and the other OpenAI-compatible providers still never receive it Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Backport of BerriAI#47570 to stable/1.105.x. Cherry-picked from 04e9ed4 (main).
TLDR
Problem this solves:
litellm_proxy/...deployments droppedcache_control_injection_pointswithlocation: tool_configextra_bodyfor every OpenAI SDK providerHow it solves it:
litellm_proxykeeps forwardingcache_control_injection_pointsinextra_bodyadd_provider_specific_params_to_optional_params, reusingLITELLM_ONLY_PARAMSUser Flow
Before: a team routing one LiteLLM proxy to another configures a tool cache breakpoint on the front proxy and never gets a cache hit
model: litellm_proxy/claude-sonnet-4-6,api_base: http://downstream:4001, andcache_control_injection_points: [{location: tool_config, control: {type: ephemeral}}]on the front proxyusage.cache_creation_input_tokensis 0, and the same request a second time readscache_read_input_tokens: 0cache_controlon any of themAfter: the same config produces a cache write on the first call and a cache read on the second
litellm_proxy/...deployment with the samecache_control_injection_pointsentrycache_creation_input_tokens: 22661, and the identical second call showscache_read_input_tokens: 22661cache_control: {"type": "ephemeral"}on the last toolRelevant issues
Fixes a regression from #47394, which added
LITELLM_ONLY_PARAMSand withheldcache_control_injection_pointsfrom the OpenAI SDKextra_bodyfor every provider on that path, includinglitellm_proxyPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<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 moreScreenshots / Proof of Fix
Two local proxies, both started with
python litellm/proxy/proxy_cli.py --config <config> --detailed_debugand local Postgres (sudo service postgresql start,prisma db push). Downstream on :4001 is a realanthropic/claude-sonnet-4-6deployment with no injection point of its own. Upstream on :4000 routes to itpayload.jsonis a chat request with 40 function tools whose descriptions are about 120 words each (about 22.6k prompt tokens),payload_messages.jsonis the same tools in Anthropic/v1/messagesshape. The same two curls run twice per caseBefore (5145250)
/v1/chat/completions, two identical calls
{"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0}{"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0}'required': ['query']}}}], 'extra_body': {}}and the grep count forcache_control_injection_pointsis0tool_39with nocache_controlkey on any tool/v1/messages, two identical calls
{"input_tokens": 22991, "output_tokens": 4}{"input_tokens": 22991, "output_tokens": 4}'extra_body': {}}, grep count0After (14b1185)
/v1/chat/completions, two identical calls
{"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 22661, "cache_read_input_tokens": 0}{"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 22661}'extra_body': {'cache_control_injection_points': [{'location': 'tool_config', 'control': {'type': 'ephemeral'}}]}}, grep count2'name': 'tool_39', ... 'cache_control': {'type': 'ephemeral'}/v1/messages, two identical calls
{"input_tokens": 330, "output_tokens": 4, "cache_read_input_tokens": 22661}(the 40 tools were already cached by the chat case){"input_tokens": 330, "output_tokens": 4, "cache_read_input_tokens": 22661}cache_control_injection_pointsentry, grep count4Red leg of the new unit test on the merge base, for reference only, the proof above is the live run
Type
🐛 Bug Fix
Caveats (if any)
Low
litellm_proxygets the key back, no other OpenAI SDK provider inopenai_compatible_providersis LiteLLM-awareFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/98f9c29d4d034578aac45b9f41c81c1b
Open in Devin Desktop: https://app.devin.ai/desktop/session/98f9c29d4d034578aac45b9f41c81c1b?variant=devin
Requested by: @kerrylu-berri
Note
Low Risk
Single conditional in optional-param forwarding for one provider; OpenAI paths unchanged and covered by tests.
Overview
Fixes a regression where
litellm_proxyroutes droppedcache_control_injection_points(e.g.location: tool_config) before they reached a downstream LiteLLM proxy, so tool cache breakpoints never applied.When building OpenAI SDK
extra_body, LiteLLM-only params are still withheld for OpenAI/Azure and other compatible providers, butwithheld_paramsis empty forcustom_llm_provider == "litellm_proxy", socache_control_injection_pointsis forwarded inextra_bodyagain. A unit test asserts that behavior alongside existing coverage that OpenAI still does not get the key.Reviewed by Cursor Bugbot for commit 14b1185. Bugbot is set up for automated code reviews on this repo. Configure here.