Skip to content

fix(responses): keep cache breakpoints on blocks the bridge stringifies - #40032

Merged
mateo-berri merged 10 commits into
mainfrom
litellm_lit_7108_responses_prompt_cache_breakpoint
Oct 8, 2026
Merged

mateo-berri merged 10 commits into
mainfrom
litellm_lit_7108_responses_prompt_cache_breakpoint

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Explicit prompt caching lost its breakpoint on one kind of content block
  • A system prompt ending in a block the bridge cannot map (input_audio) cached nothing
  • Only deployments that set prompt_cache_options: {mode: explicit} are affected
  • With drop_params on, a malformed hand-written marker on a text, image or file block still reached the provider and failed the whole request

How it solves it:

  • The bridge's fallback branch keeps prompt_cache_breakpoint, like the text, image and file branches already do
  • Under drop_params, a marker that is not a valid PromptCacheBreakpoint is dropped on every carrying branch instead of reaching the provider; without drop_params it goes out verbatim and the provider's 400 names the field
  • PromptCacheBreakpoint gains the ttl: "30m" field OpenAI accepts, so a valid ttl survives that validation
  • Regression tests that fail on main's product code

User Flow

Before: a developer whose OpenAI deployment runs over the Responses API with explicit prompt caching sends a system prompt that ends in an audio block, and their cached token count stays at zero

  1. The proxy admin adds a deployment on openai/responses/gpt-6.1-sol with prompt_cache_options: {mode: explicit} and a cache_control_injection_points entry for role: system
  2. The developer sends POST https://litellm-domain/v1/chat/completions twice with the same ~8000 token system prompt as a list of content blocks ending in an input_audio block, plus a one word user message
  3. Both responses come back with "prompt_tokens_details": {"cached_tokens": 0}
  4. They resend the pair with the system prompt as one plain string, and the second response comes back with "cached_tokens": 8104, so the breakpoint works until the prompt ends in a block the gateway cannot map

After: the same block-split system prompt reads its cached prefix on the second request

  1. Same deployment and config
  2. The developer sends the same two POST https://litellm-domain/v1/chat/completions requests with the block-split system prompt
  3. The first response comes back with "cached_tokens": 0 and the second with "cached_tokens": 8140
  4. The plain-string pair still comes back with "cached_tokens": 8104 on its second call, so the two shapes now agree

Before, with drop_params: true: a developer hand-writes prompt_cache_breakpoint: "yes" on the system text block of a POST https://litellm-domain/v1/chat/completions request, and the whole request fails

  1. Same deployment, with litellm_settings: drop_params: true
  2. The developer sends the request with the string marker on the text block
  3. The response is a 400 from OpenAI: Invalid type for 'input[0].content[0].prompt_cache_breakpoint': expected an object, but got a string instead

After: the same request answers 200 with the malformed marker left out

  1. Same deployment and config
  2. The developer sends the same request
  3. The response is a 200 with the model's answer
  4. The same request on a proxy without drop_params still gets OpenAI's 400 naming the field

Relevant issues

None filed on GitHub

#42281 landed the breakpoint carry for the text, image and file branches of this conversion and made the hook leave OpenAI's implicit caching on unless the caller asks for explicit mode. This PR finishes the one branch it left out. An earlier revision also changed how the Responses entry point decides whether a request bridges to chat completions; that part was dropped because main already behaves the same there end to end

#38729 is separate: it decides which hosted deployments are eligible for an OpenAI-dialect breakpoint. Nothing here changes eligibility

Linear ticket

Part of LIT-7108, which also tracks follow-ups that stay open after this merges

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
  • 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)

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: 0135dad. QA and /live-pr-risk ran on eca0a96, the last commit written for this PR's product code; 18a8185 merges main (which landed #44119, the same bridge's strip of prompt_cache_breakpoint for models without breakpoint support) into the branch, resolves the conflict so both behaviors compose, and ships this audit's tests/integration cells; 0135dad changes only those cells (its scripted upstream now mints a unique response id per reply). The product diff against the merge base bf9bd35 is the same three behaviors as before, threaded through the converter main renamed. /live-pr-risk's merged-tree check and the /qa probes were re-run at 18a8185 (below the A/B section), and /audit ran every cell at 0135dad against bf9bd35, its live OpenAI rows at 18a8185

Shared setup. Two proxies on the same box, one booted at the merge base and one at the PR tip, each from its own worktree, both with 2 uvicorn workers, no database, hitting the real OpenAI API:

python litellm/proxy/proxy_cli.py --config qa_config.yaml --port <port> --num_workers 2
model_list:
  - model_name: cache-explicit
    litellm_params:
      model: openai/responses/gpt-6.1-sol
      api_key: os.environ/OPENAI_API_KEY
      prompt_cache_options:
        mode: explicit
      cache_control_injection_points:
        - location: message
          role: system
  - model_name: cache-default
    litellm_params:
      model: openai/responses/gpt-6.1-sol
      api_key: os.environ/OPENAI_API_KEY
      cache_control_injection_points:
        - location: message
          role: system
  - model_name: cache-nopoints
    litellm_params:
      model: openai/responses/gpt-6.1-sol
      api_key: os.environ/OPENAI_API_KEY

litellm_settings:
  drop_params: true

Each case sends the same ~8000 token system prompt twice and reads the cached token count back. Every case picks its own nonce, so no case reads a prefix another case already cached. blocks sends the system prompt as a text block followed by an input_audio block, which is the block type the bridge has no mapping for; text sends it as one plain string:

#!/bin/zsh
# usage: proof_case.sh <port> <model_name> <text|blocks>
PORT=$1; MODEL=$2; SHAPE=$3
NONCE=$(python3 -c 'import random; print(random.randint(10**9, 10**10))')
python3 - "$MODEL" "$NONCE" "$SHAPE" <<'PY'
import json, sys
model, nonce, shape = sys.argv[1:4]
text = f'cache probe {nonce} line. ' * 900
system = text if shape == 'text' else [
    {'type': 'text', 'text': text},
    {'type': 'input_audio', 'input_audio': {'data': 'Zm9v', 'format': 'wav'}},
]
body = {'model': model, 'max_tokens': 16,
        'messages': [{'role': 'system', 'content': system},
                     {'role': 'user', 'content': 'reply with the single word ok'}]}
json.dump(body, open('/tmp/probe.json', 'w'))
PY
for i in 1 2; do
  printf 'call %s -> ' $i
  curl -s http://127.0.0.1:$PORT/v1/chat/completions \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d @/tmp/probe.json | jq -c '{prompt_tokens: .usage.prompt_tokens, cached_tokens: .usage.prompt_tokens_details.cached_tokens}'
  sleep 2
done

The /v1/messages control sends the same system prompt through the Anthropic-shaped route:

#!/bin/zsh
# usage: proof_messages_case.sh <port> <model_name>
PORT=$1; MODEL=$2
NONCE=$(python3 -c 'import random; print(random.randint(10**9, 10**10))')
python3 - "$MODEL" "$NONCE" <<'PY'
import json, sys
model, nonce = sys.argv[1:3]
body = {'model': model, 'max_tokens': 16, 'system': f'cache probe {nonce} line. ' * 900,
        'messages': [{'role': 'user', 'content': 'reply with the single word ok'}]}
json.dump(body, open('/tmp/probe_m.json', 'w'))
PY
for i in 1 2; do
  printf 'call %s -> ' $i
  curl -s http://127.0.0.1:$PORT/v1/messages \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
    -d @/tmp/probe_m.json | jq -c '{prompt_tokens: .usage.input_tokens, cached_tokens: .usage.cache_read_input_tokens}'
  sleep 2
done

/v1/responses on this deployment goes to OpenAI natively and never runs the chat-to-Responses conversion this PR changes, so it has no case

Before (7921716)

/v1/chat/completions, explicit mode, system prompt as blocks ending in input_audio

  1. zsh proof_case.sh 29818 cache-explicit blocks
  2. Neither call caches, so the explicit breakpoint never reached the wire:
call 1 -> {"prompt_tokens":8153,"cached_tokens":0}
call 2 -> {"prompt_tokens":8153,"cached_tokens":0}

/v1/chat/completions, explicit mode, system prompt as a plain string

  1. zsh proof_case.sh 29818 cache-explicit text
  2. The second call caches, so explicit mode and the breakpoint work on the text branch already:
call 1 -> {"prompt_tokens":8117,"cached_tokens":0}
call 2 -> {"prompt_tokens":8117,"cached_tokens":8104}

/v1/chat/completions, default mode, same block-split prompt

  1. zsh proof_case.sh 29818 cache-default blocks
  2. OpenAI's implicit caching covers the deployment that did not opt into explicit mode:
call 1 -> {"prompt_tokens":8153,"cached_tokens":0}
call 2 -> {"prompt_tokens":8153,"cached_tokens":8150}

/v1/chat/completions, no injection point

  1. zsh proof_case.sh 29818 cache-nopoints text
  2. Implicit caching, as a baseline:
call 1 -> {"prompt_tokens":8117,"cached_tokens":0}
call 2 -> {"prompt_tokens":8117,"cached_tokens":8114}

/v1/messages, explicit mode deployment

  1. zsh proof_messages_case.sh 29818 cache-explicit
  2. The second call caches:
call 1 -> {"prompt_tokens":13,"cached_tokens":null}
call 2 -> {"prompt_tokens":13,"cached_tokens":8104}

After (eca0a96)

/v1/chat/completions, explicit mode, system prompt as blocks ending in input_audio

  1. zsh proof_case.sh 37130 cache-explicit blocks
  2. The block the bridge cannot map keeps its breakpoint, so the second call reads the cached prefix:
call 1 -> {"prompt_tokens":8153,"cached_tokens":0}
call 2 -> {"prompt_tokens":8153,"cached_tokens":8140}

/v1/chat/completions, explicit mode, system prompt as a plain string

  1. zsh proof_case.sh 37130 cache-explicit text
  2. Unchanged:
call 1 -> {"prompt_tokens":8117,"cached_tokens":0}
call 2 -> {"prompt_tokens":8117,"cached_tokens":8104}

/v1/chat/completions, default mode, same block-split prompt

  1. zsh proof_case.sh 37130 cache-default blocks
  2. Unchanged:
call 1 -> {"prompt_tokens":8153,"cached_tokens":0}
call 2 -> {"prompt_tokens":8153,"cached_tokens":8150}

/v1/chat/completions, no injection point

  1. zsh proof_case.sh 37130 cache-nopoints text
  2. Unchanged:
call 1 -> {"prompt_tokens":8117,"cached_tokens":0}
call 2 -> {"prompt_tokens":8117,"cached_tokens":8114}

/v1/messages, explicit mode deployment

  1. zsh proof_messages_case.sh 37130 cache-explicit
  2. Unchanged:
call 1 -> {"prompt_tokens":13,"cached_tokens":null}
call 2 -> {"prompt_tokens":13,"cached_tokens":8104}

Live A/B against the merge base (/live-pr-risk)

Rig: three no-DB proxies with 2 uvicorn workers each, base 7921716 and head eca0a96 from the same config plus a second head proxy from that config minus drop_params: true, each with its own forwarding recorder in front of api.openai.com (the recorder logs the request and forwards it, so every call hit the real provider). Deployments: openai/responses/gpt-6.1-sol with and without prompt_cache_options: {mode: explicit} plus a system injection point, bedrock_mantle/openai.gpt-6.1-sol, xai/grok-4.20-multi-agent, perplexity/openai/gpt-5.2, drop_params: true. Same cells in the same order on the base and head sides; the proxy without drop_params ran the four cells of its own table

Cell Dependent path Base 7921716 Head eca0a96
Hook marker, explicit mode, system [text, input_audio], two calls hook -> fallback branch -> OpenAI 200, cached 0 then 0 200, cached 0 then 9940
Same with stream: true streaming bridge path 200, cached 0 then 0 200, cached 0 then 9941
Hand-written {"mode": "explicit"} on the input_audio block, no injection point, on OpenAI, Bedrock Mantle, xAI, Perplexity every Responses-mode provider behind the bridge 200 on all four 200 on all four
Same marker on the text block control, main's carry since #42281 200 on all four 200 on all four
Malformed marker on the input_audio block (string, int, list, empty string, 5 KB string, {"mode": "bogus"}), drop_params on hostile input on the field the branch now reads 200, block stringified, marker never sent 200, marker dropped before the wire
{"mode": "explicit", "ttl": "1h"} on the input_audio block, drop_params on a ttl OpenAI rejects 200, marker never sent 200, marker dropped before the wire
{"mode": "explicit", "ttl": "30m"} on the input_audio block the ttl OpenAI accepts 200, marker never sent 200, marker sent with its ttl
Two marked input_audio blocks duplicate marker 200 200, both forwarded
String marker on a text block, drop_params on main's verbatim carry since #42281 400 from OpenAI, expected an object, but got a string 200, marker dropped before the wire
No API key auth before the bridge 401 401
Direct POST /v1/responses carrying the marker never enters the bridge 200 200

Same head, drop_params off:

Cell Head eca0a96 without drop_params
String marker on the input_audio block 400 from OpenAI, expected an object, but got a string instead
{"mode": "bogus"} on the input_audio block 400 from OpenAI, Invalid value: 'bogus'. Value must be 'explicit'
{"mode": "explicit", "ttl": "1h"} on the input_audio block 400 from OpenAI, Invalid value: '1h'. Supported values are: '30m'
{"mode": "explicit", "ttl": "30m"} on the input_audio block 200, marker sent with its ttl

Wire: 17 recorded OpenAI requests per side, one per cell that reached the provider, plus 4 on the proxy without drop_params. After dropping the recorder's own timestamps and the per-side nonce, the differences between base and head are the added prompt_cache_breakpoint on the second (input_text) item of the system message where the source block carried a valid one (both items on the duplicate cell, mode plus ttl on the 30m cell) and, on the string-marker text cell, the base's prompt_cache_breakpoint: "yes" gone from the head's request. The malformed input_audio cells carry no marker on either side (the base stringified the block, the head dropped the marker). The proxy without drop_params sent every marker verbatim, the string, bogus and 1h ones included. No header, path, or request-count change

Suites on the head tree: the mapped unit files (bridge transformation, cache-control hook) pass, and the three tests/llm_translation/test_openai.py tests that run openai/responses/* through the bridge pass against the live API. The two tests/integration files naming prompt_cache_breakpoint drive Anthropic deployments, which never enter this bridge, and no integration fixture marks a bridged block, so they were not run here (that suite needs its CircleCI harness)

Findings

  • Breaking: none. Every cell that answered 200 on the base still does on the head; one cell flips the other way, a string marker on a text block with drop_params on goes from OpenAI's 400 to a 200 with the marker dropped
  • Backward incompatible: with drop_params on, a prompt_cache_breakpoint that does not validate as PromptCacheBreakpoint (mode: "explicit", optional ttl: "30m") is dropped on every carrying branch (text, image_url, file and the fallback), where fix(responses): preserve prompt cache reuse in chat bridge #42281 forwarded it verbatim on the first three and OpenAI answered 400 naming the field. With drop_params off nothing changes on those three branches, and the fallback branch joins them: the marker goes out verbatim and the provider's 400 names the field, where main stringified the whole block and answered 200. Both halves follow the repo's drop_params convention (an unsupported or malformed value drops under drop_params and answers 400 without it, the shape o-series temperature takes), chosen over two alternatives: dropping only the offending key (keeping mode when ttl is wrong, which sends a marker the caller did not write) and forwarding verbatim regardless of drop_params (what the previous revision of this PR did, recorded as a Low caveat). The validation treats the marker as one unit: a bad mode or ttl drops the whole marker, an unknown key is left out. ttl joined the type because OpenAI accepts "30m" (its 400 on 2026-10-07: Invalid value: '1h'. Supported values are: '30m') and the type without it would have stripped a valid ttl under drop_params. Shipped in f2c6ade and eca0a96
  • Regression risk: on Bedrock Mantle, xAI and Perplexity a hand-written marker was observed as status and usage only (200 both sides), not as a cache-hit flip; the bridge's in-process callers (the noma guardrail, the Responses guardrail translation handler, the complexity router) call the converter with its drop_params default of off, so they see the same verbatim markers as before, and were not driven
  • Dependency graph: _prompt_cache_breakpoint_for_wire -> the four carrying branches of _convert_content_to_responses_format -> convert_chat_completion_messages_to_responses_api -> transform_request, which reads drop_params from the call's litellm params or the global setting, verified live streaming and not, with and without drop_params; the noma guardrail, Responses guardrail translation and complexity router callers, untested here; every Responses-mode provider receiving bridged input: OpenAI verified for cache hits and for the 400s, Bedrock Mantle, xAI and Perplexity verified for status
  • Not verified: the two integration wire hits above, cache-hit flips on the non-OpenAI providers, and the three in-process callers

Observations

  • input_audio blocks go out as input_text repr, pre-existing, unchanged here
  • Explicit mode caches nothing past the marked message, by design
  • Marking the user message instead caches the bulk
  • Anthropic style image blocks fail validation with a 500, pre-existing

Audit (/audit, 0135dad vs bf9bd35; live rows at 18a8185)

Every cell below is a checked-in tests/integration/providers/ test (test_responses_bridge_prompt_cache_breakpoint_wire.py, test_responses_bridge_prompt_cache_breakpoint_wire_chaos.py, helpers in tests/integration/_support/prompt_cache_breakpoint.py; main's own test_responses_bridge_prompt_cache_breakpoint*.py files from #44119 are untouched), run with uv run --no-sync python tests/integration/run.py providers <node ids> on a two-worker proxy with its own Postgres database, Redis and owned upstream per leg, the Responses deployment pointed at a scripted Responses endpoint that records every request it receives. Each cell reads back the client's response, the request on the wire and the spend row by litellm_call_id. The merge-base leg ran the same cells against bf9bd35 (its tests overlaid); the head leg ran them twice at 0135dad (lanes round3-head-run1 277 s and round3-head-run2 on the head leg, round3-base 285 s on the base leg, run one after the other since the box had under 4 GB free per lane; round3-base lost one cell, test_flipping_drop_params_mid_burst_keeps_every_marked_request_answered, to the harness client's 15 s ReadTimeout on /model/update while the base proxy logged a localhost Redis read timeout in the same second and another rig's four lanes ended on the box, so that one cell re-ran on the base leg as round3-base-e3 once the box was quiet (passed, 7.0 s) and the matrix names that lane on its row). The four L rows are live cells against the real OpenAI API through the same proxies (openai/responses/gpt-6.1-sol, a model main's new strip rule keeps breakpoints for), run once per leg at 18a8185 and kept over the tests-only 0135dad, not committed; their artifacts are the proxy response, the OpenAI response_id, usage and the spend row per leg

Row Cell Base bf9bd35 Head run 1 Head run 2 Result Last ran at
H1 wire::test_openai_sdk_sends_a_valid_marker_through_the_bridge green pass 6.5s pass 5.6s PASS 0135dad
H2 wire::test_openai_sdk_stream_carries_the_system_list_marker green pass 0.1s pass 0.1s PASS 0135dad
H3 wire::test_async_openai_sdk_keeps_the_ttl_without_drop_params green pass 0.2s pass 0.2s PASS 0135dad
H4 wire::test_valid_marker_shapes_reach_the_wire_unchanged[explicit-on] green pass 0.1s pass 0.1s PASS 0135dad
H4 wire::test_valid_marker_shapes_reach_the_wire_unchanged[explicit-off] green pass 0.1s pass 0.1s PASS 0135dad
H4 wire::test_valid_marker_shapes_reach_the_wire_unchanged[ttl-on] green pass 0.1s pass 0.1s PASS 0135dad
H4 wire::test_valid_marker_shapes_reach_the_wire_unchanged[ttl-off] green pass 0.1s pass 0.1s PASS 0135dad
H16 wire::test_marker_with_an_unknown_key[normalized-on] red (expected) pass 0.2s pass 0.1s PASS 0135dad
H16 wire::test_marker_with_an_unknown_key[verbatim-off] green pass 0.1s pass 0.1s PASS 0135dad
H1 wire::test_valid_marker_is_carried_on_every_block_kind[text-on] green pass 0.1s pass 0.1s PASS 0135dad
H1 wire::test_valid_marker_is_carried_on_every_block_kind[text-off] green pass 0.1s pass 0.1s PASS 0135dad
H12 wire::test_valid_marker_is_carried_on_every_block_kind[image_url-on] green pass 0.1s pass 0.1s PASS 0135dad
H12 wire::test_valid_marker_is_carried_on_every_block_kind[image_url-off] green pass 0.1s pass 0.1s PASS 0135dad
H13 wire::test_valid_marker_is_carried_on_every_block_kind[file-on] green pass 0.1s pass 0.1s PASS 0135dad
H13 wire::test_valid_marker_is_carried_on_every_block_kind[file-off] green pass 0.1s pass 0.1s PASS 0135dad
H10 wire::test_valid_marker_is_carried_on_every_block_kind[input_audio-on] red (expected) pass 0.1s pass 0.1s PASS 0135dad
H10 wire::test_valid_marker_is_carried_on_every_block_kind[input_audio-off] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_on_every_block_kind[text] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S12 wire::test_malformed_marker_is_dropped_on_every_block_kind[image_url] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S12 wire::test_malformed_marker_is_dropped_on_every_block_kind[file] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S11 wire::test_malformed_marker_is_dropped_on_every_block_kind[input_audio] green pass 0.1s pass 0.1s PASS 0135dad
H14 wire::test_tool_output_marker[valid-on] green pass 0.1s pass 0.2s PASS 0135dad
H14 wire::test_tool_output_marker[valid-off] green pass 0.1s pass 0.1s PASS 0135dad
S12 wire::test_tool_output_marker[malformed-on] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S9 wire::test_tool_output_marker[malformed-off] green pass 0.1s pass 0.1s PASS 0135dad
H15 wire::test_assistant_list_marker[valid-on] green pass 0.1s pass 0.1s PASS 0135dad
H15 wire::test_assistant_list_marker[valid-off] green pass 0.1s pass 0.1s PASS 0135dad
S12 wire::test_assistant_list_marker[malformed-on] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S9 wire::test_assistant_list_marker[malformed-off] green pass 0.1s pass 0.1s PASS 0135dad
H5 wire::test_injected_system_marker_survives_a_trailing_audio_block red (expected) pass 0.1s pass 0.2s PASS 0135dad
H6 wire::test_injected_marker_on_a_string_system_message green pass 0.1s pass 0.1s PASS 0135dad
H7 wire::test_anthropic_sdk_marker_on_user_text[valid-on] green pass 0.9s pass 3.1s PASS 0135dad
H7 wire::test_anthropic_sdk_marker_on_user_text[valid-off] green pass 1.0s pass 0.7s PASS 0135dad
S17 wire::test_anthropic_sdk_marker_on_user_text[malformed-on] green pass 1.6s pass 0.3s PASS 0135dad
S9 wire::test_anthropic_sdk_marker_on_user_text[malformed-off] green pass 3.3s pass 3.6s PASS 0135dad
H8 wire::test_anthropic_sdk_system_string_gets_the_injected_marker green pass 0.6s pass 1.4s PASS 0135dad
H9 wire::test_native_responses_request_never_enters_the_bridge green pass 0.1s pass 0.1s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[string] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[int] red (expected) pass 0.1s pass 0.2s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[list] red (expected) pass 0.2s pass 0.1s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[empty-string] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[5kb-string] red (expected) pass 0.1s pass 0.1s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[empty-object] red (expected) pass 0.2s pass 0.1s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[bogus-mode] red (expected) pass 0.1s pass 0.5s PASS 0135dad
S1-S8 wire::test_malformed_marker_is_dropped_under_drop_params[bad-ttl] red (expected) pass 0.1s pass 1.2s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[string] green pass 0.1s pass 0.2s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[int] green pass 0.1s pass 0.2s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[list] green pass 0.1s pass 0.1s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[empty-string] green pass 0.1s pass 0.2s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[5kb-string] green pass 0.1s pass 0.1s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[empty-object] green pass 0.1s pass 0.1s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[bogus-mode] green pass 0.1s pass 0.2s PASS 0135dad
S9 wire::test_malformed_marker_passes_verbatim_without_drop_params[bad-ttl] green pass 0.1s pass 0.2s PASS 0135dad
S10 wire::test_two_marked_blocks_are_both_carried green pass 0.1s pass 0.1s PASS 0135dad
S13 wire::test_wrong_key_is_refused_before_the_wire green pass 0.0s pass 0.0s PASS 0135dad
S14 wire::test_upstream_error_reaches_the_caller_once[400-on] green pass 0.3s pass 0.4s PASS 0135dad
S14 wire::test_upstream_error_reaches_the_caller_once[400-off] green pass 0.3s pass 0.3s PASS 0135dad
S15 wire::test_upstream_error_reaches_the_caller_once[401-on] green pass 0.3s pass 0.4s PASS 0135dad
S16 wire::test_null_drop_params_on_the_deployment_means_off green pass 0.4s pass 0.4s PASS 0135dad
E1 wire::test_null_or_missing_marker_sends_a_plain_block[null-on] green pass 0.1s pass 0.1s PASS 0135dad
E1 wire::test_null_or_missing_marker_sends_a_plain_block[null-off] green pass 0.2s pass 0.1s PASS 0135dad
E1 wire::test_null_or_missing_marker_sends_a_plain_block[missing-on] green pass 0.1s pass 0.1s PASS 0135dad
E1 wire::test_null_or_missing_marker_sends_a_plain_block[missing-off] green pass 0.2s pass 0.1s PASS 0135dad
E3 wire::test_flipping_drop_params_mid_burst_keeps_every_marked_request_answered green (round3-base-e3) pass 1.4s pass 1.3s PASS 0135dad
E4 wire::test_three_identical_marked_requests_are_each_sent_and_logged green pass 0.6s pass 0.6s PASS 0135dad
H17 chaos::test_global_drop_params_drops_a_malformed_marker[deployment-unset] red (expected) pass 61.1s pass 46.7s PASS 0135dad
H18 chaos::test_global_drop_params_drops_a_malformed_marker[deployment-false] red (expected) pass 0.3s pass 1.9s PASS 0135dad
C1 chaos::test_mixed_burst_carries_every_marker_once green pass 1.5s pass 2.5s PASS 0135dad
C2 chaos::test_upstream_outage_fails_cleanly_and_the_restarted_upstream_serves_marked_calls green pass 2.2s pass 2.8s PASS 0135dad
C3 chaos::test_concurrent_slow_streams_each_complete_with_one_upstream_call green pass 1.6s pass 1.6s PASS 0135dad
C4 chaos::test_worker_sigkill_mid_burst_leaves_the_sibling_answering red (expected) pass 63.6s pass 72.1s PASS 0135dad
C5 chaos::test_proxy_restart_mid_burst_never_lands_a_served_call_twice green pass 109.2s pass 116.5s PASS 0135dad
L1 live OpenAI live/18a818530f/<leg>/L1*.json call2 cached_tokens=0 (prompt 19853), 200 call2 cached_tokens=21640 (prompt 21653), 200 once per leg PASS 18a8185
L2 live OpenAI live/18a818530f/<leg>/L2*.json 200 200 once per leg PASS 18a8185
L3 live OpenAI live/18a818530f/<leg>/L3*.json 400 naming 30m 400 naming 30m once per leg PASS 18a8185
L4 live OpenAI live/18a818530f/<leg>/L4*.json 400 naming 30m 200 once per leg PASS 18a8185

Inventory walk

  • H1: VERIFIED
  • H2: VERIFIED
  • H3: VERIFIED
  • H4: VERIFIED
  • H5: VERIFIED
  • H6: VERIFIED
  • H7: VERIFIED
  • H8: VERIFIED
  • H9: VERIFIED
  • H10: VERIFIED
  • H12: VERIFIED
  • H13: VERIFIED
  • H14: VERIFIED
  • H15: VERIFIED
  • H16: VERIFIED
  • H17: VERIFIED
  • H18: VERIFIED
  • S1-S8: VERIFIED
  • S9: VERIFIED
  • S10: VERIFIED
  • S11: VERIFIED
  • S12: VERIFIED
  • S13: VERIFIED
  • S14: VERIFIED
  • S15: VERIFIED
  • S16: VERIFIED
  • S17: VERIFIED
  • E1: VERIFIED
  • E2: VERIFIED
  • E3: VERIFIED
  • E4: VERIFIED
  • C1: VERIFIED
  • C2: VERIFIED
  • C3: VERIFIED
  • C4: VERIFIED
  • C5: VERIFIED
  • L1: VERIFIED
  • L2: VERIFIED
  • L3: VERIFIED
  • L4: VERIFIED

Failures

  • none

C5 restart-mid-burst counts (head run 1)

{"served": "20", "landed": "20", "lost_responses": "0"}

Lane counts (passed/collected)

{"base": [52, 72], "run1": [72, 72], "run2": [72, 72]}

Rows marked red (expected) on the base are the behaviors this PR changes; green on the base is a regression guard that reads the same on both legs. The run before this one, at 18a8185, had test_three_identical_marked_requests_are_each_sent_and_logged red on every leg for a reason inside the audit's own scripted upstream: it minted the response id from the request's marker, so three identical requests shared one id, and the spend-log writer skips a row whose request_id already landed; 0135dad makes that upstream mint a unique id per reply, as a real provider does, and every cell was rerun there. Two things the matrix does not show: an unknown chat block type ({"type": "custom_blob"}) is refused before the bridge with a 500 on both legs, so the fallback branch is proven through input_audio, the one valid chat block type without a mapping; and the /v1/messages cells (Anthropic SDK) are served by the Anthropic-to-Responses adapter, which never enters this bridge, so they are regression guards and the malformed-marker cell there pins the adapter's current verbatim forwarding (the Low caveat below)

Merged-tree check at 18a8185 (/live-pr-risk merge-ref drift, /qa probes)

Main moved under this branch (#44119 landed in the same bridge), so the /live-pr-risk top scenarios and the /qa probes were re-run on the merged tree at 18a8185: one laptop proxy from the merged worktree (proxy_cli.py --config qa_config.yaml --num_workers 2, no database, drop_params: true, the same deployments as the A/B above, a forwarding recorder in front of api.openai.com), the same cell script with a fresh nonce, every call against the real providers

Check at 18a8185 Result
Statuses of the 25 A/B cells (hook marker two calls, streaming twice, hand-written marker on OpenAI, Bedrock Mantle, xAI and Perplexity, the eight hostile markers, the two controls, the ttl cells) identical to the head column above: every cell 200, the unauthenticated cell 401, no 400
Wire to OpenAI, 17 recorded requests paired by order with the eca0a96 head run identical after replacing each run's nonce, zero field differences: the marker on the input_text item where the source block carried a valid one, mode plus ttl on the 30m cell, no marker on any malformed cell
Explicit-mode cache hit on the block-split system prompt call 2 cached_tokens 9040 of 9059 (non-stream), 9041 of 9060 (stream)
The five /qa probes (proof_case.sh, proof_messages_case.sh) same numbers as the After section: 8140, 8104, 8150, 8114 cached of 8153 or 8117, and 8104 on /v1/messages

The three non-OpenAI deployments were observed as status and usage only (200, as before); for their models supports_openai_prompt_cache_breakpoint is false, so main's #44119 now strips a hand-written marker before the wire, which is main's behavior and outside this diff

Type

🐛 Bug Fix

Caveats (if any)

Low

  • The image branch of the bridge (an Anthropic style {"type": "image", "source": ...} block) is the one carrying branch left without a breakpoint carry

    • {"type": "input_image", **item} lets the spread put "type": "image" back, so a marker there would ride a block the Responses API refuses
    • through POST /v1/chat/completions that block never reaches the bridge on this run: the proxy rejects the message first with a 500 Invalid user message at index 0, on the merge base and the tip alike, so the branch was left alone deliberately, and that 500 is a pre-existing wart outside this diff
  • Without drop_params, a malformed prompt_cache_breakpoint hand-written on an unmapped block (input_audio) now gets the provider's 400 where main answered 200 with the block stringified

    • the 400 half of the drop_params convention, and what the same marker on a text block gets on main since fix(responses): preserve prompt cache reuse in chat bridge #42281; with drop_params on the marker drops and the request answers 200
    • net negative to fix: the only fix is dropping the marker without drop_params too, a silent edit of the caller's request on a route where every other unsupported value answers 400, for a caller who hand-writes OpenAI's Responses dialect with the wrong type on an audio block
  • An Anthropic-shaped request (/v1/messages, Claude Code, the Anthropic SDK) to a Responses-served deployment is translated by the Anthropic-to-Responses adapter, not by this bridge, and that adapter forwards a malformed prompt_cache_breakpoint verbatim with drop_params on, so the provider's 400 still reaches that caller where the chat path now drops the marker

    • inherited, outside this diff, same on the merge base; the audit cell test_anthropic_sdk_marker_on_user_text[malformed-on] pins the current behavior so the flip is visible when the adapter gets the same validation
    • left alone here because it is a second entry point with its own transformation module and a follow-up is filed for it; folding it into this PR would widen a bridge fix into the Anthropic adapter
  • Since main's fix(responses): keep prompt_cache_breakpoint markers in the chat to responses bridge #44119 (merged into this branch), a prompt_cache_breakpoint on a chat block is stripped before the wire for any model that fails supports_openai_prompt_cache_breakpoint (no cost-map flag and no gpt-5.6+ name), with or without drop_params, so the 400-without-drop_params half of this PR's convention only reaches callers of models that keep breakpoints

    • main's behavior, not this PR's; the merged tree composes both: main's strip decides whether markers reach the wire at all, this PR decides what a kept malformed marker does under drop_params
    • the merged-tree check above observed the Bedrock Mantle, xAI and Perplexity hand-written-marker cells as status and usage only (200, as before); supports_openai_prompt_cache_breakpoint is false for their models, so main's rule strips the marker there

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
  • Mutation tested: dropping the breakpoint carry on the fallback branch fails the new test with the KeyError the merge base raises, and removing the drop_params validation fails the two drop tests (2 failed, 5 passed across the breakpoint tests)
  • eca0a96 passes /live-pr-risk
  • 0135dad passes /audit (every inventory row VERIFIED; the deterministic cells at 0135dad, the live rows at 18a8185, whose product code 0135dad does not change)
  • 18a8185 passes the merged-tree re-run of the /live-pr-risk top scenarios and the /qa probes

Note

Medium Risk
Changes how outbound Responses API input is built for all bridged chat traffic when explicit cache markers or drop_params are used; malformed markers are silently dropped under drop_params, which is intentional but alters prior verbatim-forwarding behavior on some branches.

Overview
Fixes explicit prompt caching when chat completions are bridged to the Responses API: prompt_cache_breakpoint is now attached on content blocks that fall through the unmapped fallback (e.g. trailing input_audio), matching text/image/file behavior so injected system markers survive on the wire.

When drop_params is on (per-call or global), markers are validated against PromptCacheBreakpoint before send; malformed values are omitted instead of causing upstream 400s, while valid {"mode":"explicit"} and optional ttl":"30m" are kept (the type gains ttl: "30m"). drop_params is threaded through message/content conversion from transform_request.

Adds unit tests for carry/drop behavior and integration wire/chaos tests for SDK paths, block kinds, tool/assistant content, and proxy failure modes.

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

…ponses API

The chat-completions bridge rebuilt every content block without the
prompt_cache_breakpoint marker the cache-control hook had just placed on it, so
the request went out with prompt_cache_options set to explicit mode and nothing
actually marked. Explicit mode caches only what is marked, so those deployments
lost the implicit caching they were getting before the injection point was added

The native surface had a second miss. The bridging check looked the provider
config up with the still-prefixed model while the config keys on the bare one,
so every bedrock_mantle model read as having no native Responses support, and
role-targeted injection points were deferred to a chat-completions pass that
never runs for them
@mateo-berri
mateo-berri requested a review from a team September 6, 2026 08:27
@greptile-apps

greptile-apps Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds prompt cache breakpoint handling to response transformation.

The PR appears safe to merge, with no outstanding correctness, security, or repository-rule issues

Findings

  1. P2 Tests Monkeypatch Class Attributes ▶

Summary

This PR preserves explicit prompt-cache breakpoints when chat content blocks are stringified for the Responses API bridge. It also validates breakpoint shapes under drop_params, adds support for the accepted 30m TTL, composes the behavior with model capability filtering from main, and adds full-stack wire and resilience coverage

Reviews (8) · Last reviewed commit: "test(integration): give every scripted r..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_lit_7108_responses_prompt_cache_breakpoint (0135dad) with main (87e961f)

Open in CodSpeed

@codecov

codecov Bot commented Sep 6, 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 Author

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 Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

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 Author

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 Author

@greptileai

Comment on lines +382 to +390
patch.object(
import_module("litellm.responses.mcp.litellm_proxy_mcp_handler").LiteLLM_Proxy_MCP_Handler,
"_should_use_litellm_mcp_gateway",
return_value=False,
),
patch.object(
import_module("litellm.responses.main").base_llm_http_handler,
"response_api_handler",
return_value=MagicMock(),

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 Tests Monkeypatch Class Attributes

These new tests replace class and module attributes with patch.object. The repository requires dependency injection for test doubles, so this must be addressed before merging. The same pattern also appears at lines 411-419

Context Used: CLAUDE.md (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!

@yuneng-berri
yuneng-berri deleted the branch main September 13, 2026 04:50
@mateo-berri mateo-berri reopened this Sep 13, 2026
@mateo-berri
mateo-berri changed the base branch from litellm_internal_staging to main September 13, 2026 05:13
…onses_prompt_cache_breakpoint

# Conflicts:
#	litellm/completion_extras/litellm_responses_transformation/transformation.py
#	litellm/responses/main.py
#	tests/unit/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py
…ady routes the hook

#42281 landed the text, image_url and file branch carry and the implicit default
on main, and the Responses routing lookup this branch changed has no observable
effect there, so the PR shrinks to the unknown-block fallback branch and its
regression test
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri mateo-berri changed the title fix(responses): keep cache breakpoints on requests that reach the Responses API fix(responses): keep cache breakpoints on blocks the bridge stringifies Oct 7, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor Author

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 Author

@greptileai

…_params

OpenAI's Responses API takes a ttl of 30m on an explicit breakpoint marker, so the drop_params validation keeps it instead of stripping it as an unknown key. Trims the bridge test docstrings to the dated vendor citation.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…e chat-to-Responses bridge

Adds the /audit cells for the bridge's prompt_cache_breakpoint carry: valid and malformed markers on every
carrying block kind and on tool and assistant content, the drop_params on and off contract, the hook-injected
system marker, the Anthropic SDK path through the Responses adapter, upstream errors, idempotent spend rows,
and the chaos cells (mixed burst, upstream outage, slow streams, worker SIGKILL and a proxy restart mid burst),
all against a scripted Responses endpoint with the request it received read back by response id
…onses_prompt_cache_breakpoint

# Conflicts:
#	litellm/completion_extras/litellm_responses_transformation/transformation.py
#	tests/integration/providers/test_responses_bridge_prompt_cache_breakpoint_chaos.py
The prompt-cache-breakpoint audit's scripted upstream minted the response id
from the request's marker, so three identical marked requests shared one id.
The spend-log writer skips rows whose request_id already landed, and the
idempotent-logging cell saw one row for three calls on every leg. The upstream
now mints a unique id per reply like a real provider, and the cells match a
response to its request by the marker inside that id.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

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 0135dad. Configure here.

@mateo-berri
mateo-berri merged commit 9d3bf29 into main Oct 8, 2026
104 of 106 checks passed
@mateo-berri
mateo-berri deleted the litellm_lit_7108_responses_prompt_cache_breakpoint branch October 8, 2026 01:28
mateo-berri added a commit that referenced this pull request Oct 8, 2026
#40032 landed first and added the wire helper that drops a malformed
prompt_cache_breakpoint under drop_params, so the input_audio branch now
carries its marker through that helper like the text and image branches,
with a regression test for the malformed case. Main's unknown-block marker
test used input_audio as its unmappable example and now uses a video_url
part. The audio test fixture registers its fake models through monkeypatch
on the price map, so nothing leaks into the provider model sets, and the
new tests carry the Final and fixture annotations the repo asks for
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.

3 participants