Skip to content

fix(litellm_proxy): forward tool_config cache_control_injection_points to the downstream proxy - #47570

Merged
klu-berri merged 1 commit into
mainfrom
litellm_litellm_proxy_forwards_tool_config_cache_point
Oct 20, 2026
Merged

klu-berri merged 1 commit into
mainfrom
litellm_litellm_proxy_forwards_tool_config_cache_point

Conversation

@klu-berri

@klu-berri klu-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • litellm_proxy keeps forwarding cache_control_injection_points in extra_body
  • OpenAI and every other OpenAI SDK provider still never receive the key
  • One line in add_provider_specific_params_to_optional_params, reusing LITELLM_ONLY_PARAMS

User 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

  1. The admin sets model: litellm_proxy/claude-sonnet-4-6, api_base: http://downstream:4001, and cache_control_injection_points: [{location: tool_config, control: {type: ephemeral}}] on the front proxy
  2. A developer sends POST http://front:4000/v1/chat/completions (or /v1/messages) with 40 tools, about 22k tokens of tool descriptions
  3. The response comes back 200 but usage.cache_creation_input_tokens is 0, and the same request a second time reads cache_read_input_tokens: 0
  4. The downstream proxy's request to Anthropic carries the tools with no cache_control on any of them

After: the same config produces a cache write on the first call and a cache read on the second

  1. The admin sets the same litellm_proxy/... deployment with the same cache_control_injection_points entry
  2. The developer sends the same POST http://front:4000/v1/chat/completions
  3. The response shows cache_creation_input_tokens: 22661, and the identical second call shows cache_read_input_tokens: 22661
  4. The downstream proxy's request to Anthropic now has cache_control: {"type": "ephemeral"} on the last tool

Relevant issues

Fixes a regression from #47394, which added LITELLM_ONLY_PARAMS and withheld cache_control_injection_points from the OpenAI SDK extra_body for every provider on that path, including litellm_proxy

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

Two local proxies, both started with python litellm/proxy/proxy_cli.py --config <config> --detailed_debug and local Postgres (sudo service postgresql start, prisma db push). Downstream on :4001 is a real anthropic/claude-sonnet-4-6 deployment with no injection point of its own. Upstream on :4000 routes to it

# downstream.yaml (:4001)
model_list:
  - model_name: claude-sonnet-4-6
    litellm_params:
      model: anthropic/claude-sonnet-4-6
      api_key: os.environ/ANTHROPIC_API_KEY
general_settings:
  master_key: sk-4001

# upstream.yaml (:4000)
model_list:
  - model_name: claude-sonnet-4-6
    litellm_params:
      model: litellm_proxy/claude-sonnet-4-6
      api_base: http://localhost:4001
      api_key: sk-4001
      cache_control_injection_points:
        - location: tool_config
          control:
            type: ephemeral
general_settings:
  master_key: sk-4000

payload.json is a chat request with 40 function tools whose descriptions are about 120 words each (about 22.6k prompt tokens), payload_messages.json is the same tools in Anthropic /v1/messages shape. The same two curls run twice per case

for i in 1 2; do curl -s http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-4000" -H "Content-Type: application/json" -d @payload.json | python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin)['usage']))"; done
for i in 1 2; do curl -s http://localhost:4000/v1/messages -H "Authorization: Bearer sk-4000" -H "Content-Type: application/json" -d @payload_messages.json | python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin)['usage']))"; done
grep "^-d '{'model'" upstream.log | grep -c cache_control_injection_points

Before (5145250)

/v1/chat/completions, two identical calls

  1. Call 1 usage: {"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0}
  2. Call 2 usage: {"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0}
  3. Upstream detailed_debug, the body sent to :4001 ends with 'required': ['query']}}}], 'extra_body': {}} and the grep count for cache_control_injection_points is 0
  4. Downstream detailed_debug, the body sent to https://api.anthropic.com/v1/messages lists tool_39 with no cache_control key on any tool

/v1/messages, two identical calls

  1. Call 1 usage: {"input_tokens": 22991, "output_tokens": 4}
  2. Call 2 usage: {"input_tokens": 22991, "output_tokens": 4}
  3. Upstream body to :4001 again ends with 'extra_body': {}}, grep count 0

After (14b1185)

/v1/chat/completions, two identical calls

  1. Call 1 usage: {"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 22661, "cache_read_input_tokens": 0}
  2. Call 2 usage: {"completion_tokens": 4, "prompt_tokens": 22991, "total_tokens": 22995, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 22661}
  3. Upstream body to :4001 ends with 'extra_body': {'cache_control_injection_points': [{'location': 'tool_config', 'control': {'type': 'ephemeral'}}]}}, grep count 2
  4. Downstream body to https://api.anthropic.com/v1/messages shows the last tool as 'name': 'tool_39', ... 'cache_control': {'type': 'ephemeral'}

/v1/messages, two identical calls

  1. Call 1 usage: {"input_tokens": 330, "output_tokens": 4, "cache_read_input_tokens": 22661} (the 40 tools were already cached by the chat case)
  2. Call 2 usage: {"input_tokens": 330, "output_tokens": 4, "cache_read_input_tokens": 22661}
  3. Upstream body to :4001 carries the same cache_control_injection_points entry, grep count 4

Red leg of the new unit test on the merge base, for reference only, the proof above is the live run

FAILED tests/unit/test_utils.py::test_get_optional_params_forwards_a_tool_config_cache_point_to_a_downstream_litellm_proxy
AssertionError: assert {'kept': True} == {'kept': True, 'cache_control_injection_points': [{'location': 'tool_config', 'control': {'type': 'ephemeral'}}]}

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Only litellm_proxy gets the key back, no other OpenAI SDK provider in openai_compatible_providers is LiteLLM-aware

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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_proxy routes dropped cache_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, but withheld_params is empty for custom_llm_provider == "litellm_proxy", so cache_control_injection_points is forwarded in extra_body again. 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.

…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
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing litellm_litellm_proxy_forwards_tool_config_cache_point (14b1185) with main (5145250)

Open in CodSpeed

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@klu-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk low

Approved at 14b1185.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Cursor Bugbot: Low Risk at 14b1185. Single conditional in optional-param forwarding for one provider; OpenAI paths unchanged and covered by tests. Bugbot run requested, finished in 3 min.
Bugbot Low is low, Medium and High are high. The judge model was not called.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 kerry-berri added the risk:low Small, isolated, low-risk change label Oct 20, 2026

@kerry-berri kerry-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low risk by rule and by judgement at 14b1185

@klu-berri
klu-berri merged commit 04e9ed4 into main Oct 20, 2026
97 checks passed
@klu-berri
klu-berri deleted the litellm_litellm_proxy_forwards_tool_config_cache_point branch October 20, 2026 15:04
pamanseau pushed a commit to KubeTEE-AI/litellm that referenced this pull request Oct 25, 2026
…s to the downstream proxy (BerriAI#47570)

Backport of BerriAI#47570 to stable/1.103.x

Cherry-picked from 04e9ed4 (main)
Cartofante pushed a commit to CartoDB/litellm that referenced this pull request Oct 26, 2026
…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)
yuneng-berri pushed a commit that referenced this pull request Oct 28, 2026
…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)
haowang1013 pushed a commit to directivegames/litellm that referenced this pull request Nov 3, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants