Skip to content

fix(openai): stop stripping cache_control from the caller's own messages and tools - #35602

Merged
mateo-berri merged 15 commits into
BerriAI:mainfrom
vineethsaivs:fix-cache-control-strip-mutates-caller-messages
Oct 31, 2026
Merged

mateo-berri merged 15 commits into
BerriAI:mainfrom
vineethsaivs:fix-cache-control-strip-mutates-caller-messages

Conversation

@vineethsaivs

@vineethsaivs vineethsaivs commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

When an app marks its request with cache_control and an OpenAI-compatible model goes first, LiteLLM removed the hints from the app's request, so a Claude fallback sent none and paid full price. This PR removes them on a copy, and since Claude takes at most 4, it keeps the newest 4 under drop_params and otherwise returns Claude's error. A Gemini fallback now gets them too, so its context caching moves the system prompt into the cache, as Gemini requires

Details

TLDR

Problem this solves:

  • Stripping cache_control for OpenAI-compatible providers edited the caller's request, so Claude fallbacks lost caching

How it solves it:

  • OpenAI, Fireworks AI, Groq, Mistral, DeepInfra, hosted vLLM, watsonx, and xAI strip hints on a copy
  • Under drop_params, Claude on Anthropic, Vertex AI, Bedrock, Azure AI, OpenRouter, and Databricks keeps the newest 4, and /v1/messages passes them unchanged
  • The oldest go first, since the newest hint caches everything before it. Keeping system hints would favor cross-conversation reuse
  • Gemini context caching moves system messages into the cache it creates, which Gemini requires

Logs now keep the caller's hints, opt-in prompt_caching routing pins hinted OpenAI traffic, and a Gemini fallback creates a context cache. Copying 80 messages with 390 KB images takes 0.20 ms

User Flow

Before: an app that marks a long document with cache_control loses prompt caching whenever its OpenAI-compatible model falls back to Claude

  1. The proxy admin sets gpt-5.5 (OpenAI) to fall back to Claude Haiku
  2. The app sends POST https://litellm-domain/v1/responses (or /v1/chat/completions, streamed or not) with "model": "gpt-5.5" and a long document marked "cache_control": {"type": "ephemeral"}
  3. OpenAI rejects the call and Claude answers, with x-litellm-attempted-fallbacks: 1
  4. Every call shows 0 cache write tokens and 0 cached tokens, so each pays for the whole document

After: the same fallback writes the cache once and reads it on every repeat

  1. The proxy admin sets gpt-5.5 (OpenAI) to fall back to Claude Haiku
  2. The app sends POST https://litellm-domain/v1/responses (or /v1/chat/completions, streamed or not) with "model": "gpt-5.5" and a long document marked "cache_control": {"type": "ephemeral"}
  3. OpenAI rejects the call and Claude answers, with x-litellm-attempted-fallbacks: 1
  4. The first call shows about 56k cache write tokens and each repeat about 56k cached tokens
Five hints in one message, with a Claude fallback that has drop_params

Before: an app that marks five parts of one message with cache_control gets no caching from a Claude fallback that has drop_params: true

  1. The proxy admin sets gpt-5.5 to fall back to a Claude deployment on Anthropic, OpenRouter, Vertex AI, Bedrock, Azure AI, or Databricks with drop_params: true
  2. The app sends POST https://litellm-domain/v1/chat/completions (or /v1/responses) with "model": "gpt-5.5" and five text parts, each marked cache_control
  3. OpenAI rejects the call and Claude answers, with x-litellm-attempted-fallbacks: 1
  4. Every call shows 0 cache write tokens and 0 cached tokens

After: Claude keeps the newest 4 hints, so the cache is written once and read on every repeat

  1. The proxy admin sets gpt-5.5 to fall back to a Claude deployment on Anthropic, OpenRouter, Vertex AI, Bedrock, Azure AI, or Databricks with drop_params: true
  2. The app sends POST https://litellm-domain/v1/chat/completions (or /v1/responses) with "model": "gpt-5.5" and five text parts, each marked cache_control
  3. OpenAI rejects the call and Claude answers, with x-litellm-attempted-fallbacks: 1
  4. The first call shows about 61k cache write tokens and each repeat shows about 61k cached tokens

Without drop_params on the Claude deployment, step 4 is instead Claude's "A maximum of 4 blocks with cache_control" error under the first model's status (401 here), where Before gave a 200 with no caching

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

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

Last updated: fbc2685. QA ran on 092d3bc. Since then only the 4-hint cap and Gemini caching changed, and the other cases reach neither. N1, N2, N4, and R1 to R7 ran again at 929a93c, and G1 and G2 at fbc2685

Live calls, no mocks. Each leg runs litellm --config config.yaml --port $PORT --num_workers 2, and each first model has a bad key or dead endpoint

config.yaml
model_list:
  - model_name: gpt-5.5
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: gpt-5.5-drop
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: fw-gpt-oss
    litellm_params:
      model: fireworks_ai/accounts/fireworks/models/gpt-oss-120b
      api_key: sk-litellm-qa-invalid-fireworks-key
  - model_name: kimi
    litellm_params:
      model: moonshot/kimi-k3.1-pro
      api_key: sk-litellm-qa-invalid-moonshot-key
  - model_name: gpt-5.5-live
    litellm_params:
      model: openai/gpt-5.5
      api_key: os.environ/OPENAI_API_KEY
  - model_name: claude-haiku
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: claude-haiku-drop
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
      drop_params: true
  - model_name: gpt-5.5-or
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: gpt-5.5-vx
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: gpt-5.5-bc
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: gpt-5.5-bi
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: claude-or-drop
    litellm_params:
      model: openrouter/anthropic/claude-haiku-5.5
      api_key: os.environ/OPENROUTER_API_KEY
      drop_params: true
  - model_name: claude-vx-drop
    litellm_params:
      model: vertex_ai/claude-haiku-5-5
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
      drop_params: true
  - model_name: claude-bc-drop
    litellm_params:
      model: bedrock/converse/us.anthropic.claude-haiku-5-5
      aws_region_name: us-west-2
      drop_params: true
  - model_name: claude-bi-drop
    litellm_params:
      model: bedrock/invoke/us.anthropic.claude-haiku-5-5
      aws_region_name: us-west-2
      drop_params: true
  - model_name: groq-bad
    litellm_params:
      model: groq/openai/gpt-oss-120b
      api_key: sk-litellm-qa-invalid-groq-key
  - model_name: mistral-bad
    litellm_params:
      model: mistral/mistral-medium-latest
      api_key: sk-litellm-qa-invalid-mistral-key
  - model_name: deepinfra-bad
    litellm_params:
      model: deepinfra/meta-llama/Llama-3.3-70B-Instruct
      api_key: sk-litellm-qa-invalid-deepinfra-key
  - model_name: vllm-dead
    litellm_params:
      model: hosted_vllm/qwen3-32b
      api_base: http://127.0.0.1:9/v1
  - model_name: watsonx-bad
    litellm_params:
      model: watsonx/ibm/granite-3-3-8b-instruct
      api_base: https://us-south.ml.cloud.ibm.com
      token: litellm-qa-invalid-watsonx-token
      project_id: litellm-qa-invalid-project
  - model_name: xai-bad
    litellm_params:
      model: xai/grok-4
      api_key: sk-litellm-qa-invalid-xai-key
  - model_name: gpt-5.5-db
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: gpt-5.5-az
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: gpt-5.5-oc
    litellm_params:
      model: openai/gpt-5.5
      api_key: sk-litellm-qa-invalid-openai-key
  - model_name: claude-db-drop
    litellm_params:
      model: databricks/databricks-claude-haiku-5-5
      api_base: os.environ/DATABRICKS_QA2_API_BASE
      api_key: os.environ/DATABRICKS_QA2_API_KEY
      drop_params: true
  - model_name: claude-az-drop
    litellm_params:
      model: azure_ai/claude-sonnet-5-5
      api_base: os.environ/AZ_CLAUDE_API_BASE
      api_key: os.environ/E2E_CLAUDE_FOUNDRY_API_KEY
      drop_params: true
  - model_name: claude-oc-drop
    litellm_params:
      model: openai/anthropic/claude-haiku-5.5
      api_base: https://openrouter.ai/api/v1
      api_key: os.environ/OPENROUTER_API_KEY
      drop_params: true

router_settings:
  fallbacks: [{"gpt-5.5": ["claude-haiku"]}, {"gpt-5.5-drop": ["claude-haiku-drop"]}, {"fw-gpt-oss": ["claude-haiku"]}, {"kimi": ["claude-haiku"]}, {"gpt-5.5-or": ["claude-or-drop"]}, {"gpt-5.5-vx": ["claude-vx-drop"]}, {"gpt-5.5-bc": ["claude-bc-drop"]}, {"gpt-5.5-bi": ["claude-bi-drop"]}, {"groq-bad": ["claude-haiku"]}, {"mistral-bad": ["claude-haiku"]}, {"deepinfra-bad": ["claude-haiku"]}, {"vllm-dead": ["claude-haiku"]}, {"watsonx-bad": ["claude-haiku"]}, {"xai-bad": ["claude-haiku"]}, {"gpt-5.5-db": ["claude-db-drop"]}, {"gpt-5.5-az": ["claude-az-drop"]}, {"gpt-5.5-oc": ["claude-oc-drop"]}]

general_settings:
  master_key: os.environ/LITELLM_QA_MASTER_KEY

Bodies hold 17k to 65k marked tokens. "cached" means written, then read. All raw output

Case Request Before After
O1 responses, gpt-5.5 none cached
O2 chat, gpt-5.5 none cached
O4 chat, Fireworks AI none cached
N1 chat, 5 hints, drop_params none cached
N2 chat, 5 hints 200, none 401, 4-block error
N4 responses, 5 hints, drop_params none cached
N6 chat streamed, gpt-5.5 none cached
G2 chat, Gemini direct, system prompt 400 200, cached
Controls and G1, plus R1 to R7 (five hints through other Claude routes) and P1 to P6 (other first providers)
Case Request Before After
O3 messages, gpt-5.5 cached cached
O5 chat, valid key 200 "OK" 200 "OK"
O6 responses, valid key 200 "OK" 200 "OK"
G1 chat, Gemini fallback, system prompt 200, no context cache 200, cached
N3 Claude direct, 5 hints 400, 4-block error 400, 4-block error
N5 chat, Moonshot cached cached
R1 chat, 5 hints, OpenRouter none cached
R2 chat, 5 hints, Vertex AI none cached
R3 chat, 5 hints, Bedrock Converse none cached
R4 chat, 5 hints, Bedrock Invoke none cached
R5 chat, 5 hints, Databricks none cached
R6 chat, 5 hints, Azure AI none cached
R7 chat, 5 hints, custom openai/ none cached
P1 chat, Groq none cached
P2 chat, Mistral cached cached
P3 chat, DeepInfra none cached
P4 chat, hosted vLLM none cached
P5 chat, watsonx cached cached
P6 chat, xAI none cached

Before (d18efdf)

O1, /v1/responses

$ ./call.sh O1 1 /v1/responses
$ ./call.sh O1 2 /v1/responses
$ ./call.sh O1 3 /v1/responses
$ cat O1.out
--- O1 call 1 16:33:41
HTTP 200
{"model":"claude-haiku-5-5","usage":{"input_tokens":56520,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":56520,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":56524,"cost":null}}
reply: OK
x-litellm-attempted-fallbacks: 1
--- O1 call 2 16:38:14
HTTP 200
{"model":"claude-haiku-5-5","usage":{"input_tokens":56520,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":56520,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":56524,"cost":null}}
reply: OK
x-litellm-attempted-fallbacks: 1
--- O1 call 3 16:39:53
HTTP 200
{"model":"claude-haiku-5-5","usage":{"input_tokens":56520,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":56520,"video_tokens":null},"output_tokens":34,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":30,"text_tokens":4},"total_tokens":56554,"cost":null}}
reply: OK
x-litellm-attempted-fallbacks: 1

After (092d3bc)

O1 again

