litellm - ✅(Solved) Fix [Bug]: cache_control_injection_points with the Responses API is broken [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#25335Fetched 2026-04-09 07:52:41
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2

PR fix notes

PR #25412: fix(responses): extract cache_control_injection_points from extra_body

Description (problem / solution / changelog)

Relevant issues

Fixes #25335

What's broken

When cache_control_injection_points is passed via extra_body in the Responses API:

client.responses.create(
    model="claude-sonnet-4-6",
    input=messages,
    extra_body={
        "cache_control_injection_points": [
            {"location": "message", "role": "system", "index": 0},
            {"location": "message", "role": "user", "index": -1},
        ]
    },
)

…the AnthropicCacheControlHook never fires. The hook system checks top-level kwargs for cache_control_injection_points (via DynamicPromptManagementParamLiteral), but the Responses API keeps it nested inside extra_body — so should_run_prompt_management_hooks returns False and the injection never happens.

The same call works fine on the Chat Completions API because users pass cache_control_injection_points as a direct kwarg there.

Fix

Before the prompt management hooks run in both responses() and aresponses(), extract any DynamicPromptManagementParam keys from extra_body into kwargs. This mirrors how the Chat Completions path already receives these params.

The extraction is conservative: it only moves keys that are in the DynamicPromptManagementParamLiteral enum, doesn't overwrite existing kwargs, and does nothing if extra_body is not a dict.

Tests

Two unit tests added covering:

  • Extraction moves the key and removes it from extra_body
  • Existing kwargs are not overwritten

All 18 tests in test_anthropic_cache_control_hook.py pass.

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory
  • My PR passes all unit tests on make test-unit (tested locally: 18/18 passed)
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix ✅ Test

Changed files

  • litellm/responses/main.py (modified, +28/-0)
  • tests/test_litellm/integrations/test_anthropic_cache_control_hook.py (modified, +42/-0)

Code Example

Expected output: input_tokens_details.cached_tokens should be > 0 after reaching 5000 input tokens
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

cache_control_injection_points with the Responses API is broken. It works with 1.82.3.

Steps to Reproduce

LONG_TEXT = "A large enough prompt to exceed Anthropic's 1024-token caching minimum"

messages = [ {"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]}, {"role": "user", "content": [{"type": "text", "text": LONG_TEXT}]}, ]

for turn in range(10): response = client.responses.create( model="claude-sonnet-4-6", input=messages, extra_body={ "cache_control_injection_points": [ {"location": "message", "role": "system", "index": 0}, {"location": "message", "role": "user", "index": -1}, ] }, ) usage = response.usage print(f"turn {turn}: input={usage.input_tokens} cached={usage.input_tokens_details.cached_tokens}") messages.append({"role": "assistant", "content": response.output_text}) messages.append({"role": "user", "content": [{"type": "text", "text": "Summarize that in one sentence."}]})

Relevant log output

Expected output: input_tokens_details.cached_tokens should be > 0 after reaching 5000 input tokens

What part of LiteLLM is this about?

No response

What LiteLLM version are you on ?

v1.82.6

Twitter / LinkedIn details

No response

extent analysis

TL;DR

Downgrade to version 1.82.3 to potentially resolve the cache_control_injection_points issue with the Responses API.

Guidance

  • Verify that the issue is specific to version 1.82.6 by testing the same code with version 1.82.3, as mentioned in the issue.
  • Check the documentation for any changes or updates to the cache_control_injection_points feature between versions 1.82.3 and 1.82.6.
  • Review the code to ensure that the extra_body parameters, including cache_control_injection_points, are correctly formatted and match the expected input for the client.responses.create method.
  • Test the code with a smaller input to see if the issue is related to the size of the input or the specific version.

Example

No code snippet is provided as the issue does not require a code change, but rather a potential version downgrade.

Notes

The issue seems to be version-specific, and downgrading to version 1.82.3 may resolve the issue. However, this may not be a long-term solution, and it is recommended to investigate the changes between versions 1.82.3 and 1.82.6 to determine the root cause.

Recommendation

Apply workaround: Downgrade to version 1.82.3, as it is reported to work correctly with the cache_control_injection_points feature.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING