Skip to content

fix(anthropic): replay OpenAI encrypted reasoning byte for byte through the /v1/messages bridge - #40451

Merged
mateo-berri merged 7 commits into
litellm_internal_stagingfrom
litellm_responses_bridge_replay_encrypted_reasoning
Sep 10, 2026
Merged

mateo-berri merged 7 commits into
litellm_internal_stagingfrom
litellm_responses_bridge_replay_encrypted_reasoning

Conversation

@devin-ai-integration

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

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • OpenAI reasoning items are rebuilt from summary text on every /v1/messages turn
  • The encrypted reasoning is thrown away, so nothing is byte-stable across turns
  • Claude Code gets thinking blocks with an empty signature

How it solves it:

  • Request include: ["reasoning.encrypted_content"] on every bridged Responses call to a provider whose Responses API returns it (OpenAI), with or without a client thinking block
  • Pack the encrypted reasoning into the thinking block signature, replay it unchanged
  • Anthropic, Gemini, and Bedrock backends drop bridge-tagged blocks instead of forwarding them as real signatures
  • The router's encrypted_content_affinity check reads the pin from the replayed thinking block too, so a model group spread across OpenAI orgs keeps follow-ups on the org that minted the reasoning
  • When that conversation is replayed to a model group the minting org is not part of (a tier change to gpt-5.1-tier), the check drops the bridge-tagged blocks whole instead of forwarding reasoning the routed org cannot decrypt, the same way fix(router): strip encrypted reasoning on an auto-router tier change instead of a 503 #40280 drops undecryptable reasoning items from Responses input

User Flow

Claude Code pointed at a LiteLLM proxy with ANTHROPIC_MODEL=gpt-5.1 (an OpenAI reasoning model behind the Anthropic Messages bridge), in a session with follow-up questions

Before

The reasoning gpt-5.1 produced in turn one never comes back on turn two, so the prompt prefix is rebuilt from a lossy summary and the model gets thinking blocks with no signature

  1. POST http://localhost:4000/v1/messages with model: gpt-5.1, thinking: {type: adaptive}, stream: true, and the first question
  2. The stream carries a thinking block whose signature_delta is empty; the reply text follows
  3. POST http://localhost:4000/v1/messages again with the whole conversation, the earlier thinking block replayed with signature: ""
  4. The reply arrives, but the reasoning replayed upstream is a rebuild from the summary text and drops any reasoning item that had no summary, so the prefix is not the bytes the model produced
  5. POST http://localhost:4000/v1/messages to claude-sonnet-4-6 with that same conversation gets 400 Invalid signature in thinking block from Anthropic, and only an internal strip-everything retry turns it into a 200 with no thinking at all
  6. With gpt-5.1 load balanced across two OpenAI orgs and encrypted_content_affinity enabled, turn two lands on either org: there is no encrypted reasoning to pin on, and the check cannot read a pin off this route anyway
  7. POST http://localhost:4000/v1/messages replaying that conversation with model: gpt-5.1-tier (a group on a third OpenAI org) goes through on the same lossy summary rebuild; nothing ties the conversation to the org that produced the reasoning

After

The encrypted reasoning gpt-5.1 produced comes back on every later turn unchanged, and Claude Code shows it as a signed thinking block

  1. POST http://localhost:4000/v1/messages with model: gpt-5.1, thinking: {type: adaptive}, stream: true, and the first question
  2. The stream carries a thinking block whose signature_delta holds the encrypted reasoning (litellm_encrypted_reasoning:...), or a redacted_thinking block whose data holds it when the model returned no summary; the reply text follows
  3. POST http://localhost:4000/v1/messages again with the whole conversation, the earlier block replayed as Claude Code received it
  4. The reply arrives; every replayed reasoning item carries the exact encrypted reasoning the model produced (the summary text is display-only), so the prompt prefix stays identical turn over turn and the cache hit covers it
  5. POST http://localhost:4000/v1/messages to claude-sonnet-4-6 (or gemini-3.8-flash) with that same conversation returns 200 on the first attempt, the bridge-tagged block dropped up front, and Anthropic answers with its own thinking block
  6. With gpt-5.1 load balanced across two OpenAI orgs and encrypted_content_affinity enabled, turn two is pinned to the org that produced the reasoning (x-litellm-model-id matches turn one every time), so OpenAI never sees encrypted reasoning minted by another org
  7. POST http://localhost:4000/v1/messages replaying that conversation with model: gpt-5.1-tier (a group on a third OpenAI org) returns 200 from openai-org-c on the first attempt: the minting org is not a candidate in that group, so the check drops the bridge-tagged blocks the new org cannot decrypt and the routed request carries the conversation's text with no reasoning item for those turns

Relevant issues

Fixes #40288

Linear ticket

Resolves LIT-7339

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

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

Setup shared by both legs: the same proxy config, two uvicorn workers, a recording reverse proxy in front of api.openai.com set as the OpenAI api_base so the bytes the proxy sends upstream can be diffed turn over turn, and Claude Code v2.1.266 driven interactively in tmux against the proxy

model_list:
  - model_name: gpt-5.1
    litellm_params:
      model: openai/gpt-5.1
      api_key: os.environ/OPENAI_API_KEY
      api_base: http://127.0.0.1:<openai recorder port>/v1
      drop_params: true
  - model_name: claude-sonnet-4-6
    litellm_params:
      model: anthropic/claude-sonnet-4-6
      api_key: os.environ/ANTHROPIC_API_KEY

litellm_settings:
  reasoning_auto_summary: true

general_settings:
  master_key: sk-lit7339-qa
python litellm/proxy/proxy_cli.py --config config.yaml --port <proxy port> --num_workers 2 --detailed_debug

env -u ANTHROPIC_API_KEY ANTHROPIC_BASE_URL=http://127.0.0.1:<client recorder port> ANTHROPIC_AUTH_TOKEN=sk-lit7339-qa \
    ANTHROPIC_MODEL=gpt-5.1 ANTHROPIC_SMALL_FAST_MODEL=gpt-5.1 claude

Per leg: Before boots the proxy from a checkout of the merge base 075655c on port 28813, with the client recorder on 34517 and the OpenAI recorder on 41423; After boots it from the PR tip 5a1be56 on port 24754, with the client recorder on 30016 and the OpenAI recorder on 41554. The Before screenshot file is named after the PR head at the time it was uploaded (751431d), not the merge base the leg ran at; the After one is named after the tip it ran at. Claude Code auto-updated from 2.1.266 to 2.1.267 between the two legs

Three prompts typed into Claude Code, one turn each: the five-houses zebra puzzle ("Do not use any tools. Solve this in your head ..."), then "No tools. Which house colour does the zebra owner live in, and who is their left-hand neighbour? One line.", then "No tools. And who smokes Kools? One line."

Before (075655c)

Proxy on port 28813, booted from a checkout of the merge base

Claude Code, three turns on gpt-5.1

  1. What the proxy sent to POST https://api.openai.com/v1/responses on each turn (one line per input item, reasoning items hashed)
request #1: include=None reasoning={'effort': 'high', 'summary': 'detailed'}
   response usage: input_tokens=28708 cached_tokens=0 reasoning_tokens=691
   response reasoning item: id=rs_0819...3c7f09 encrypted_content=<5644 chars> summary_parts=2

request #2: include=None
   input reasoning item: id=None encrypted_content=None summary_parts=1 sha_of_item=ca4037461404
   response usage: input_tokens=30217 cached_tokens=28544 reasoning_tokens=295
   response reasoning item: id=rs_0638...961fce encrypted_content=<2872 chars> summary_parts=0

request #3: include=None
   input reasoning item: id=None encrypted_content=None summary_parts=1 sha_of_item=ca4037461404
   (the summary-less item from request #2 is gone from the replay)
   response usage: input_tokens=30545 cached_tokens=30080 reasoning_tokens=663

request #4: include=None
   input reasoning item: id=None encrypted_content=None summary_parts=1 sha_of_item=ca4037461404
   response usage: input_tokens=30665 cached_tokens=30080 reasoning_tokens=775

The proxy never asks for reasoning.encrypted_content, so every response item's 2.8 to 5.6 KB of encrypted reasoning is dropped on the floor. What gets replayed is a fresh item rebuilt from the summary text (encrypted_content=None), and items that came back without a summary are not replayed at all

  1. What Claude Code received and sent back on POST http://127.0.0.1:34517/v1/messages
request #3: thinking={'type': 'adaptive'}
   streamed thinking block: signature='' thinking_len=945
request #4:
   replayed thinking: signature='' thinking_len=945
request #5:
   replayed thinking: signature='' thinking_len=945
   streamed thinking block: signature='' thinking_len=1012
request #7:
   replayed thinking: signature='' thinking_len=945
   replayed thinking: signature='' thinking_len=429
  1. Claude Code's pane at the end of the session

pr40451-751431dc3f-before_claude_code.png

Cross-model replay to claude-sonnet-4-6

Take the conversation Claude Code built through the bridge (an assistant turn whose thinking block carries the bridge signature) and send it to an Anthropic-backed model on the same proxy

curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:28813/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "max_tokens": 2048, "thinking": {"type": "enabled", "budget_tokens": 1024},
       "messages": [
         {"role": "user", "content": "No tools. Which house colour does the zebra owner live in? One line."},
         {"role": "assistant", "content": [
           {"type": "thinking", "thinking": "**Analyzing housing clues** ...", "signature": "litellm_encrypted_reasoning:gAAAAABqobox..."},
           {"type": "text", "text": "The zebra owner lives in the green house."}]},
         {"role": "user", "content": "No tools. And who drinks water? One line."}]}'
HTTP 200
content: [{"type": "text", "text": "The Norwegian drinks water."}]
usage: {"input_tokens": 51, "output_tokens": 8}

Anthropic first answered 400 messages.1.content.0: Invalid signature in thinking block (visible in the proxy log), then the existing invalid-signature retry stripped every thinking block and resent, which is why the 200 carries no thinking block at all despite thinking.type: enabled

curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:28813/v1/chat/completions \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "max_tokens": 2048, "thinking": {"type": "enabled", "budget_tokens": 1024},
       "messages": [
         {"role": "user", "content": "No tools. Which house colour does the zebra owner live in? One line."},
         {"role": "assistant", "content": "The zebra owner lives in the green house.",
          "thinking_blocks": [{"type": "thinking", "thinking": "**Analyzing housing clues** ...", "signature": "litellm_encrypted_reasoning:gAAAAABqobox..."}]},
         {"role": "user", "content": "No tools. And who drinks water? One line."}]}'
HTTP 400
{"error": {"message": "litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.1.content.0: Invalid `signature` in `thinking` block\"}} ...", "type": "invalid_request_error", "code": "400"}}

Multi-deployment replay pins to the minting deployment

Two openai/gpt-5.1 deployments in one model group, each on its own OpenAI org in production (here the same key twice, told apart by model_info.id), with the router's encrypted_content_affinity check enabled

model_list:
  - model_name: gpt-5.1-ha
    litellm_params:
      model: openai/gpt-5.1
      api_key: os.environ/OPENAI_API_KEY
      drop_params: true
    model_info:
      id: openai-org-a
  - model_name: gpt-5.1-ha
    litellm_params:
      model: openai/gpt-5.1
      api_key: os.environ/OPENAI_API_KEY
      drop_params: true
    model_info:
      id: openai-org-b

router_settings:
  optional_pre_call_checks: ["encrypted_content_affinity"]

Turn one, then the same follow-up replayed six times with turn one's thinking block as the client received it

curl -s -D turn1.headers -o turn1.json http://127.0.0.1:28813/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d '{"model": "gpt-5.1-ha", "max_tokens": 8192, "thinking": {"type": "adaptive"},
       "messages": [{"role": "user", "content": "No tools. In the classic zebra puzzle, which house colour does the zebra owner live in? One line."}]}'
grep -i x-litellm-model-id turn1.headers
jq '{model:"gpt-5.1-ha", max_tokens:512, thinking:{type:"adaptive"}, messages:[
      {role:"user", content:"No tools. In the classic zebra puzzle, which house colour does the zebra owner live in? One line."},
      {role:"assistant", content:[.content[] | select(.type=="thinking" or .type=="redacted_thinking" or .type=="text")]},
      {role:"user", content:"No tools. And who drinks water? One line."}]}' turn1.json > turn2.json
for i in 1 2 3 4 5 6; do
  curl -s -D - -o /dev/null -w 'HTTP %{http_code}\n' http://127.0.0.1:28813/v1/messages \
    -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" -d @turn2.json | grep -i 'x-litellm-model-id\|^HTTP [0-9]'
done
turn 1 -> x-litellm-model-id: openai-org-a, thinking signature length 0, text: The zebra owner lives in the green house.
turn 2 replay #1 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #2 -> HTTP 200 x-litellm-model-id: openai-org-b
turn 2 replay #3 -> HTTP 200 x-litellm-model-id: openai-org-b
turn 2 replay #4 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #5 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #6 -> HTTP 200 x-litellm-model-id: openai-org-a

Turn one's thinking block has no signature (nothing encrypted came back), so there is nothing to pin and the follow-ups spread across both deployments. With real encrypted reasoning in the replay (the After leg) and two different orgs, every replay that lands on the other org is a 400 invalid_encrypted_content from OpenAI, and the affinity check that LiteLLM's own error text points at could not see the pin on this route because it only read the Responses input, which /v1/messages builds after the router has already picked a deployment

After (5a1be56)

Every case below ran at the tip 5a1be56 against one proxy booted from that commit with two uvicorn workers on port 24754, with a client recorder on 30016 in front of it for the Claude Code leg and an OpenAI recorder on 41554 as the api_base of the gpt-5.1 and gpt-5.1-tier deployments. The Claude Code leg ran first and the curl cases after it, so the recorder numbers below continue from the Claude Code leg's. The config lists gpt-5.1 (openai/gpt-5.1, drop_params: true), claude-sonnet-4-6, gemini-3.8-flash (gemini/gemini-3.8-flash), bedrock-sonnet-5 (bedrock/us.anthropic.claude-sonnet-5), perplexity-sonar (perplexity/perplexity/sonar, no drop_params), the two-deployment gpt-5.1-ha group (model_info.id openai-org-a and openai-org-b), gpt-5.1-tier (openai/gpt-5.1, model_info.id: openai-org-c), router_settings.optional_pre_call_checks: ["encrypted_content_affinity"], and litellm_settings.reasoning_auto_summary: true

Claude Code, three turns on gpt-5.1

Re-run at 5a1be56: Claude Code v2.1.267 in tmux, ANTHROPIC_BASE_URL pointing at a recorder on 30016 in front of the proxy on 24754 (two uvicorn workers), ANTHROPIC_MODEL=gpt-5.1, the same three prompts typed into the TUI as in the Before leg

  1. What the proxy sent to POST https://api.openai.com/v1/responses on each turn
request #1: include=['reasoning.encrypted_content'] reasoning={'effort': 'high', 'summary': 'detailed'}
   response usage: input_tokens=29682 cached_tokens=0 reasoning_tokens=464
   response reasoning item: id=rs_0c9d...9d58 encrypted_content=<3852 chars sha=17cf3acf4526> summary_parts=0

request #2: include=['reasoning.encrypted_content']
   input reasoning item: id=None encrypted_content=<3852 chars sha=17cf3acf4526> summary_parts=0
   response usage: input_tokens=30133 cached_tokens=29568 reasoning_tokens=1125
   response reasoning item: id=rs_0d6b...ab02 encrypted_content=<6924 chars sha=8d31b8bde5d2> summary_parts=4

request #3: include=['reasoning.encrypted_content']
   input reasoning item: id=None encrypted_content=<3852 chars sha=17cf3acf4526> summary_parts=0
   input reasoning item: id=None encrypted_content=<6924 chars sha=8d31b8bde5d2> summary_parts=1
   response usage: input_tokens=30585 cached_tokens=30080 reasoning_tokens=515
   response reasoning item: id=rs_0131...efc1 encrypted_content=<4152 chars sha=4d46eaa61b31> summary_parts=0

request #4: include=['reasoning.encrypted_content']
   input reasoning item: id=None encrypted_content=<3852 chars sha=17cf3acf4526> summary_parts=0
   input reasoning item: id=None encrypted_content=<6924 chars sha=8d31b8bde5d2> summary_parts=1
   input reasoning item: id=None encrypted_content=<4152 chars sha=4d46eaa61b31> summary_parts=0
   response usage: input_tokens=30901 cached_tokens=30464 reasoning_tokens=1005
   response reasoning item: id=rs_0812...6faf encrypted_content=<7224 chars sha=df8f25c52f21> summary_parts=2

Every request asks for the encrypted reasoning and every replayed item carries the exact bytes the model produced (the sha of each response item's encrypted_content, taken from its response.output_item.done event, reappears unchanged as the input item on every later turn), and OpenAI's cache covers the whole growing prefix: cached_tokens 29568 of 30133 on turn two, 30080 of 30585 on turn three, 30464 of 30901 on the last request. The request the proxy sends is the same with or without a client thinking block, since Claude Code sends one on every turn here; request #1 is the boot-time title request. Two of the four turns came back with no summary this run, so they travel as redacted_thinking blocks below

  1. What Claude Code received and sent back on POST http://127.0.0.1:30016/v1/messages
request #3: thinking={'type': 'adaptive'}
   streamed redacted_thinking block: data=<3993 chars>
request #4:
   replayed redacted_thinking: data=<3993 chars>
   streamed thinking block: signature='<7065 chars>' thinking_len=1895
request #5:
   replayed redacted_thinking: data=<3993 chars>
   replayed thinking: signature='<7065 chars>' thinking_len=1895
   streamed redacted_thinking block: data=<4293 chars>
request #6:
   replayed redacted_thinking: data=<3993 chars>
   replayed thinking: signature='<7065 chars>' thinking_len=1895
   replayed redacted_thinking: data=<4293 chars>
   streamed thinking block: signature='<7365 chars>' thinking_len=895

Each turn's block carries the encrypted reasoning (the litellm_encrypted_reasoning: payload plus the deployment wrapper, hence the length over the raw ciphertext) in the thinking block's signature when OpenAI returned a summary and in a redacted_thinking block's data when it did not, and Claude Code replays every one of them untouched, both shapes side by side. The 4716b46 run of this leg had three signed thinking blocks and a summary-less last turn; the e27a018 run had the summary-less turn first

  1. Claude Code's pane at the end of the session

pr40451-5a1be56426-after8_claude_code.png

Multi-deployment replay pins to the minting deployment

Two openai/gpt-5.1 deployments in one model group, each on its own OpenAI org in production (here the same key twice, told apart by model_info.id), with the router's encrypted_content_affinity check enabled

model_list:
  - model_name: gpt-5.1-ha
    litellm_params:
      model: openai/gpt-5.1
      api_key: os.environ/OPENAI_API_KEY
      drop_params: true
    model_info:
      id: openai-org-a
  - model_name: gpt-5.1-ha
    litellm_params:
      model: openai/gpt-5.1
      api_key: os.environ/OPENAI_API_KEY
      drop_params: true
    model_info:
      id: openai-org-b

router_settings:
  optional_pre_call_checks: ["encrypted_content_affinity"]

Turn one, then the same follow-up replayed six times with turn one's thinking block as the client received it

curl -s -D turn1.headers -o turn1.json http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d '{"model": "gpt-5.1-ha", "max_tokens": 8192, "thinking": {"type": "adaptive"},
       "messages": [{"role": "user", "content": "No tools. In the classic zebra puzzle, which house colour does the zebra owner live in? One line."}]}'
grep -i x-litellm-model-id turn1.headers
jq '{model:"gpt-5.1-ha", max_tokens:512, thinking:{type:"adaptive"}, messages:[
      {role:"user", content:"No tools. In the classic zebra puzzle, which house colour does the zebra owner live in? One line."},
      {role:"assistant", content:[.content[] | select(.type=="thinking" or .type=="redacted_thinking" or .type=="text")]},
      {role:"user", content:"No tools. And who drinks water? One line."}]}' turn1.json > turn2.json
for i in 1 2 3 4 5 6; do
  curl -s -D - -o /dev/null -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
    -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" -d @turn2.json | grep -i 'x-litellm-model-id\|^HTTP [0-9]'
done
turn 1 -> x-litellm-model-id: openai-org-a, thinking signature length 2301, text: The zebra owner lives in the green house.
turn 2 replay #1 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #2 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #3 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #4 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #5 -> HTTP 200 x-litellm-model-id: openai-org-a
turn 2 replay #6 -> HTTP 200 x-litellm-model-id: openai-org-a

Turn one came back as a thinking block whose signature carries the encrypted reasoning wrapped with the minting deployment id, and all six replays are pinned to openai-org-a. The proxy log shows the check doing it: EncryptedContentAffinityCheck: decoded model_id=openai-org-a from the request's encrypted content markers then pinning -> deployment=openai-org-a, once per replay (six lines). The same case at e27a018 landed turn one on openai-org-b as a redacted_thinking block (no summary that turn) and pinned all six replays there, so both block shapes carry the pin

Tool-use continuation on gpt-5.1

A tool call turn, then the tool_result continuation with the assistant's reasoning and tool_use blocks replayed as the client received them (the shape every agentic turn in Claude Code takes)

tools='[{"name":"get_weather","description":"Current weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}]'
curl -s -o turn1.json -w 'turn 1 -> HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d "{\"model\": \"gpt-5.1\", \"max_tokens\": 2048, \"thinking\": {\"type\": \"adaptive\"}, \"tools\": $tools,
       \"messages\": [{\"role\": \"user\", \"content\": \"Use get_weather for Paris, then tell me in one line whether to bring an umbrella.\"}]}"
jq -c '[.content[]|{type, sig_prefix: ((.signature // .data // "")[:40]), name, input}]' turn1.json
jq -n --argjson tools "$tools" --slurpfile t1 turn1.json '
  ($t1[0].content | map(select(.type=="thinking" or .type=="redacted_thinking" or .type=="tool_use"))) as $assistant
  | ($assistant | map(select(.type=="tool_use"))[0].id) as $tid
  | {model:"gpt-5.1", max_tokens:512, thinking:{type:"adaptive"}, tools:$tools, messages:[
      {role:"user",content:"Use get_weather for Paris, then tell me in one line whether to bring an umbrella."},
      {role:"assistant",content:$assistant},
      {role:"user",content:[{type:"tool_result",tool_use_id:$tid,content:"Paris: 14C, light rain all afternoon"}]}]}' > turn2.json
curl -s -w 'turn 2 (tool_result continuation) -> HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" -d @turn2.json
turn 1 -> HTTP 200
[{"type":"redacted_thinking","sig_prefix":"litellm_encrypted_reasoning:litellm_enc:","name":null,"input":null},{"type":"tool_use","sig_prefix":"","name":"get_weather","input":{"city":"Paris"}}]
turn 2 (tool_result continuation) -> HTTP 200
{"content":[{"type":"text","text":"Yes—bring an umbrella, there’s light rain expected all afternoon in Paris."}],"usage":{"input_tokens":118,"output_tokens":20}}

On the OpenAI recorder, the continuation replays the reasoning item ahead of the tool call and its output, byte for byte the item turn one returned

request #6: include=['reasoning.encrypted_content'] tools=['get_weather']
   response reasoning item: id=rs_05b...f63c encrypted_content=<1316 chars sha=4902f10b1402> summary_parts=0
   response function_call: call_id=call_rhpKnHeQiG9bPtiL1JC7gCIO name=get_weather arguments={"city":"Paris"}

request #7: include=['reasoning.encrypted_content'] tools=['get_weather']
   input reasoning item: id=None encrypted_content=<1316 chars sha=4902f10b1402> summary_parts=0
   input function_call: call_id=call_rhpKnHeQiG9bPtiL1JC7gCIO name=get_weather arguments={"city": "Paris"}
   input function_call_output: call_id=call_rhpKnHeQiG9bPtiL1JC7gCIO output=Paris: 14C, light rain all afternoon
   response message: Yes—bring an umbrella, there’s light rain expected all afternoon in Paris.

(The 4716b46 run of this case returned turn one as a signed thinking block with a 1784-char item and replayed it the same way)

Auto-router tier change strips the other org's reasoning

The customer's auto-router can send a follow-up to a different model group than the turn that produced the reasoning. Here gpt-5.1-tier is a third OpenAI org that never minted anything in the conversation, so the pin from turn one names a deployment that is not a candidate

  - model_name: gpt-5.1-tier
    litellm_params:
      model: openai/gpt-5.1
      api_key: os.environ/OPENAI_API_KEY
      drop_params: true
    model_info:
      id: openai-org-c

Turn one on gpt-5.1-ha, then the follow-up replayed with model: gpt-5.1-tier and turn one's blocks as the client received them

curl -s -D turn1.headers -o turn1.json http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d '{"model": "gpt-5.1-ha", "max_tokens": 8192, "thinking": {"type": "adaptive"},
       "messages": [{"role": "user", "content": "No tools. In the classic zebra puzzle, which house colour does the zebra owner live in? One line."}]}'
grep -i x-litellm-model-id turn1.headers
jq -c '[.content[]|{type, len: ((.signature // .data // .text // "")|length)}]' turn1.json
jq '{model:"gpt-5.1-tier", max_tokens:512, thinking:{type:"adaptive"}, messages:[
      {role:"user", content:"No tools. In the classic zebra puzzle, which house colour does the zebra owner live in? One line."},
      {role:"assistant", content:[.content[] | select(.type=="thinking" or .type=="redacted_thinking" or .type=="text")]},
      {role:"user", content:"No tools. And who drinks water? One line."}]}' turn1.json > turn2.json
curl -s -D - -o turn2.out -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" -d @turn2.json | grep -i 'x-litellm-model-id\|^HTTP [0-9]'
jq -r '[.content[]|select(.type=="text")][0].text' turn2.out
turn 1 on gpt-5.1-ha -> x-litellm-model-id: openai-org-a, blocks: [{"type":"redacted_thinking","len":2513},{"type":"text","len":41}]
turn 2 replayed to gpt-5.1-tier -> HTTP 200 x-litellm-model-id: openai-org-c, text: The Norwegian drinks the water.

The proxy log names the decision: EncryptedContentAffinityCheck: model_id=openai-org-a is not a candidate for the routed group gpt-5.1-tier; forwarding without its encrypted reasoning. On the recorder, the request that reached org-c carries the three messages and no reasoning item

request #8: include=['reasoning.encrypted_content'] tools=[]
   input message role=user parts=['input_text']
   input message role=assistant parts=['output_text']
   input message role=user parts=['input_text']
   response reasoning item: id=rs_01f...4461 encrypted_content=<3512 chars sha=6ea516bd2319> summary_parts=2
   response message: The Norwegian drinks the water.

The same replay built from a signed thinking block with readable text (turn one of an earlier multi-deployment run: a 6569-char signature from openai-org-a over the text "Recalling clues for a puzzle ..."), with max_tokens: 4096

HTTP 200
x-litellm-model-id: openai-org-c
{"stop_reason":"end_turn","usage":{"input_tokens":59,"output_tokens":159},"content":[{"type":"thinking","len":511},{"type":"text","len":27,"text":"The Norwegian drinks water."}]}
request #9: include=['reasoning.encrypted_content'] tools=[]
   input message role=user parts=['input_text']
   input message role=assistant parts=['output_text']
   input message role=user parts=['input_text']
   response reasoning item: id=rs_0cc...86bd encrypted_content=<2084 chars sha=5ac6e1a99d99> summary_parts=1
   response message: The Norwegian drinks water.

The signed text block is dropped whole too: nothing from turn one's reasoning reaches org-c, its text included, and the new org answers from the conversation text alone. At 4716b46 this replay kept the text as an unsigned thinking block, which the OpenAI bridge turned into a summary-only reasoning item but Anthropic and Bedrock reject outright, the model-switch case next

Mid-session model switch with the affinity check on

The same signed text turn from openai-org-a replayed to an Anthropic, a Gemini, and a Bedrock deployment with encrypted_content_affinity enabled (the /model switch in Claude Code after a few OpenAI turns, on a proxy that also runs the multi-org group). This is the Bugbot finding on 4716b46: the check stripped the signature and left the text behind as an unsigned thinking block

for m in claude-sonnet-4-6 gemini-3.8-flash bedrock-sonnet-5; do
  jq --arg m $m '.model=$m | .max_tokens=4096' turn2.json > switch_$m.json
  curl -s -o switch_$m.out -w "$m -> HTTP %{http_code}\n" http://127.0.0.1:24754/v1/messages \
    -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" -d @switch_$m.json
done
grep -c 'invalid thinking signature' proxy.log

At 4716b46 (the previous tip, proxy on 26604)

claude-sonnet-4-6 -> HTTP 200
content: [{"type": "text", "text": "The Norwegian drinks water."}]   usage: {"input_tokens": 59, "output_tokens": 13}
gemini-3.8-flash -> HTTP 200
bedrock-sonnet-5 -> HTTP 400
{"type":"error","error":{"type":"invalid_request_error","message":"litellm.BadRequestError: BedrockException - {\"message\":\"messages.1.content.0.thinking.signature: Field required\"}. Received Model Group=bedrock-sonnet-5 ..."}}
1

Anthropic's 200 there is the second attempt: the proxy log shows the 400 on the unsigned block and then Anthropic /v1/messages: invalid thinking signature; stripping thinking blocks and retrying (attempt 2/2). Bedrock has no such retry and returns the 400 to the client

At 5a1be56 (proxy on 24754)

claude-sonnet-4-6 -> HTTP 200
content: [{"type": "thinking", "thinking": "Let me work through the classic Zebra puzzle (also known as Einstein's puzzle).\n ...", "signature": "EtQ2CpIBCBEYAipADzEmuS..."},
          {"type": "text", "text": "The Norwegian drinks water."}]   usage: {"input_tokens": 59, "output_tokens": 2398}
gemini-3.8-flash -> HTTP 200
content: [{"type": "thinking", "thinking": "**My Zebra Puzzle Deduction**\n\nOkay, the question is \"who drinks water?\" ..."},
          {"type": "text", "text": "The Norwegian drinks water."}]   usage: {"input_tokens": 47, "output_tokens": 285}
bedrock-sonnet-5 -> HTTP 200
content: [{"type": "text", "text": "In the classic Zebra Puzzle, the Norwegian drinks water."}]   usage: {"input_tokens": 72, "output_tokens": 27}
0

All three answer on the first attempt with their own reasoning, and the proxy log has the three not a candidate for the routed group lines and no strip-and-retry line

Cross-model replay to claude-sonnet-4-6, gemini-3.8-flash, and bedrock-sonnet-5

Same two commands as the Before leg, against the proxy booted from this branch

curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d @crossmodel_messages.json
HTTP 200
content: [{"type": "thinking", "thinking": "The Norwegian drinks water in the classic Zebra/Einstein puzzle.", "signature": "ErUCCpIBCBEYAipAq/Pp..."},
          {"type": "text", "text": "The Norwegian drinks water."}]
usage: {"input_tokens": 80, "output_tokens": 30, "output_tokens_details": {"thinking_tokens": 19}}

One request to Anthropic, no 400, no strip-and-retry in the proxy log, and Claude's own thinking block comes back

curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/chat/completions \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d @crossmodel_chat.json
HTTP 200
{"choices": [{"message": {"role": "assistant", "content": "The Norwegian drinks water."}}], "model": "claude-sonnet-4-6"}

The same bridge-signed history sent to a Gemini deployment (the mid-session /model switch in Claude Code from gpt-5.1 to Gemini)

sed 's/"claude-sonnet-4-6"/"gemini-3.8-flash"/' crossmodel_messages.json > gemini_messages.json
curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d @gemini_messages.json
HTTP 200
content: [{"type": "text", "text": "The Norwegian drinks water."}]
usage: {"input_tokens": 39, "output_tokens": 5}

At the merge base the same history carries signature: "" and Gemini answers 200 as well; the interim tip of this branch (751431d) forwarded the bridge-tagged signature as a thoughtSignature and Gemini answered 400 Base64 decoding failed, which is what the chat-adapter strip fixes

The same history sent to a Bedrock deployment (bedrock/us.anthropic.claude-sonnet-5)

sed 's/"claude-sonnet-4-6"/"bedrock-sonnet-5"/' crossmodel_messages.json > bedrock_messages.json
curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d @bedrock_messages.json
HTTP 200
content: [{"type": "thinking", "thinking": "", "signature": "EpwCCnkIERABGAIqQATj..."},
          {"type": "text", "text": "The Norwegian drinks water."}]
usage: {"input_tokens": 59, "output_tokens": 41, "output_tokens_details": {"thinking_tokens": 27}}

Bedrock answers 200 with the bridge-tagged block dropped up front, and this run came back with Bedrock's own signed thinking block in front of the text (the 4716b46 run answered without thinking)

sed 's/"claude-sonnet-4-6"/"bedrock-sonnet-5"/' crossmodel_chat.json > bedrock_chat.json
curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/chat/completions \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d @bedrock_chat.json
HTTP 400
{"error": {"message": "litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: messages.1.content.0: Invalid `signature` in `thinking` block\"} ...", "type": "invalid_request_error", "code": "400"}}

/v1/chat/completions with a bridge-tagged thinking_blocks[].signature still gets the provider's 400 on Gemini and Bedrock, exactly as it does at the merge base for any signature the provider did not mint: the chat bridge never emits bridge-tagged signatures, so that history only exists when a client copies one across routes by hand

A Responses provider that rejects include

perplexity/perplexity/sonar is routed to the same bridge (mode responses) but its Responses API rejects include, so the bridge leaves it out there

curl -s -w 'HTTP %{http_code}\n' http://127.0.0.1:24754/v1/messages \
  -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
  -d '{"model": "perplexity-sonar", "max_tokens": 512, "thinking": {"type": "enabled", "budget_tokens": 1024},
       "messages": [{"role": "user", "content": "One line: which house colour does the zebra owner live in, in the classic zebra puzzle?"}]}'