$ ./call.sh O1 1 /v1/responses
$ ./call.sh O1 2 /v1/responses
$ ./call.sh O1 3 /v1/responses
$ cat O1.out
--- O1 call 1 16:33:45
HTTP 200
{"model":"claude-haiku-5-5","usage":{"input_tokens":56520,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":56506,"image_tokens":null,"text_tokens":14,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":56524,"cost":null}}
reply: OK
x-litellm-attempted-fallbacks: 1
--- O1 call 2 16:38:15
HTTP 200
{"model":"claude-haiku-5-5","usage":{"input_tokens":56520,"input_tokens_details":{"audio_tokens":null,"cached_tokens":56506,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":14,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":56524,"cost":null}}
reply: OK
x-litellm-attempted-fallbacks: 1
--- O1 call 3 16:39:47
HTTP 200
{"model":"claude-haiku-5-5","usage":{"input_tokens":56520,"input_tokens_details":{"audio_tokens":null,"cached_tokens":56506,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":14,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":56524,"cost":null}}
reply: OK
x-litellm-attempted-fallbacks: 1

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Without drop_params, a Claude fallback given over 4 hints now returns Claude's 4-block error instead of a 200 without caching
  • Hosted vLLM, Mistral file blocks, and Azure chat still edit the caller's messages, as on the base
  • A hinted message nested about 800 levels deep now fails to copy
  • A tool schema property named cache_control is still dropped, as on the base
  • The new copy helper sits beside the Responses bridge's top-level-only strip
  • Bedrock Converse trims only when the model or base_model names Claude, so an inference profile ARN needs base_model
  • Bedrock Converse reserves room only for tool hints, so an injected tool_config cache point is not counted
  • Optional OSV Scan flags pyasn1, pypdf, and minimatch lockfile entries that build(deps): bump pyasn1, pypdf and minimatch to clear osv-scan #49362 already fixed on main

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

@vineethsaivs vineethsaivs changed the title Stop stripping cache_control from the caller's own messages and tools fix(openai): stop stripping cache_control from the caller's own messages and tools Aug 2, 2026
@greptile-apps

greptile-apps Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge with both previous findings addressed

Summary

The PR keeps the caller's cache hints when preparing requests for providers that cannot read them. Claude requests keep the newest four message hints under drop_params. Gemini now puts system prompts into the context cache

The latest changes address both previous findings. No new actionable issue was found

  • Provider request shaping leaves the caller's cache hints intact.
  • Claude requests keep the newest four cache hints when drop_params is on.
  • Gemini context caches include system messages alongside marked conversation blocks.

Reviews (8) · Last reviewed commit: "fix(vertex_ai): put every system message..." · Reviewed by Greptile

@codecov

codecov Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.13433% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...tellm/integrations/anthropic_cache_control_hook.py 96.26% 4 Missing ⚠️
litellm/llms/openai/chat/gpt_transformation.py 98.43% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing vineethsaivs:fix-cache-control-strip-mutates-caller-messages (fbc2685) with main (a392a39)

Open in CodSpeed

@Sanjays2402

Copy link
Copy Markdown

the Responses API sibling still has this exact bug: remove_cache_control_flag_from_input_and_tools in litellm/llms/openai/responses/transformation.py calls filter_value_from_dict on each input item/tool in place and its docstring even says so ("mutates each dict in place, so the same objects are returned"). so a caller who reuses their input list after a responses call loses cache_control the same way. worth deepcopying there too while you're here?

@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch from 4c01e47 to ff6350a Compare August 3, 2026 16:16
@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Pushed a fixup for the lint red: the annotation on new_tools used a quoted "ChatCompletionToolParam", which trips UP037 in the strict-rule budget since the name is imported unquoted a few lines above. Dropped the annotation. ruff check --config ruff-strict.toml --statistics now reports the identical 15 findings on the changed file as on the unmodified one, so the budget total is unchanged against the base.

@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Second lint fixup. The type-discipline budget flagged LIT002: total 27276 over limit 27256 (this change added 2): the two list comprehensions are new collection construction, where the old code mutated the incoming lists in place and constructed nothing. The declared return type is tuple[list[AllMessageValues], list[ChatCompletionToolParam] | None], so freezing them into tuples is not available without changing the signature and every caller; added # mutable-ok: with that reason on each, which is the escape the rule text names.

Checked against the unmodified file rather than in isolation: scripts/check_type_discipline.py now reports the identical totals on both (LIT001 62, LIT002 23, LIT006 15, LIT009 5), ruff check --config ruff-strict.toml --statistics diffs clean against it, and ruff.toml check and format are clean.

@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch from ff6350a to f4614c1 Compare August 3, 2026 16:39
@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Good catch, and you are right. Done in 77a00a9.

I reproduced it before touching anything rather than going off the docstring. _validate_input_param builds a new list but passes plain dict items through by reference (filtered_item = cast(dict[str, Any], item)), so the new list still holds the caller's dicts and filter_value_from_dict edits them:

outbound body stripped: True
caller's input unchanged: False
caller's tools unchanged: False
  caller's first content block now: [{"type": "input_text", "text": "a very long cached system prompt"}]

Same fix shape as the chat path, and the docstring line that stated the in-place behaviour as a fact is corrected rather than left to mislead the next reader.

I had flagged this one as a deliberate follow-up in the PR body because it is a second API surface and litellm's own checklist asks for isolated scope. Since you would rather have it here, here it is; the two are one defect with one cause, so keeping them together is easy to argue.

Regression test added to the mapped Responses test file, next to the existing test_transform_strips_cache_control_from_* pair: it asserts the outbound body is still stripped and that the caller's input and tools compare equal to a deepcopy taken beforehand. It fails on the previous commit and passes now.

On the three lint gates, checked against the unmodified file rather than in isolation: ruff.toml check and format clean, ruff check --config ruff-strict.toml --statistics diffs identical, and scripts/check_type_discipline.py reports the same totals on both (LIT001 30, LIT002 27, LIT006 5, LIT009 1). The two list comprehensions carry # mutable-ok: because the declared return types are ResponseInputParam and List[ALL_RESPONSES_API_TOOL_PARAMS], and I dropped one of the two new casts so LIT006 stays net-zero rather than leaning on a second suppression.

@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch 2 times, most recently from 14e4811 to 5215469 Compare August 27, 2026 17:09
@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch from 5215469 to 6b50e7d Compare September 8, 2026 19:26
@vineethsaivs
vineethsaivs requested a review from a team September 8, 2026 19:26
@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Rebased onto litellm_internal_staging, and the fix changed shape because of what the rebase surfaced.

Copying every message and tool unconditionally broke two assertions that were added upstream in the meantime, test_clean_object_schema_passes_through_as_same_object and test_openai_keeps_combinators_for_models_that_accept_them, both of which require the same object back when nothing needed changing.

So the strip now goes through without_cache_control in llms/openai/common_utils.py, which returns the item untouched when there is no cache_control anywhere in it and only deep-copies when there is. That keeps the identity contract and drops a deep copy from every request that has no cache breakpoints, which is most of them.

tests/test_litellm/llms/openai: 915 passed.

@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch 2 times, most recently from d37c498 to b832e17 Compare September 8, 2026 19:49
@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:38
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch from b832e17 to 965b59e Compare September 18, 2026 19:27
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 15:20
@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch from 965b59e to 2750687 Compare September 26, 2026 22:24
@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Rebased onto main as a single commit. The diff had picked up unrelated staging commits after the retarget; it now contains only this fix.

@vineethsaivs
vineethsaivs force-pushed the fix-cache-control-strip-mutates-caller-messages branch 2 times, most recently from 6487f55 to 1c84934 Compare October 23, 2026 03:07
# Conflicts:
#	tests/unit/llms/mistral/test_mistral_chat_transformation.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…on OpenAI-compatible Claude routes under drop_params
# Conflicts:
#	litellm/llms/openai/common_utils.py
#	tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py
#	tests/unit/llms/mistral/test_mistral_chat_transformation.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…model, and Converse tool messages

The 4-hint cap now reads drop_params through drops_unsupported_params on chat, Converse, and Anthropic routes, names Claude by base_model on OpenAI-compatible routes, and counts a Converse tool message's hints as the one cache point it sends.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@veria-ai

veria-ai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

# Conflicts:
#	tests/unit/llms/openrouter/chat/test_openrouter_chat_transformation.py

@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.

Stale Bugbot comment from a previous run.

…rve a top-level cache_control on OpenAI-compatible routes

Dropping the oldest hint one at a time re-walked the whole request per hint, which took seconds on long tool histories. The cap now drops each message's oldest hints in the order the provider counts them, so a string assistant turn loses its text hint before its tool call hints. OpenAI-compatible Claude routes also keep room for a request-level or extra_body cache_control under drop_params.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-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.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-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 fbc2685. Configure here.

@mateo-berri mateo-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.

LGTM. Thanks for the contribution!

@mateo-berri
mateo-berri merged commit a7b66dd into BerriAI:main Oct 31, 2026
143 of 146 checks passed
mateo-berri added a commit that referenced this pull request Oct 31, 2026
…#49192 and #35602 in their integration tests (#49468)

* fix(caching): stop counting an unrun server tool call mark, and follow #49192 and #35602 in their integration tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(caching): return the server tool call id instead of a TypeGuard

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(integration): assert the Gemini cache write carries the system prompt

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants