Skip to content

fix: apply configured cache_control_injection_points beside client cache_control marks - #41956

Merged
mateo-berri merged 9 commits into
mainfrom
litellm_explicit_cache_injection_points_survive_client_marks
Sep 21, 2026
Merged

mateo-berri merged 9 commits into
mainfrom
litellm_explicit_cache_injection_points_survive_client_marks

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Configured cache_control_injection_points vanish whenever the client marks any cache_control itself
  • The operator's rolling-tail checkpoint never lands, so every turn is billed uncached
  • Nothing in the response or the logs says the configured point was dropped

How it solves it:

  • Configured points always apply; a target the client already marked is left as is
  • Client marks on messages, system, tools, a root cache_control, and the same fields sent inside extra_body count toward Anthropic's 4-block cap first
  • Only the automatic defaults (enable_anthropic_prompt_caching) still stand down on client marks

User Flow

Before: the operator's configured tail checkpoint is dropped the moment the client marks anything, so the conversation is billed at full price on every turn

  1. The operator adds a deployment sonnet-tail-cached for anthropic/claude-sonnet-5 with cache_control_injection_points: [{location: message, index: -1}] and restarts the gateway
  2. Their app sends POST https://litellm-domain/v1/chat/completions for sonnet-tail-cached with a 6.5k-token system message it marked cache_control: {type: ephemeral} itself, followed by a 5k-token conversation
  3. 200, usage.prompt_tokens_details.cached_tokens is 0 and cache_creation_input_tokens is 6563: only the system block was written to the cache
  4. The app sends the same request again: cached_tokens is 6563 and the 5k-token conversation is billed uncached again
  5. The same app on POST https://litellm-domain/v1/messages sees cache_read_input_tokens 6563 and input_tokens 4974 on every turn
  6. The operator's cache hit rate metric drops and nothing in the response or the gateway logs explains why

After: the configured tail checkpoint lands beside the client's own mark, so the second turn reads the whole prefix from cache

  1. The operator adds a deployment sonnet-tail-cached for anthropic/claude-sonnet-5 with cache_control_injection_points: [{location: message, index: -1}] and restarts the gateway
  2. Their app sends POST https://litellm-domain/v1/chat/completions for sonnet-tail-cached with a 6.5k-token system message it marked cache_control: {type: ephemeral} itself, followed by a 5k-token conversation
  3. 200, cache_creation_input_tokens is 11535: the system block and the conversation up to the last user turn were both written to the cache
  4. The app sends the same request again: cached_tokens is 11535 and only the new tokens are billed
  5. The same app on POST https://litellm-domain/v1/messages sees cache_read_input_tokens 11535 and input_tokens 2
  6. A request that already carries four client marks (three user turns plus a tool) still gets 200, because a configured point that would be the fifth block is skipped instead of tripping Anthropic's "A maximum of 4 blocks with cache_control may be provided" error

Relevant issues

Fixes #40675

Related: #38684 counts client-marked tools in the chat/completions census; this PR carries that count on both endpoints, so #38684 is superseded once this lands

Affected release

Introduced in v1.95.0 by #33886, which made configured points stand down the same way the automatic defaults do, and present in every release since

Linear ticket

Resolves LIT-7586

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • 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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Screenshots / Proof of Fix

Both legs are a real proxy booted from that exact commit with 2 uvicorn workers, hitting Anthropic, OpenAI, and Bedrock for real. The hook keeps no state between requests, so one 2-worker process per leg is the topology on both sides. Before ran on port 20641 from the merge base 1fcef68 and After on port 37384 from the PR tip f567fe2

Config, identical on both legs:

model_list:
  - model_name: sonnet-tail-cached
    litellm_params:
      model: anthropic/claude-sonnet-5
      api_key: os.environ/ANTHROPIC_API_KEY
      cache_control_injection_points:
        - location: message
          index: -1
  - model_name: sonnet-system-cached
    litellm_params:
      model: anthropic/claude-sonnet-5
      api_key: os.environ/ANTHROPIC_API_KEY
      cache_control_injection_points:
        - location: message
          role: system
  - model_name: sonnet-plain
    litellm_params:
      model: anthropic/claude-sonnet-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: gpt56-tail-cached
    litellm_params:
      model: openai/gpt-5.6
      api_key: os.environ/OPENAI_API_KEY
      cache_control_injection_points:
        - location: message
          index: -1
  - model_name: bedrock-sonnet5-toolcfg
    litellm_params:
      model: bedrock/us.anthropic.claude-sonnet-5
      aws_region_name: us-east-1
      cache_control_injection_points:
        - location: tool_config
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
litellm_settings:
  drop_params: false

Boot command, identical on both legs apart from the checkout and the port:

$ python litellm/proxy/proxy_cli.py --config qa_config.yaml --port <port> --num_workers 2

Payloads, with the long filler text elided. Each leg got its own salt inside the filler so neither leg could read the other's cache. Within a leg, chat.json and messages.json share a prefix (the same goes for each chat and messages pair below), which is why the /v1/messages cases already read from cache on their first request:

# chat.json
{"model": "sonnet-tail-cached", "max_tokens": 40, "messages": [{"role": "system", "content": [{"type": "text", "text": "<21811 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "user", "content": "<13211 chars of filler text>"}, {"role": "assistant", "content": "Noted, the tiered rate applies above 1000 kWh."}, {"role": "user", "content": "Which clause covers a disputed meter reading? Answer in one short sentence."}]}
# messages.json
{"model": "sonnet-tail-cached", "max_tokens": 40, "system": [{"type": "text", "text": "<21811 chars of filler text>", "cache_control": {"type": "ephemeral"}}], "messages": [{"role": "user", "content": "<13211 chars of filler text>"}, {"role": "assistant", "content": "Noted, the tiered rate applies above 1000 kWh."}, {"role": "user", "content": "Which clause covers a disputed meter reading? Answer in one short sentence."}]}
# responses.json
{"model": "sonnet-tail-cached", "max_output_tokens": 40, "input": [{"role": "system", "content": [{"type": "input_text", "text": "<21971 chars of filler text>"}]}, {"role": "user", "content": [{"type": "input_text", "text": "<404 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": [{"type": "output_text", "text": "Understood."}]}, {"role": "user", "content": [{"type": "input_text", "text": "<16331 chars of filler text>"}]}, {"role": "assistant", "content": [{"type": "output_text", "text": "Noted, the tiered rate applies above 1000 kWh."}]}, {"role": "user", "content": [{"type": "input_text", "text": "Which clause covers a disputed meter reading? Answer in one short sentence."}]}]}
# chat_cap.json
{"model": "sonnet-system-cached", "max_tokens": 40, "tools": [{"type": "function", "function": {"name": "lookup_clause", "description": "<5110 chars of filler text>", "parameters": {"type": "object", "properties": {"clause": {"type": "string"}}}}, "cache_control": {"type": "ephemeral"}}], "messages": [{"role": "system", "content": "<7910 chars of filler text>"}, {"role": "user", "content": [{"type": "text", "text": "<5070 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted."}, {"role": "user", "content": [{"type": "text", "text": "<5070 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted again."}, {"role": "user", "content": [{"type": "text", "text": "Which clause covers a disputed meter reading? One short sentence.", "cache_control": {"type": "ephemeral"}}]}]}
# messages_cap.json
{"model": "sonnet-system-cached", "max_tokens": 40, "system": "<7910 chars of filler text>", "tools": [{"name": "lookup_clause", "description": "<5110 chars of filler text>", "input_schema": {"type": "object", "properties": {"clause": {"type": "string"}}}, "cache_control": {"type": "ephemeral"}}], "messages": [{"role": "user", "content": [{"type": "text", "text": "<5070 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted."}, {"role": "user", "content": [{"type": "text", "text": "<5070 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted again."}, {"role": "user", "content": [{"type": "text", "text": "Which clause covers a disputed meter reading? One short sentence.", "cache_control": {"type": "ephemeral"}}]}]}
# chat_openai.json
{"model": "gpt56-tail-cached", "max_tokens": 40, "messages": [{"role": "system", "content": [{"type": "text", "text": "<21811 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "user", "content": "<13211 chars of filler text>"}, {"role": "assistant", "content": "Noted, the tiered rate applies above 1000 kWh."}, {"role": "user", "content": "Which clause covers a disputed meter reading? Answer in one short sentence."}]}
# messages_openai.json
{"model": "gpt56-tail-cached", "max_tokens": 40, "system": [{"type": "text", "text": "<21811 chars of filler text>", "cache_control": {"type": "ephemeral"}}], "messages": [{"role": "user", "content": "<13211 chars of filler text>"}, {"role": "assistant", "content": "Noted, the tiered rate applies above 1000 kWh."}, {"role": "user", "content": "Which clause covers a disputed meter reading? Answer in one short sentence."}]}
# bedrock_chat_cap.json
{"model": "bedrock-sonnet5-toolcfg", "max_tokens": 40, "tools": [{"type": "function", "function": {"name": "lookup_clause", "description": "<5030 chars of filler text>", "parameters": {"type": "object", "properties": {"clause": {"type": "string"}}}}}], "messages": [{"role": "system", "content": [{"type": "text", "text": "<7790 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "user", "content": [{"type": "text", "text": "<4990 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted."}, {"role": "user", "content": [{"type": "text", "text": "<4990 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted again."}, {"role": "user", "content": [{"type": "text", "text": "<5070 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted thrice."}, {"role": "user", "content": "Which clause covers a disputed meter reading? One short sentence."}]}
# messages_bedrock_cap.json
{"model": "bedrock-sonnet5-toolcfg", "max_tokens": 40, "system": [{"type": "text", "text": "<7790 chars of filler text>", "cache_control": {"type": "ephemeral"}}], "tools": [{"name": "lookup_clause", "description": "<5030 chars of filler text>", "input_schema": {"type": "object", "properties": {"clause": {"type": "string"}}}}], "messages": [{"role": "user", "content": [{"type": "text", "text": "<4990 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted."}, {"role": "user", "content": [{"type": "text", "text": "<4990 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted again."}, {"role": "user", "content": [{"type": "text", "text": "<5070 chars of filler text>", "cache_control": {"type": "ephemeral"}}]}, {"role": "assistant", "content": "Noted thrice."}, {"role": "user", "content": "Which clause covers a disputed meter reading? One short sentence."}]}

The Bedrock tool_config cases were added after Bugbot's review. At the previous tip 171b33a the Bedrock /v1/chat/completions request below returned 400 with "A maximum of 4 blocks with cache_control may be provided. Found 5.", and the PR tip f567fe2 carries the fix

Before (1fcef68)

/v1/chat/completions: client-marked system block plus the configured tail point

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/chat.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 11537, "total_tokens": 11577, "completion_tokens_details": {"reasoning_tokens": 40, "text_tokens": 0}, "prompt_tokens_details": {"cached_tokens": 0, "text_tokens": 4974, "cache_write_tokens": 6563, "cache_creation_tokens": 6563, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 6563, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 6563, "cache_read_input_tokens": 0, "inference_geo": "global", "service_tier": "standard"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/chat.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 11537, "total_tokens": 11577, "completion_tokens_details": {"reasoning_tokens": 39, "text_tokens": 1}, "prompt_tokens_details": {"cached_tokens": 6563, "text_tokens": 4974, "cache_write_tokens": 0, "cache_creation_tokens": 0, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 6563, "inference_geo": "global", "service_tier": "standard"}}
    

/v1/messages: client-marked system block plus the configured tail point

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages.json
    HTTP 200
    {"usage": {"input_tokens": 4974, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 6563, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard", "inference_geo": "global"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages.json
    HTTP 200
    {"usage": {"input_tokens": 4974, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 6563, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 40}, "service_tier": "standard", "inference_geo": "global"}}
    

/v1/responses: client-marked user turn plus the configured tail point

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/responses.json
    HTTP 200
    {"usage": {"input_tokens": 12071, "input_tokens_details": {"audio_tokens": null, "cached_tokens": 0, "cached_tokens_details": null, "image_tokens": null, "text_tokens": 2, "video_tokens": null, "cache_write_tokens": 12069}, "output_tokens": 40, "output_tokens_details": {"audio_tokens": null, "reasoning_tokens": 39, "text_tokens": 1}, "total_tokens": 12111, "cost": null}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/responses.json
    HTTP 200
    {"usage": {"input_tokens": 12071, "input_tokens_details": {"audio_tokens": null, "cached_tokens": 12069, "cached_tokens_details": null, "image_tokens": null, "text_tokens": 2, "video_tokens": null, "cache_write_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"audio_tokens": null, "reasoning_tokens": 39, "text_tokens": 1}, "total_tokens": 12111, "cost": null}}
    

/v1/chat/completions: four client marks already fill the cap

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7896, "total_tokens": 7936, "completion_tokens_details": {"reasoning_tokens": 38, "text_tokens": 2}, "prompt_tokens_details": {"cached_tokens": 0, "text_tokens": 2, "cache_write_tokens": 7894, "cache_creation_tokens": 7894, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 7894, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 7894, "cache_read_input_tokens": 0, "inference_geo": "global", "service_tier": "standard"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7896, "total_tokens": 7936, "completion_tokens_details": {"reasoning_tokens": 39, "text_tokens": 1}, "prompt_tokens_details": {"cached_tokens": 7894, "text_tokens": 2, "cache_write_tokens": 0, "cache_creation_tokens": 0, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 7894, "inference_geo": "global", "service_tier": "standard"}}
    

/v1/messages: four client marks already fill the cap

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages_cap.json
    HTTP 200
    {"usage": {"input_tokens": 2, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 7894, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard", "inference_geo": "global"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages_cap.json
    HTTP 200
    {"usage": {"input_tokens": 2, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 7894, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard", "inference_geo": "global"}}
    

/v1/chat/completions to OpenAI gpt-5.6

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/chat_openai.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7329, "total_tokens": 7369, "completion_tokens_details": {"accepted_prediction_tokens": 0, "audio_tokens": 0, "reasoning_tokens": 40, "rejected_prediction_tokens": 0}, "prompt_tokens_details": {"audio_tokens": 0, "cached_tokens": 0, "cache_write_tokens": 7326, "cache_creation_tokens": 7326}}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/chat_openai.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7329, "total_tokens": 7369, "completion_tokens_details": {"accepted_prediction_tokens": 0, "audio_tokens": 0, "reasoning_tokens": 40, "rejected_prediction_tokens": 0}, "prompt_tokens_details": {"audio_tokens": 0, "cached_tokens": 7326, "cache_write_tokens": 0, "cache_creation_tokens": 0}}}
    

/v1/messages to OpenAI gpt-5.6

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages_openai.json
    HTTP 200
    {"usage": {"input_tokens": 3, "output_tokens": 40, "cache_creation_input_tokens": 7326}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages_openai.json
    HTTP 200
    {"usage": {"input_tokens": 3, "output_tokens": 40, "cache_read_input_tokens": 7326}}
    

/v1/chat/completions to Bedrock: tool_config point with four client marks

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/bedrock_chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 9332, "total_tokens": 9372, "completion_tokens_details": {}, "prompt_tokens_details": {"cached_tokens": 0, "text_tokens": 34, "cache_write_tokens": 9298, "cache_creation_tokens": 9298, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 9298, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 9298, "cache_read_input_tokens": 0}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/bedrock_chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 9332, "total_tokens": 9372, "completion_tokens_details": {}, "prompt_tokens_details": {"cached_tokens": 9298, "text_tokens": 34, "cache_write_tokens": 0, "cache_creation_tokens": 0}, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 9298}}
    

/v1/messages to Bedrock: tool_config point with four client marks

  1. Send the request

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages_bedrock_cap.json
    HTTP 200
    {"usage": {"input_tokens": 34, "cache_creation_input_tokens": 9293, "cache_read_input_tokens": 0, "cache_creation": {"ephemeral_5m_input_tokens": 9293, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:20641/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_base7/messages_bedrock_cap.json
    HTTP 200
    {"usage": {"input_tokens": 34, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 9293, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard"}}
    

After (f567fe2)

/v1/chat/completions: client-marked system block plus the configured tail point

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/chat.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 11537, "total_tokens": 11577, "completion_tokens_details": {"reasoning_tokens": 39, "text_tokens": 1}, "prompt_tokens_details": {"cached_tokens": 0, "text_tokens": 2, "cache_write_tokens": 11535, "cache_creation_tokens": 11535, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 11535, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 11535, "cache_read_input_tokens": 0, "inference_geo": "global", "service_tier": "standard"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/chat.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 11537, "total_tokens": 11577, "completion_tokens_details": {"reasoning_tokens": 39, "text_tokens": 1}, "prompt_tokens_details": {"cached_tokens": 11535, "text_tokens": 2, "cache_write_tokens": 0, "cache_creation_tokens": 0, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 11535, "inference_geo": "global", "service_tier": "standard"}}
    

/v1/messages: client-marked system block plus the configured tail point

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages.json
    HTTP 200
    {"usage": {"input_tokens": 2, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 11535, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard", "inference_geo": "global"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages.json
    HTTP 200
    {"usage": {"input_tokens": 2, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 11535, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 40}, "service_tier": "standard", "inference_geo": "global"}}
    

/v1/responses: client-marked user turn plus the configured tail point

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/responses.json
    HTTP 200
    {"usage": {"input_tokens": 11788, "input_tokens_details": {"audio_tokens": null, "cached_tokens": 6563, "cached_tokens_details": null, "image_tokens": null, "text_tokens": 2, "video_tokens": null, "cache_write_tokens": 5223}, "output_tokens": 40, "output_tokens_details": {"audio_tokens": null, "reasoning_tokens": 39, "text_tokens": 1}, "total_tokens": 11828, "cost": null}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/responses.json
    HTTP 200
    {"usage": {"input_tokens": 11788, "input_tokens_details": {"audio_tokens": null, "cached_tokens": 11786, "cached_tokens_details": null, "image_tokens": null, "text_tokens": 2, "video_tokens": null, "cache_write_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"audio_tokens": null, "reasoning_tokens": 39, "text_tokens": 1}, "total_tokens": 11828, "cost": null}}
    

/v1/chat/completions: four client marks already fill the cap

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7536, "total_tokens": 7576, "completion_tokens_details": {"reasoning_tokens": 29, "text_tokens": 11}, "prompt_tokens_details": {"cached_tokens": 0, "text_tokens": 2, "cache_write_tokens": 7534, "cache_creation_tokens": 7534, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 7534, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 7534, "cache_read_input_tokens": 0, "inference_geo": "global", "service_tier": "standard"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7536, "total_tokens": 7576, "completion_tokens_details": {"reasoning_tokens": 32, "text_tokens": 8}, "prompt_tokens_details": {"cached_tokens": 7534, "text_tokens": 2, "cache_write_tokens": 0, "cache_creation_tokens": 0, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 7534, "inference_geo": "global", "service_tier": "standard"}}
    

/v1/messages: four client marks already fill the cap

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages_cap.json
    HTTP 200
    {"usage": {"input_tokens": 2, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 7534, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard", "inference_geo": "global"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages_cap.json
    HTTP 200
    {"usage": {"input_tokens": 2, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 7534, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 40}, "service_tier": "standard", "inference_geo": "global"}}
    

/v1/chat/completions to OpenAI gpt-5.6

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/chat_openai.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7609, "total_tokens": 7649, "completion_tokens_details": {"accepted_prediction_tokens": 0, "audio_tokens": 0, "reasoning_tokens": 40, "rejected_prediction_tokens": 0}, "prompt_tokens_details": {"audio_tokens": 0, "cached_tokens": 0, "cache_write_tokens": 7606, "cache_creation_tokens": 7606}}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/chat_openai.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 7609, "total_tokens": 7649, "completion_tokens_details": {"accepted_prediction_tokens": 0, "audio_tokens": 0, "reasoning_tokens": 40, "rejected_prediction_tokens": 0}, "prompt_tokens_details": {"audio_tokens": 0, "cached_tokens": 7606, "cache_write_tokens": 0, "cache_creation_tokens": 0}}}
    

/v1/messages to OpenAI gpt-5.6

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages_openai.json
    HTTP 200
    {"usage": {"input_tokens": 3, "output_tokens": 40, "cache_creation_input_tokens": 7606}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages_openai.json
    HTTP 200
    {"usage": {"input_tokens": 3, "output_tokens": 40, "cache_read_input_tokens": 7606}}
    

/v1/chat/completions to Bedrock: tool_config point with four client marks

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/bedrock_chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 9112, "total_tokens": 9152, "completion_tokens_details": {}, "prompt_tokens_details": {"cached_tokens": 0, "text_tokens": 34, "cache_write_tokens": 9078, "cache_creation_tokens": 9078, "cache_creation_token_details": {"ephemeral_5m_input_tokens": 9078, "ephemeral_1h_input_tokens": 0}}, "cache_creation_input_tokens": 9078, "cache_read_input_tokens": 0}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/bedrock_chat_cap.json
    HTTP 200
    {"usage": {"completion_tokens": 40, "prompt_tokens": 9112, "total_tokens": 9152, "completion_tokens_details": {}, "prompt_tokens_details": {"cached_tokens": 9078, "text_tokens": 34, "cache_write_tokens": 0, "cache_creation_tokens": 0}, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 9078}}
    

/v1/messages to Bedrock: tool_config point with four client marks

  1. Send the request

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages_bedrock_cap.json
    HTTP 200
    {"usage": {"input_tokens": 34, "cache_creation_input_tokens": 9073, "cache_read_input_tokens": 0, "cache_creation": {"ephemeral_5m_input_tokens": 9073, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 40}, "service_tier": "standard"}}
    
  2. Send the same request again

    $ curl -s http://127.0.0.1:37384/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d @qa_head9/messages_bedrock_cap.json
    HTTP 200
    {"usage": {"input_tokens": 34, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 9073, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, "output_tokens": 40, "output_tokens_details": {"thinking_tokens": 39}, "service_tier": "standard"}}
    

Regression check: /v1/messages with a direct marked tool and an extra_body copy that unmarks it

The request marks the system block, two user turns, and the lookup_clause tool directly, and repeats the tool list unmarked inside extra_body. The native /v1/messages route keeps the direct tool and drops the envelope, so the wire already carries four client marks and a configured point would be the fifth. Each row is that request through a proxy booted from the named commit, with a recorder in front of Anthropic counting the cache_control blocks the gateway actually sent

Commit Response Blocks on the wire
1fcef68 (merge base) 200 4
827d1c9 (previous tip) 400, "Found 5" 5
f567fe2 (tip) 200 4
ba711c4d68 (tip merged with main 4b2e96a) 200 4

Type

🐛 Bug Fix

Caveats (if any)

Low

  • OpenAI-dialect deployments with a configured point now send explicit caching when the client marks
    • Before, a client mark made the configured point stand down there too, the same drop this PR fixes on Anthropic
    • Set prompt_cache_options: {mode: implicit} on the deployment to opt out
    • Usage numbers were identical on both legs
    • Left as is: skipping OpenAI here would keep the drop on those deployments, and special-casing the cache mode would pick a default OpenAI has not documented
  • /v1/responses already applied configured points at the merge base
    • Both legs return identical usage there; this PR leaves it alone
  • /v1/messages to OpenAI sometimes returns zero usage
    • Seen on both legs (1 of 11 before, 2 of 11 after)
    • Pre-existing in the bridge; this PR leaves it alone
  • Tool-search tool marks count on /v1/messages, not on chat seeding
  • A tool_config point has no effect on /v1/messages to Bedrock
    • Same at the merge base; this PR leaves it alone
  • The Bedrock tool_config cases pass on both legs
    • They guard the 400 seen at the earlier tip 171b33a
  • On /v1/messages the cap reserves the larger of the direct and extra_body censuses
    • The hook runs before the native and bridge routes split
    • Native keeps the direct marks and drops the envelope; the bridge merges the envelope
    • A client that marks a tool directly and unmarks it through extra_body loses one point on a bridged deployment, never a 400
  • Test expectation flipped in f567fe2: the extra_body_unmarks /v1/messages case now expects the configured system point skipped
    • Its direct marked tool stays on the wire, and the old expectation returned a live Anthropic 400 (regression check above)
  • Non-required CircleCI jobs integration-extensions and logging_testing are red at the tip; main fixed both after the merge base 1fcef68

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
  • f567fe2 passes /live-pr-risk

Note

Medium Risk
Changes prompt-caching behavior for deployments that mix client marks with gateway-configured injection points; cap logic touches Bedrock and extra_body merging, though behavior is heavily tested.

Overview
Configured cache_control_injection_points are no longer dropped when the client already set cache_control on messages, system, tools, or a root cache_control (including the same fields via extra_body). They are applied in config order, skip targets the client already marked, and stay within Anthropic’s four-block limit. Automatic defaults from enable_anthropic_prompt_caching still stand down when any client breakpoint is present.

The hook now censuses “external” breakpoints (count_external_cache_breakpoints), reserves that budget plus Bedrock tool_config slots (_blocks_reserved_outside_messages), and drops a forwarded tool_config point when the cap is full (_points_with_a_slot_left). Chat seeding stamps the external count on points (_litellm_external_breakpoints) and ignores tool-search tool types that never carry marks upstream. The old _litellm_judged / stand-down path for configured points is removed.

Reviewed by Cursor Bugbot for commit 827d1c9. Bugbot is set up for automated code reviews on this repo. Configure here.

…che_control marks

Configured injection points were dropped whenever the request already
carried a client-set cache_control anywhere, so an operator's rolling
tail checkpoint silently never landed once a caller marked its own
system prompt. Only the automatic defaults stand down now. Configured
points skip a target the client already marked and stay under the
provider's 4-block cap, counting the client's marks on messages, system,
tools and the root cache_control first. The chat path carries the tool
count as a stamp on the points because the prompt-management hook never
receives tools.

Fixes #40675
@devin-ai-integration

devin-ai-integration Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author

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

@codspeed

codspeed Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_explicit_cache_injection_points_survive_client_marks (f567fe2) with main (36b8be7)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (4b2e96a) during the generation of this report, so 36b8be7 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR is not yet safe to merge because the unresolved route census can still suppress a configured cache checkpoint that the final provider request has capacity to accept.

Findings

  1. P1 Route Census Drops Checkpoint ▶
  2. P2 Inline Stamp Violates Placement ▶
  3. P2 Provider Logic Misplaced ▶

Summary

This PR changes Anthropic prompt-cache injection so configured checkpoints coexist with client-provided marks while respecting provider breakpoint limits.

  • Counts client marks across messages, system content, tools, root cache controls, and extra_body.
  • Preserves automatic caching’s existing stand-down behavior.
  • Adds Bedrock tool_config capacity handling and broad regression coverage.

Reviews (9) · Last reviewed commit: "fix: reserve cap slots for direct marks ..."

# rather than spending them on a list that is still missing some of their targets.
CARRY_UNMATCHED_MESSAGE_POINTS: Final = "_litellm_carry_unmatched_cache_control_points"

EXTERNAL_BREAKPOINTS_STAMP: Final = "_litellm_external_breakpoints"

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.

P2 Inline Stamp Violates Placement

This sentinel-like stamp is defined inline, violating the requirement to centralize such values in constants.py before merging

Rule Used: What: Require sentinel-like variables (e.g., _NEGATIVE_TEAM_SENTINEL) to be defined in constants.py instead of inline or in other modules. Why: Centralizing shared constants prevents duplication, inconsistencies, and makes future changes safer ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

Keeping it inline: sibling stamps CARRY_UNMATCHED_MESSAGE_POINTS and _litellm_openai_dialect already live here, and this one is private wire between the hook's two passes.

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.

That’s fair. Since CARRY_UNMATCHED_MESSAGE_POINTS and _litellm_openai_dialect are sibling hook-local stamps, and this value is only used for the hook’s private two-pass handoff, keeping EXTERNAL_BREAKPOINTS_STAMP in this module is consistent. I’m withdrawing the finding; no change is needed.

Comment on lines +302 to +326
def count_external_cache_breakpoints(tools: Iterable[object] | None, cache_control: object = None) -> int:
"""Client breakpoints outside messages and system that the provider cap still counts.

A tool carries its mark at the top level (Anthropic shape) or under ``function``
(OpenAI shape); the Anthropic chat transform forwards both. A top-level
``cache_control`` is Anthropic's automatic caching, which places one breakpoint
of its own on top of the explicit ones.
"""
automatic_blocks: Final = 1 if cache_control is not None else 0
tool_blocks: Final = sum(1 for tool in tools if _tool_carries_cache_breakpoint(tool)) if tools else 0
return automatic_blocks + tool_blocks

@staticmethod
def _blocks_reserved_outside_messages(
remaining_points: Sequence[CacheControlInjectionPoint], external_breakpoints: int, openai_dialect: bool
) -> int:
"""Slots of the provider cap that the message census cannot see.

The client's breakpoints on tools and its automatic top-level ``cache_control``
are already on the wire, and a ``tool_config`` point becomes one more cachePoint
in the Bedrock converse transform. OpenAI's cap counts only its own block markers.
"""
if openai_dialect:
return 0
tool_config_blocks: Final = 1 if any(p.get("location") == "tool_config" for p in remaining_points) else 0

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.

P2 Provider Logic Misplaced

This adds Anthropic-specific cap accounting outside llms/, violating the provider-code placement requirement that must be satisfied before merging

Rule Used: What: Avoid writing provider-specific code outside of the llms/ directory. Why: This practice ensures better maintainability and reduces complexity over time. Good: ```python # Handle provider-specific logic within llms/vertex_ai/transformation.py ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

Keeping it here: this hook is Anthropic-specific by name and its four-block cap accounting already lived in this module before this PR.

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.

You're right. This is an existing Anthropic-specific integration hook, and the four-block accounting already belongs to this module; the change extends that established responsibility rather than introducing provider logic into a general/shared layer. I withdraw the placement concern.

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 19, 2026

@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

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@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 mateo-berri added run-ci backport-stable P0 regression fix only (Urgent ticket): cherry-pick onto the baking rc line before the stable tag and removed run-ci labels Sep 19, 2026
…e_injection_points_survive_client_marks

Main's #41920 scoped the automatic breakpoints to supported Claude transports and
taught the client-mark check to read the extra_body envelope. Both changes are kept:
the defaults still stand down on any client mark, extra_body included. Configured
injection points keep applying beside client marks, and the cap census now counts
extra_body marks too, so a configured point never lands as a fifth block.
test_new_transports_preserve_client_controls now expects configured points to apply
beside client marks instead of standing down
@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 20, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 20, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 20, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 20, 2026
@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

Comment on lines +349 to +352
return max(
AnthropicCacheControlHook.count_external_cache_breakpoints(tools, cache_control),
AnthropicCacheControlHook.count_external_cache_breakpoints(tools, cache_control, request_kwargs),
)

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.

P1 Route Census Drops Checkpoint

When extra_body replaces a marked direct tool with an unmarked one on a bridge route, taking the larger census still reserves the obsolete tool's slot. The configured system checkpoint is then skipped even though the provider request has capacity, reducing the intended cache coverage.

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.

The hook runs before the route splits: native drops extra_body, the bridge merges it. Reserving more costs one point in that shape, never a 400

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.

You're right — given that the hook runs before the route split, the max() is an intentional conservative reservation. The native /v1/messages path drops extra_body and needs the direct-tool census, while the bridge path merges extra_body and needs the envelope census. Reserving the larger count guarantees neither path exceeds Anthropic's cap; in the opposite shape it can only suppress one configured point, not produce a 400. I withdraw the comment.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 21, 2026

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

@mateo-berri
mateo-berri merged commit d8267d5 into main Sep 21, 2026
146 of 148 checks passed
@mateo-berri
mateo-berri deleted the litellm_explicit_cache_injection_points_survive_client_marks branch September 21, 2026 19:28
yuneng-berri added a commit that referenced this pull request Sep 26, 2026
* fix: apply configured cache_control_injection_points beside client cache_control marks (#41956)

(cherry picked from commit d8267d5)

* fix(token_counter): count replayed redacted_thinking blocks so prompt_caching keeps pinning (#42069)

(cherry picked from commit 0e7cf51)

* fix(mcp): return camelCase tool keys from /v1/mcp/tools after the SDK 2 upgrade (#42352)

(cherry picked from commit 5eb4e30)

* fix(rust_bridge): keep the Messages route on Python until the Rust path is ready (#42517)

rc/1.103.0 has no token counter or tokenizer routes in the catalog, so only the Messages rule moves to PYTHON_ONLY

(cherry picked from commit 85ed18e)

* fix(proxy): stop leaking periodic tasks on every DB config reload (#42784)

(cherry picked from commit fc87a06)

---------

Co-authored-by: Mateo Wang <277851410+mateo-berri@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri mateo-berri removed the backport-stable P0 regression fix only (Urgent ticket): cherry-pick onto the baking rc line before the stable tag label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: cache_control_injection_points silently dropped entirely when client marks cache_control on an unrelated message

1 participant