HTTP 200
content: [{"type": "text", "text": "The zebra owner lives in the **green house**."}]
usage: {"input_tokens": 44, "output_tokens": 85}

Without the provider check this call fails with UnsupportedParamsError: LlmProviders.PERPLEXITY does not support parameters: {'include': ['reasoning.encrypted_content']} unless the deployment sets drop_params

Observations from the run

  • Before leg cache hits were already high: the summary-only item is stable too
  • The customer's loss is the encrypted reasoning itself, discarded every turn
  • Before leg drops summary-less reasoning items entirely on replay
  • Existing invalid-signature retry strips Anthropic's own signed blocks as well; this PR leaves it alone
  • OpenAI's prompt cache is best-effort: an earlier After run reported cached_tokens=0 on turn two and hits on the next two with byte-identical input prefixes; this run hit on every turn after the first. What the PR controls is the input bytes
  • A tier change to a group the minting org is not in drops that turn's reasoning outright, summary text included: the new org could not decrypt the bytes, and an unsigned leftover is what Anthropic and Bedrock reject
  • OpenAI serializes the same reasoning item twice per stream with two different ciphertexts (response.output_item.done and response.completed carry different encrypted_content bytes of the same length). The bridge replays the output_item.done bytes, and OpenAI accepts and caches them, as the per-turn cache hits above show

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Azure Responses deployments and /v1/chat/completions clients keep lossy reasoning replay
    • _RESPONSES_API_PROVIDERS is frozenset({"openai"}), so Azure Responses-mode deployments reach OpenAI through the chat->Responses bridge from /v1/messages, and that bridge never asks for include. Follow-up: LIT-7419
  • Every turn's encrypted reasoning is replayed for the life of the session, with no cap
    • Decision: each assistant turn carries its 1.3 to 10 KB encrypted reasoning in signature (or redacted_thinking.data), the client replays all of them, and the bridge forwards all of them. Issue [Bug]: reasoning items rebuilt from lossy summary text on every turn, breaking prompt-cache byte-stability for OpenAI reasoning models behind /v1/messages #40288 flagged the per-turn growth and asked for this to be chosen explicitly, naming a last-N-turns cap as one option. Alternatives not taken: replaying only the last N turns' payloads, or dropping payloads past a byte budget. Both change the input bytes for every turn after the first drop, which is the lossy prefix this PR removes, and OpenAI only reads reasoning it can decrypt, so a dropped item is a lost item. The client owns history length (Claude Code compacts), and the same growth already exists for Anthropic's own signatures
  • A reasoning turn with no summary comes back as a redacted_thinking block
    • Without reasoning_auto_summary or thinking.summary, OpenAI returns no summary text, so the block is {"type": "redacted_thinking", "data": "litellm_encrypted_reasoning:..."} where the merge base returned text only. That is the Messages API's shape for opaque reasoning; an empty thinking block would misrepresent it as visible text

Low

  • Bridge-tagged blocks replayed to a non-OpenAI model, or to an OpenAI group the minting deployment is not part of, are dropped whole, text included
    • After a mid-session model switch the OpenAI reasoning text is not carried over to Anthropic, Gemini, or Bedrock, and after a tier change it is not carried over to the new OpenAI org either. Forwarding the block signed is a guaranteed 400 (the provider did not mint it), forwarding it unsigned is the same 400 from Anthropic and Bedrock (thinking.signature: Field required, the Bugbot finding on 4716b46, shown in the model-switch case above), and the merge base lost the same text through its strip-and-retry, so dropping it up front is the same outcome without the failed request
    • Decision for the cross-group route (a tier change): forward the conversation without the blocks the routed org cannot decrypt, the call fix(router): strip encrypted reasoning on an auto-router tier change instead of a 503 #40280 already made for Responses input. Alternatives not taken: keeping the readable text as an unsigned thinking block (what 4716b46 did; the OpenAI bridge turned it into a summary-only reasoning item, but Anthropic and Bedrock 400 on it, so the router would have to know the routed provider to pick per target), a 400 naming the pin (every tier change in the customer's auto-router would then fail), or routing back to the minting deployment (it is not a candidate in the routed group, which is the point of the tier change)
  • The Before screenshot file is named after an interim commit
    • Screenshot assets are named after the PR head at upload time (751431d), not the commit the leg ran at; the heading and the per-leg ports above are the provenance, and the recorded upstream request bodies are the evidence
  • A reasoning output_item.done with no id lands on whichever block is current
    • _close_reasoning_item falls back to the current block index when the item has no id. OpenAI always sends reasoning item ids and only OpenAI-routed deployments reach this iterator, so it needs a non-OpenAI upstream behind the openai/ prefix to trigger
  • The Before and After screenshots show the same Claude Code outcome
    • The bug is invisible in the TUI by construction (the loss is in the bytes sent upstream), so each screenshot is paired with the recorded upstream request bodies, which is where the difference shows
  • Multi-part reasoning summaries are replayed as one summary part
    • The summary is display text; the encrypted payload is what the model reads, and it is replayed unchanged

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

…d /v1/messages

Reasoning items the Responses API returned for a /v1/messages turn were rebuilt
from their summary text on every replay, so the prompt the model saw changed
between turns and the prompt cache never matched. The bridge now asks for
reasoning.encrypted_content, carries it in the thinking signature (or as a
redacted_thinking block when there is no summary), and replays it verbatim as
the reasoning item's encrypted_content. Anthropic replay paths drop those
tagged blocks so a cross-model resume never forwards OpenAI bytes to Anthropic
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_responses_bridge_replay_encrypted_reasoning (5a1be56) with litellm_internal_staging (2611f64)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (9839bfc) during the generation of this report, so 2611f64 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 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR carries OpenAI encrypted reasoning through the Anthropic Messages bridge, replays it across turns, and adds deployment affinity and cross-provider sanitization

  • Requests encrypted reasoning from compatible Responses providers
  • Encodes reasoning into thinking or redacted-thinking blocks and restores it on replay
  • Pins follow-up requests to compatible deployments
  • Removes foreign reasoning markers before incompatible provider calls
  • Adds focused translation, streaming, routing, and sanitization coverage

Confidence Score: 4/5

The PR is not yet safe to merge because cross-group OpenAI routing can discard readable reasoning context, and a repository typing requirement remains unmet

The cross-group affinity path unconditionally removes complete bridge-tagged blocks, even when the destination is another OpenAI Responses deployment that can retain their readable text as summary-only reasoning. The new Anthropic sanitization helpers also violate the repository’s strong-typing requirement. The prior affinity finding is no longer outstanding because its thread was resolved and the current code reads the callback’s messages argument

Files Needing Attention: litellm/litellm_core_utils/prompt_templates/common_utils.py, litellm/llms/anthropic/common_utils.py

Important Files Changed

Filename Overview
litellm/litellm_core_utils/prompt_templates/common_utils.py Adds encrypted-reasoning encoding and replay helpers, but cross-group stripping now unnecessarily discards readable summaries
litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py Extends affinity detection to Messages history and strips unusable reasoning when the origin is outside the routed group
litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py Translates encrypted Responses reasoning into replayable Anthropic block shapes and restores each item on subsequent requests
litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py Emits summary separators, encrypted signature deltas, and redacted-thinking blocks for streamed reasoning
litellm/llms/anthropic/common_utils.py Adds foreign-reasoning sanitization for Anthropic requests, but introduces coarse dictionary parameter types forbidden by repository guidance

Reviews (6): Last reviewed commit: "fix(router): drop bridge-tagged reasonin..." | Re-trigger Greptile

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@devin-ai-integration

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

Copy link
Copy Markdown
Contributor Author

Devin e2e QA

Tested at: f49ebc9
Session: https://app.devin.ai/sessions/a0f650f47d724f09b4abd85b5f72a03c

Setup shared by both legs: the same config as the PR description (gpt-5.1 as openai/gpt-5.1 with drop_params: true, claude-sonnet-4-6 as anthropic/claude-sonnet-4-6, reasoning_auto_summary: true), a proxy per leg with --num_workers 2 --detailed_debug on a free high port, a recording reverse proxy in front of https://api.openai.com set as the OpenAI api_base, a second recording reverse proxy between Claude Code and the proxy so what Claude Code sent and received on /v1/messages could be logged, and Claude Code v2.1.267 driven interactively in tmux (env -u ANTHROPIC_API_KEY ANTHROPIC_BASE_URL=<recorder> ANTHROPIC_AUTH_TOKEN=sk-lit7339-qa ANTHROPIC_MODEL=gpt-5.1 ANTHROPIC_SMALL_FAST_MODEL=gpt-5.1 claude). Real OpenAI and Anthropic keys, real spend. Before proxy: port 57625. After proxy: port 44819

Three prompts typed into Claude Code, one turn each: the five-houses zebra puzzle ("Do not use any tools. Solve this in your head and answer briefly. Five houses in a row ... Who drinks water, and who owns the zebra?"), then "No tools. Which house colour does the zebra owner live in, and who is their left-hand neighbour? One line.", then "No tools. And who smokes Kools? One line."

In the upstream logs below, request #1 is a smoke curl with thinking off and request #2 is Claude Code's own startup call; requests #3 to #5 are the three turns. Each reasoning item is listed twice on the response side because OpenAI streams it in response.output_item.done and again inside response.completed, and the two copies are different ciphertexts of the same length (same Fernet timestamp prefix, fresh IV). The bridge replays the response.output_item.done bytes

Before (075655c)

Claude Code, three turns on gpt-5.1

  1. What the proxy sent to POST https://api.openai.com/v1/responses on each turn
$ python analyze.py openai v2_before_openai.jsonl
request #3: include=None reasoning={'effort': 'high', 'summary': 'detailed'} status=200
   response.output_item.done reasoning item: id=rs_0757...2b7c94 encrypted_content=<1976 chars sha=344d983d1b45> summary_parts=1
   response usage: input_tokens=18909 cached_tokens=0 reasoning_tokens=112

request #4: include=None reasoning={'effort': 'high', 'summary': 'detailed'} status=200
   input reasoning item: id=None encrypted_content=None summary_parts=1
   response.output_item.done reasoning item: id=rs_02eb...806dd8 encrypted_content=<3468 chars sha=9168e4a8e6d0> summary_parts=0
   response usage: input_tokens=18972 cached_tokens=18816 reasoning_tokens=387

request #5: include=None reasoning={'effort': 'high', 'summary': 'detailed'} status=200
   input reasoning item: id=None encrypted_content=None summary_parts=1
   response.output_item.done reasoning item: id=rs_09b5...6cd9c9 encrypted_content=<4836 chars sha=4f4fd96fbda7> summary_parts=4
   response usage: input_tokens=19031 cached_tokens=18816 reasoning_tokens=720

No request asks for reasoning.encrypted_content, every replayed reasoning item is a rebuild from the summary text with encrypted_content=None, and the summary-less item from request #4 is not replayed at all in request #5

  1. What Claude Code received and sent back on POST /v1/messages
$ python analyze.py messages v2_before_messages.jsonl
request #4: model=gpt-5.1 thinking={'type': 'adaptive'} status=200
   streamed thinking block: signature=''<0 chars> thinking_len=464

request #5: model=gpt-5.1 thinking={'type': 'adaptive'} status=200
   replayed thinking: signature=''<0 chars> thinking_len=464

request #6: model=gpt-5.1 thinking={'type': 'adaptive'} status=200
   replayed thinking: signature=''<0 chars> thinking_len=464
   streamed thinking block: signature=''<0 chars> thinking_len=1949

Turn two's response reached Claude Code with no thinking block at all because its reasoning item had no summary

  1. Claude Code's pane at the end of the session

Claude Code before

Cross-model replay to claude-sonnet-4-6

The assistant turn carries the thinking block Claude Code received on turn three of the After leg (475 chars of thinking, signature litellm_encrypted_reasoning:..., 11176 chars), so both legs replay the same bridge-tagged block

  1. /v1/messages
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:57625/v1/messages \
    -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
    -d @v2_crossmodel_messages.json
{"model": "claude-sonnet-4-6", "id": "msg_011Cetc2nvhC85RxPFdFKZSb", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "The Norwegian drinks water."}], "stop_reason": "end_turn", "usage": {"input_tokens": 46, "output_tokens": 8}}
HTTP 200

The proxy log shows Anthropic first answered messages.1.content.0: Invalid signature in thinking block, then the existing strip-and-retry resent without any thinking block, which is why the 200 has no thinking despite thinking.type: enabled (44 Invalid signature log lines in the Before proxy log across the runs, 0 in the After log)

  1. /v1/chat/completions
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:57625/v1/chat/completions \
    -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
    -d @v2_crossmodel_chat.json
{"error":{"message":"litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.1.content.0: Invalid `signature` in `thinking` block\"},\"request_id\":\"req_011Cetc63Zr1VUS57eKfJEuF\"}. Received Model Group=claude-sonnet-4-6\nAvailable Model Group Fallbacks=None","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400

After (f49ebc9)

Claude Code, three turns on gpt-5.1

  1. What the proxy sent to POST https://api.openai.com/v1/responses on each turn
$ python analyze.py openai v2_after_openai.jsonl
request #3: include=['reasoning.encrypted_content'] reasoning={'effort': 'high', 'summary': 'detailed'} status=200
   response.output_item.done reasoning item: id=rs_0b3d...27ded4 encrypted_content=<36772 chars sha=33b041ccbbac> summary_parts=6
   response usage: input_tokens=18909 cached_tokens=18816 reasoning_tokens=6616

request #4: include=['reasoning.encrypted_content'] reasoning={'effort': 'high', 'summary': 'detailed'} status=200
   input reasoning item: id=None encrypted_content=<36772 chars sha=33b041ccbbac> summary_parts=1
   response.output_item.done reasoning item: id=rs_071c...ca6299 encrypted_content=<5496 chars sha=76f41e13f04a> summary_parts=4
   response usage: input_tokens=18972 cached_tokens=18816 reasoning_tokens=801

request #5: include=['reasoning.encrypted_content'] reasoning={'effort': 'high', 'summary': 'detailed'} status=200
   input reasoning item: id=None encrypted_content=<36772 chars sha=33b041ccbbac> summary_parts=1
   input reasoning item: id=None encrypted_content=<5496 chars sha=76f41e13f04a> summary_parts=1
   response.output_item.done reasoning item: id=rs_05b5...c8afc6 encrypted_content=<11148 chars sha=fae8da937330> summary_parts=1
   response usage: input_tokens=19035 cached_tokens=18816 reasoning_tokens=1860

Every request carries include=['reasoning.encrypted_content'], including the two thinking-off requests #1 and #2, since OpenAI is a provider that returns it. The item OpenAI produced in request #3 (sha=33b041ccbbac) comes back byte-identical as input in requests #4 and #5, and the request #4 item (sha=76f41e13f04a) comes back byte-identical in request #5

  1. What Claude Code received and sent back on POST /v1/messages
$ python analyze.py messages v2_after_messages.jsonl
request #4: model=gpt-5.1 thinking={'type': 'adaptive'} status=200
   streamed thinking block: signature='litellm_encrypted_reasoning:'<36800 chars sha=37e0216c2367> thinking_len=3664

request #5: model=gpt-5.1 thinking={'type': 'adaptive'} status=200
   replayed thinking: signature='litellm_encrypted_reasoning:'<36800 chars sha=37e0216c2367> thinking_len=3664
   streamed thinking block: signature='litellm_encrypted_reasoning:'<5524 chars sha=17b67b87f076> thinking_len=2204

request #6: model=gpt-5.1 thinking={'type': 'adaptive'} status=200
   replayed thinking: signature='litellm_encrypted_reasoning:'<36800 chars sha=37e0216c2367> thinking_len=3664
   replayed thinking: signature='litellm_encrypted_reasoning:'<5524 chars sha=17b67b87f076> thinking_len=2204
   streamed thinking block: signature='litellm_encrypted_reasoning:'<11176 chars sha=9640774878cc> thinking_len=475
  1. Claude Code's pane at the end of the session

Claude Code after

Cross-model replay to claude-sonnet-4-6

Same two payloads as the Before leg

  1. /v1/messages
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:44819/v1/messages \
    -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
    -d @v2_crossmodel_messages.json
{"model": "claude-sonnet-4-6", "id": "msg_011Cetc36GEXojc9my6SEv6P", "type": "message", "role": "assistant", "content": [{"type": "thinking", "thinking": "The Norwegian drinks water.", "signature": "EpACCpIBCBEYAipAyYjiLVTZ5NKIm/psIndn0FlMcpEi3Izzh/Y/52U/z07L...<372 chars>"}, {"type": "text", "text": "The Norwegian drinks water."}], "stop_reason": "end_turn", "usage": {"input_tokens": 75, "output_tokens": 21, "output_tokens_details": {"thinking_tokens": 10}}}
HTTP 200

One request to Anthropic, no Invalid signature line in the proxy log, and Claude's own signed thinking block comes back

  1. /v1/chat/completions
$ curl -s -w '\nHTTP %{http_code}\n' http://127.0.0.1:44819/v1/chat/completions \
    -H "Authorization: Bearer sk-lit7339-qa" -H "content-type: application/json" \
    -d @v2_crossmodel_chat.json
{"id": "chatcmpl-bd26daac-9e77-4846-ab94-71a11b7db14c", "model": "claude-sonnet-4-6", "object": "chat.completion", "choices": [{"finish_reason": "stop", "index": 0, "message": {"content": "The Norwegian drinks water.", "role": "assistant", "reasoning_content": "The Norwegian drinks water.", "thinking_blocks": [{"type": "thinking", "thinking": "The Norwegian drinks water.", "signature": "EpACCpIBCBEYAipAyYjiLVTZ5NKIm/psIndn0FlMcpEi3Izzh/Y/52U/z07L...<372 chars>"}]}}], "usage": {"completion_tokens": 21, "prompt_tokens": 75, "total_tokens": 96}}
HTTP 200

Observations from the run

The bridge replays every reasoning item with summary_parts=1 even when OpenAI returned 4 or 6 summary parts, since the thinking text is carried as one block; the encrypted payload is the part OpenAI validates and it is unchanged. Turn one of the After leg took 1m16s and 6616 reasoning tokens on the model side, which is model variance, and the proxy log has no retry for it. Long JSON values above are shortened to 60 chars plus their length; everything else is the raw output

…provider returns it

The bridge now asks for reasoning.encrypted_content whenever the provider's
Responses config lists include, independent of the client's thinking block,
and leaves it out for providers such as Perplexity that reject the param.
Bridge-tagged blocks are stripped on the chat adapter path too, so a mid
session model switch to Gemini or Bedrock no longer forwards them as real
signatures, a bare prefix counts as bridge-tagged, and non-mapping messages
pass through the strip untouched.
@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 9, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…t that minted it

The encrypted_content_affinity check only read the pin from the Responses
input, which /v1/messages builds after the router has picked a deployment,
so a model group spread across OpenAI orgs sent follow-up turns to the
wrong org and got invalid_encrypted_content back. The check now also
decodes the pin from bridge-tagged thinking and redacted_thinking blocks
in the Anthropic messages. The bridge also keeps a deployment's own
include list next to reasoning.encrypted_content instead of replacing it.
@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 9, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…itellm_responses_bridge_replay_encrypted_reasoning

# Conflicts:
#	litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py
#	tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py
…ip bridge reasoning on a cross-group route

The encrypted_content_affinity check only read the Anthropic history from request_kwargs["messages"], so a caller that passes it through the callback's messages argument alone skipped the pin. Read the argument first and fall back to the kwargs.

When the minting deployment is not a candidate of the routed group, the base already strips the Responses input's encrypted reasoning; do the same for the bridge-tagged thinking blocks in Anthropic messages so the routed deployment gets the readable thinking text instead of ciphertext it cannot decrypt.
@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 10, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

…ng deployment is not in the routed group

The cross-group branch of EncryptedContentAffinityCheck removed only the signature from
Anthropic-shaped thinking blocks, which left unsigned thinking blocks that Anthropic and
Bedrock reject (thinking.signature: Field required). Drop the whole block, the way #40280
drops undecryptable Responses input items, so the routed request carries the conversation
text with no reasoning item for those turns
@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 10, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

Comment thread litellm/llms/anthropic/common_utils.py Resolved

@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 5a1be56. 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 8ec2f00 into litellm_internal_staging Sep 10, 2026
122 of 128 checks passed
@mateo-berri
mateo-berri deleted the litellm_responses_bridge_replay_encrypted_reasoning branch September 10, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant