Skip to content

fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them - #54173

Merged
mateo-berri merged 26 commits into
BerriAI:mainfrom
linhqm:litellm_messages_openai_field_mapping
Nov 25, 2026
Merged

mateo-berri merged 26 commits into
BerriAI:mainfrom
linhqm:litellm_messages_openai_field_mapping

Conversation

@linhqm

@linhqm linhqm commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Anthropic apps calling an OpenAI model through /v1/messages silently lost settings like turning off parallel tool calls, fast mode, web search filters and 1h caching, and MCP servers were refused. Each now turns into the matching OpenAI setting, and one OpenAI has nothing for gets a clear 400 unless the admin turned on dropping unsupported params

Details

TLDR

Problem this solves:

  • On /v1/messages to OpenAI models, disable_parallel_tool_use, speed, web search filters and location, and 1h cache marks did nothing, mcp_servers answered 400, and container answered 200 as if it ran

How it solves it:

  • each turns into its Responses API setting, as Decisions lists
  • fields OpenAI has nothing for answer 400 unless dropped by drop_params or additional_drop_params
  • an MCP server's token shows as REDACTED in proxy logs and logged model parameters
  • guardrails also read MCP tool calls and results, except in a streamed reply
  • a json_schema OpenAI's strict mode would reject goes to OpenAI with strict: false

Intentional product change: container, top_k, inference_geo and code execution allowed_callers now answer 400 instead of being ignored, 1h cache marks write OpenAI's 12h cache at 2x, and key allowlists, tool policies and content guardrails now act on MCP on any model

User Flow

Before: an Anthropic SDK app on an OpenAI model loses some settings silently, and its MCP servers are refused

  1. The app sends POST https://litellm-domain/v1/messages with "model": "gpt-6.2-sol", a get_weather tool and disable_parallel_tool_use: true, asking about four cities
  2. The reply has four tool_use blocks
  3. It sends mcp_servers with the DeepWiki MCP server and gets a 400

After: the same requests take effect

  1. The app sends the same request
  2. The reply has one tool_use block
  3. The mcp_servers request returns 200 with DeepWiki's answer

Decisions

Eight mapping choices and why
  1. fix(anthropic-messages): honor tool_choice.disable_parallel_tool_use on the chat and responses adapters #49512 also maps disable_parallel_tool_use on chat and Bedrock. Whichever merges second drops its duplicate Responses hunk
  2. speed: "fast" maps to service_tier: "priority", per OpenAI's fast mode docs. "standard" sends nothing, other values answer 400, and a forwarded service_tier other than "auto" wins
  3. Each MCP server becomes a Responses mcp tool with require_approval: "never", since Anthropic's connector runs tools without asking. A toolset allowlist becomes allowed_tools, and a toolset or server entry OpenAI cannot express answers 400. An mcp_call comes back as mcp_tool_use and mcp_tool_result blocks and replays as the same call, each result found by its call's id. The server token goes out as authorization, which log redaction and the logged model parameters now hide
  4. Web search with domain filters moves to web_search. max_uses becomes max_tool_calls only when web search is the only tool, and answers 400 otherwise. A model that refuses domain filters, such as gpt-4o-mini, answers OpenAI's 400, and with drop_params on the turn goes again once without them, the way an unverified organization's reasoning summary already does
  5. Strict json_schema output reuses the fix(anthropic): close strict JSON schemas on the Messages to Responses bridge #51337 helper, so $ref and default keep working, and objects with properties close as fix(anthropic): close strict JSON schemas on the Messages to Responses bridge #51337 does, even ones allowing extra keys. A schema using anything OpenAI's strict mode rejects, such as a map, a free-form object, allOf, a const with no type, a $ref beside other keywords or a uri format, goes up as is with strict: false, since OpenAI takes one strict flag per schema and answered 400 to each Before. OpenAI then does not enforce that schema. The other choices were a 400 as Before, or rewriting the schema into OpenAI's subset the way Anthropic's SDK does, which drops constraints the caller set. Like OpenAI's SDK, strict mode lists every property as required, so the model fills optional fields too, and strict: false keeps them optional
  6. A 1h cache_control mark asks for 12h, OpenAI's only TTL of an hour or more, on the Responses API only, since Chat Completions and Azure reject a breakpoint TTL. Direct /v1/responses calls get it too, since a bridge-only rule would keep their 1h marks on the 30m cache. A top-level mark goes on the last block, or on the turn before an assistant prefill since OpenAI takes no mark on assistant text, unless additional_drop_params lists cache_control
  7. The key tool allowlist and the tool policy guardrail count each mcp_servers entry by its name, the way /v1/responses counts server_label, so native Anthropic models get this too. Matching a server by its URL stays a separate feature request
  8. Guardrails read mcp_tool_use input and mcp_tool_result text the way they read tool_use and tool_result, on any model, and a mask goes back into the block it came from. Streamed replies are not scanned yet, see Caveats

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Last updated: 6134a53. All 70 request cases ran again there against merge base 34d39fa, and unit tests, make check and code-quality pass

What each later commit re-ran

The A/B below ran on c7b29fe, with Before at its merge base 3e9c97e. f5f1806 hides MCP server tokens in logged model parameters, and 9194d39 only marks container read-only. 49bd187 sends open schemas non-strict, runs guardrails over MCP blocks and keeps the log pattern for a quoted authorization key off other key names. So the schema, guardrail, mask and container cases and the callback canary ran again at 49bd187 against the merge base, and the new redaction unit tests fail without the change. The other cases carry, since they send no open schema and no MCP block with a blocked word, and the clean MCP replays and the canary's MCP calls answer 200 at 49bd187. Adapter and guardrail unit tests, make check and code-quality pass at 49bd187. 640 affected test files fail only on 4 flakes and 2 tests the merge base also fails, and the guardrail handler's 1449 tests pass after its last edit. 1761d9a finds each replayed MCP result by its call's id anywhere in the assistant turn and puts a top-level cache mark on the turn before an assistant prefill, so the split replay and prefill cache cases ran at 1761d9a against 49bd187 and the merge base. At 1761d9a, the 59725 affected tests fail only on 21 flakes that pass when rerun alone and on 32 tests the merge base also fails, 31 of them Rust S3 logging tests that a follow-up tracks. pytest's workers crashed once on the loaded test host, so the tests after the crash ran again on their own. b021dfa keeps only a whole null, None, true or false authorization value out of redaction, so a token that merely starts with one is redacted too. With plain and JSON debug logs on, a canary token of that shape was logged once at 1761d9a and 0 times at b021dfa, and the Python and Rust redaction tests pass with the new cases (script, output). 92f11f3 sends a json_schema with strict: false when OpenAI's strict mode would reject any part of it, so the schema cases ran at 92f11f3 against 25b010e, whose Messages to Responses adapter matches the merge base, and the Anthropic unit tests pass. 42dfd3a merges main, which changed this PR's bridge files to add deferred tool support, and 6134a53 sends a web search again without its domain filters when OpenAI refuses them under drop_params. So all 70 request cases ran again at 6134a53 against the new merge base 34d39fa, each answering as at its last run, plus the domain filter cases on gpt-4o-mini and native MCP turns with deferred tools (table). The merge changed no logging or redaction code, so the callback canary and debug log cases carry, and the three new drop_params filter tests fail without the fix

Both legs sent the same requests through the Anthropic Python SDK to real OpenAI, Gemini and Anthropic models, with every request and reply in the gist

Setup, the same on both legs

Each leg booted its own tree on one box with its own Postgres database and 2 workers, on a free port. Env var names are OPENAI_API_KEY, GEMINI_API_KEY, LITELLM_MASTER_KEY, DATABASE_URL, OPENAI_BASE_URL, LITELLM_LOCAL_MODEL_COST_MAP=True and PYTHON_DOTENV_DISABLED=1. OPENAI_BASE_URL points at a small recorder that logs each request and forwards it unchanged to https://api.openai.com/v1, which is where the "OpenAI got" lines come from

cd <tree at the leg's commit>
python litellm/proxy/proxy_cli.py --config config.yaml --host 127.0.0.1 --port <port> --num_workers 2 --timeout_worker_healthcheck 60 --telemetry False --use_prisma_db_push

config.yaml

model_list:
  - model_name: gpt-6.2-sol
    litellm_params:
      model: openai/gpt-6.2-sol
  - model_name: gpt-6.2-sol-drop
    litellm_params:
      model: openai/gpt-6.2-sol
      drop_params: true
  - model_name: gpt-4.1
    litellm_params:
      model: openai/gpt-4.1
  - model_name: gemini-flash
    litellm_params:
      model: gemini/gemini-3.8-flash
  - model_name: gpt-6.2-sol-adp
    litellm_params:
      model: openai/gpt-6.2-sol
      additional_drop_params: ["container", "speed"]
  - model_name: claude-haiku
    litellm_params:
      model: anthropic/claude-haiku-5-5

Client code, anthropic 0.84.0. A case that sets mcp_servers, container or speed goes through client.beta.messages with the matching beta header, as its step says. The full script is sdk_leg.py

import anthropic

client = anthropic.Anthropic(base_url="http://127.0.0.1:<port>", api_key=LITELLM_MASTER_KEY, max_retries=0)
message = client.messages.create(**case)
with client.messages.stream(**case) as s:
    message = s.get_final_message()

The cache cases ran on a second pair of proxies with no recorder and no database, since LiteLLM sends cache marks only to OpenAI's own host. Their config.yaml has only the gpt-6.2-sol entry above with api_key: os.environ/OPENAI_API_KEY, started with litellm --config config.yaml --port <port> --num_workers 2. Each call sends a system prompt of about 6,000 tokens marked cache_control: {"type": "ephemeral", "ttl": "1h"}, salted per leg. At t0 it sends one /v1/messages call with the mark on the system block, one with a top-level cache_control, one /v1/responses call and one /v1/chat/completions call through the openai SDK with the mark on the system item. The top-level call repeats at +20 s. A three-turn /v1/messages chat adds a plain mark on each newest user message and resends the history every turn, with turn 2 at +20 s and turn 3 at 65 minutes. The four single calls repeat at 65 minutes too, past the 30m default. The script is sdk_cache.py, and its output is cache-progress.txt

Case Before After
disable_parallel_tool_use, 4 cities 4 tool calls 1 tool call, parallel_tool_calls: false
speed fast 200 service_tier: priority
speed fast, service_tier auto service_tier: auto service_tier: priority
mcp_servers 400 200, MCP answer
mcp_toolset 400 200, MCP answer
mcp_toolset with a disabled tool 400 200, allowed_tools sent
mcp_servers, drop_params model 200, no MCP 200, MCP answer
web_search user_location asks for the city user_location sent, SF forecast
container skills 200 400
container id 200 400
top_k 200 400
inference_geo 200 400
16 cases that answer the same on both legs
Case Before After
No parallel flag, 4 cities 200 4 tool calls 200 4 tool calls
stop_sequences 400 unsupported param 400 unsupported param
Strict schema on gpt-4.1 (chat bridge) 200 text (stop ['ZZZ']) 200 text (stop ['ZZZ'])
Strict tool 200 text (strict) 200 text (strict)
Strict tool, every field required 200 text (strict) 200 text (strict)
No speed 200 text 200 text
mcp_toolset naming no server 400 unsupported param 400 unsupported param
web_search allowed_domains 200 text 200 text
container skills, drop_params model 200 text 200 text
container id, drop_params model 200 text 200 text
top_k, drop_params model 200 text 200 text
inference_geo, drop_params model 200 text 200 text
Schema with a root $ref 200 text (strict) 200 text (strict)
Root $ref on Gemini 200 text (nothing sent) 200 text (nothing sent)
Map fields on Gemini 200 text (nothing sent) 200 text (nothing sent)
Malformed mcp_servers entry 400 unsupported param 400 unsupported param

A 1h cache mark now asks OpenAI for 12h, so the first write costs about 2x and a call 65 minutes later still hits

Cache cases
Case Before After
/v1/responses 1h mark, write TTL 30m, 6876 tokens 12h, 6866 tokens
/v1/responses first call cost $0.0172 $0.0344
/v1/messages 1h mark, first call cost $0.0173 $0.0344
/v1/messages top-level mark, first call cost $0.0172 $0.0344
Top-level mark again at +20 s hit, 6872 cached hit, 6872 cached
/v1/chat/completions 1h mark, first call cost $0.0168 $0.0168
3-turn chat, turn 2 at +20 s hit, 6884 cached hit, 6884 cached
/v1/messages 1h mark again at 65 min miss hit, 6866 cached
/v1/responses 1h mark again at 65 min miss hit, 6866 cached
/v1/chat/completions 1h mark again at 65 min miss miss
3-turn chat, turn 3 at 65 min miss hit, 6866 cached
Top-level mark, first call cost $0.0195, 7777 tokens $0.0390, 7777 tokens
Same, deployment drops cache_control $0.0209, 8320 tokens $0.0209, 8320 tokens
Top-level 1h mark with a prefill, mark sent none 12h on the user turn
Same, first call 200 200, 6014 written

The prefill rows ran at 1761d9a, and Before is 49bd187 and the merge base, which send no mark (script, output)

`model_parameters` now shows the MCP token as REDACTED, and an MCP turn replays

With debug logs on, a canary MCP token was logged 0 times on both legs, and After logged 'REDACTED' (Before, After)

A logging callback reads model_parameters from the standard logging payload, and there the token used to show up in plain text. Before put it there for a native Anthropic call, c7b29fe also put it there for both OpenAI calls, and f5f1806 shows it 0 times, with the proxy log and spend logs at 0 on every leg (script, Before, c7b29fe1160, After)

A second turn that sends the first turn's mcp_tool_use and mcp_tool_result blocks back answers 200 plain and streaming on After, and OpenAI gets the matching mcp_call item in input. Before answers 400 on both (script, Before, After)

When the first turn called two MCP tools and the replay sends both uses before either result or puts text between a use and its result, 49bd187 sent those mcp_call items with no output. 1761d9a sends both outputs in both orders, and count_tokens still answers 400 on these blocks before any OpenAI call (script, output)

The tool allowlist and the tool policy guardrail now count each mcp_servers entry by its name on any model

Allowlist cases

Each key came from /key/generate with the metadata.allowed_tools named below (script, Before, After)

Request Before After
deepwiki on gpt-6.2-sol, key allows lookup 400 invalid_request_error 403 permission_error
deepwiki on gpt-6.2-sol, key allows lookup and deepwiki 400 invalid_request_error 200, called deepwiki
deepwiki on claude-haiku, key allows lookup 200, called deepwiki 403 permission_error
deepwiki on claude-haiku, key allows lookup and deepwiki 200, called deepwiki 200, called deepwiki
tools lookup on claude-haiku, key allows lookup 200 200
Tool policy cases

Each policy was set with POST /v1/tool/policy and given 25 s to sync (script, Before, After, claude-haiku Before, claude-haiku After)

Request Before After
deepwiki blocked, gpt-6.2-sol mcp_servers deepwiki 400 mcp_servers unsupported 400 Violated tool policy, OpenAI never called
deepwiki blocked, gpt-6.2-sol mcp_servers docs 400 mcp_servers unsupported 200, called docs
deepwiki blocked, claude-haiku mcp_servers and mcp_toolset deepwiki 200, called deepwiki 400 Violated tool policy
deepwiki untrusted, same claude-haiku request 200, called deepwiki 200, called deepwiki
deepwiki blocked, /v1/responses mcp tool deepwiki 400 Violated tool policy 400 Violated tool policy
deepwiki blocked for one key, that key 400 mcp_servers unsupported 400 Violated tool policy
deepwiki blocked for one key, another key 400 mcp_servers unsupported 200, called deepwiki

A json_schema OpenAI's strict mode rejects answers 200 where Before answered 400 (wire summary)

Schema cases
Schema Before After
closed object 200, strict: true 200, strict: true
map and free-form fields 400, strict: true 200, strict: false
free-form field 400, strict: true 200, strict: false
allOf with a $ref 400, strict: true 200, strict: false
const with no type 400, strict: true 200, strict: false
$ref with a description 400, strict: true 200, strict: false
uri format 400, strict: true 200, strict: false
SDK messages.parse with HttpUrl 400, strict: true 200, strict: false
enum and date-time 200, strict: true 200, strict: true
root $ref 200, strict: true 200, strict: true

Each ran plain and streaming with the same result, and strict is what OpenAI received. The replies are closed Before, closed After, map Before, map After, free-form Before and free-form After, with the streaming ones beside them in the gist

The rows from allOf down ran at 92f11f3 against 25b010e, with the replies in their gist, for example uri Before and uri After. count_tokens on the allOf and uri schemas also answers 200 where Before answered 400 (script, output). OpenAI does not enforce a non-strict schema, and the allOf reply came back with owner as a string (After)

Content guardrails now block and mask words inside MCP blocks (guardrail wire diff, mask wire summary)

Guardrail cases

These guardrails were added to the same config.yaml, and each request turns one on with "guardrails": ["<name>"] in its body

guardrails:
  - guardrail_name: mcp_word_in
    litellm_params:
      guardrail: litellm_content_filter
      mode: pre_call
      blocked_words:
        - keyword: POISONWORD
          action: BLOCK
  - guardrail_name: mcp_word_out
    litellm_params:
      guardrail: litellm_content_filter
      mode: post_call
      blocked_words:
        - keyword: Cookbook
          action: BLOCK
  - guardrail_name: mcp_mask_in
    litellm_params:
      guardrail: litellm_content_filter
      mode: pre_call
      blocked_words:
        - keyword: POISONWORD
          action: MASK
  - guardrail_name: mcp_mask_out
    litellm_params:
      guardrail: litellm_content_filter
      mode: post_call
      blocked_words:
        - keyword: Cookbook
          action: MASK

claude-haiku goes straight to Anthropic and gpt-6.2-sol goes to OpenAI through the recorder. "blocked" is the guardrail's 400 Content blocked: keyword ... detected, and on gpt-6.2-sol Before answered 400 on every row, blocked on the user text row and mcp_servers unsupported on the rest

Request Guardrail haiku Before haiku After gpt After
POISONWORD in a replayed mcp_tool_result block 200 blocked blocked
POISONWORD in a replayed mcp_tool_use block 200 blocked blocked
same replay, streamed block 200 blocked blocked
POISONWORD in user text block blocked blocked blocked
Cookbook in the reply's mcp_tool_result block 200 blocked blocked
same reply, streamed block 200 200, not scanned 200, not scanned
clean replay block 200 200 200
clean replay none 200 200 200
POISONWORD in a replayed mcp_tool_result mask 200 200 200, OpenAI got [KEYWORD_REDACTED]
Cookbook in the reply's mcp_tool_result mask 200, Cookbook shown [KEYWORD_REDACTED] [KEYWORD_REDACTED]

A blocked request never reached OpenAI, and a blocked reply came after one OpenAI call. Each request is r10-cell-<case>.json in the gist and its replies are r10-base-<case>.txt and r10-head-<case>.txt, for example request, Before and After for the first row on gpt-6.2-sol

Tool cache marks and web search filters, checked on the wire

A cache_control mark on a tool now reaches OpenAI as that tool's prompt_cache_breakpoint, plain and streaming, where Before sent the tool with no mark, and a 1h TTL on it goes out as 12h like a message mark. All six calls answered 200. These ran at 49bd187 and 3e9c97e against api.openai.com, reading each proxy's own outbound body (outbound bodies, tool mark request, 1h request). Web search with blocked_domains and max_uses goes out on After as web_search with filters.blocked_domains and max_tool_calls, where Before sent a bare web_search_preview (wire diff, web search request, web search Before, web search After)

/live-pr-risk at 6134a53, no breaking change left

The A/B ran at c7b29fe against its merge base 3e9c97e. The callback canary and the MCP replay ran again at f5f1806, and the schema, guardrail and mask cases and the canary ran again at 49bd187 against the merge base. The split MCP replay, prefill cache and count_tokens cases ran again at 1761d9a, and the debug log redaction case at b021dfa. The new schema cases and count_tokens ran at 92f11f3. The integration suites ran with f5f1806 in the tree. Every group passed except 32 MCP e2e cases, whose helper imports an mcp 1.x module and errors the same way at the merge base, and one Vertex Gemma case that timed out under load and passed alone at 9194d39 and the merge base. The callers of 49bd187's new helpers were walked again, see the graph below. At 6134a53, after main's merge, all 70 request cases ran again against merge base 34d39fa and each answered as at its last run, and the merge touched no logging or redaction code

Breaking

  • At c7b29fe logged model_parameters showed an OpenAI call's MCP server token in plain text, and Before already did for a native Anthropic call. Fixed in f5f1806, so the canary counts 0 in model_parameters there and at 49bd187

Backward incompatible

  • On OpenAI models container, top_k, inference_geo, a code execution allowed_callers and a malformed mcp_servers entry answer 400 where they answered 200 and did nothing. Under drop_params an mcp_servers entry now goes upstream instead of being dropped. This follows litellm's drop_params convention, and the drop_params legs show the 200. Kept in Caveats for Mateo's review
  • speed: "fast" now asks for OpenAI's priority tier, and a 1h cache mark now writes the 12h cache, each billed about 2x. Both are the mapping this PR was asked for, kept in Caveats
  • A web search with domain filters on a model that refuses them, such as gpt-4o-mini, answers OpenAI's 400, where Before searched without them. Under drop_params it goes again without them, per litellm's convention, kept in Caveats
  • A key whose allowed_tools leaves out an mcp_servers entry, a tool policy that blocks one, or a content guardrail whose word shows up in an MCP block now refuses the request on any model, native Anthropic included, where Before let it through. This closes gaps in the allowlist and the guardrails, kept in Caveats for Mateo's review

Regression risk

  • A pre-existing gap went to security engineering
  • A streamed reply's MCP blocks skip guardrails on both models, as they did Before on native Anthropic. A follow-up tracks it

Dependency graph

  • extract_request_tool_names feeds the key allowlist and the tool policy guardrail, both verified live above
  • get_standard_logging_model_parameters feeds every callback's model_parameters, verified live by the canary. Its readers that take tool names only are tested or read no credential field
  • The Responses adapter and its streaming iterator serve /v1/messages on OpenAI models, verified live by the 28 cases plain and streaming
  • fits_openai_strict_mode decides strict for the adapter's json_schema output and has one caller, _text_format, which serves /v1/messages and its count_tokens on OpenAI models, both verified live at 92f11f3 and tested. openai_strict_json_schema keeps its behavior for the chat adapter, since _includes_type makes the same object check as the helper it replaces
  • openai/responses/transformation.py and the cache breakpoint helper serve direct /v1/responses too, verified live by the cache cases
  • The guardrail handler's MCP block readers and mask write-back serve every content guardrail on /v1/messages, native Anthropic included, verified live by the guardrail and mask cases on both models and tested
  • The Python and Rust log redaction, verified live with debug and JSON logs on, and the narrowed authorization pattern is tested in both. b021dfa's whole-value exception only redacts more, and every redact_string caller gets it, which the live debug log case covers
  • The native Anthropic handler and the guardrail tool name helpers, verified live on claude-haiku and tested
  • 1761d9a's _assistant_blocks_to_input_items and _with_automatic_cache_mark each have one caller in the adapter, verified live by the split replay and prefill cases and tested
  • 6134a53's refused field retry wraps every Responses call the adapter makes, verified live by the filter cases plain and streaming and tested, and the summary retry it generalizes keeps its tests
  • count_tokens on OpenAI models answers 400 on MCP blocks and ignores mcp_servers on both legs, a pre-existing gap

Not verified

  • Third-party logging vendors read back through their own APIs, since this rig has no account for them

Before (3e9c97e)

disable_parallel_tool_use, 4 cities

  1. Send m1_parallel.json with client.messages, plain and streaming
m1_parallel.json
{"model": "gpt-6.2-sol", "max_tokens": 1024, "tool_choice": {"type": "auto", "disable_parallel_tool_use": true}, "tools": [{"name": "get_weather", "description": "Get the current weather for one city", "input_schema": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}], "messages": [{"role": "user", "content": "What is the weather right now in Paris, Tokyo, Lima and Cairo? Call the tool for every city."}]}
  1. 200 with {"stop_reason": "tool_use", "tool_use": 4, "cost": "0.000912"}, and streaming gave the same status. OpenAI got {"tool_choice": "auto", "tools": [{"type": "function", "name": "get_weather", "strict": false}]}. Raw output, the stream run beside it

The other 27 Before cases are in cases-before-3e9c97e1d2b.md

After (c7b29fe)

disable_parallel_tool_use, 4 cities

  1. Send m1_parallel.json the same way as Before

  2. 200 with {"stop_reason": "tool_use", "tool_use": 1, "cost": "0.000468"}, and streaming gave the same status. OpenAI got {"parallel_tool_calls": false, "tool_choice": "auto", "tools": [{"type": "function", "name": "get_weather", "strict": false}]}. Raw output, the stream run beside it

27 more cases
No parallel flag, 4 cities (200)
  1. Send m1_no_flag.json the same way as Before

  2. 200 with {"stop_reason": "tool_use", "tool_use": 4, "cost": "0.000912"}, and streaming gave the same status. OpenAI got {"tool_choice": "auto", "tools": [{"type": "function", "name": "get_weather", "strict": false}]}. Raw output is in the gist, the stream run beside it

stop_sequences (400)
  1. Send m0_stop_sequences.json the same way as Before

  2. 400 with openai does not support parameters: ['stop'], for model=gpt-6.2-sol. To drop these, set 'litellm.drop_params=True' or for proxy:\n\n'litellm_settings:\n drop_params: true'\n. \n If you want ..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

Strict schema on gpt-4.1 (chat bridge) (200)
  1. Send h1_chat_bridge_strict.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000176"}, text {"city":"Paris","country":"France"}, and streaming gave the same status. OpenAI got {"stop": ["ZZZ"], "response_format": {"type": "json_schema", "json_schema": {"name": "structured_output", "schema": {"type": "object", "properties": {"city": {"type": "string"}, "country": {"type": "string", "default": "FR"}}, "required": ["city", "country"], "additionalProperties": false}, "strict".... Raw output is in the gist, the stream run beside it

Strict tool (200)
  1. Send m2_strict.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000366"}, text {"color":"blue","note":"Purple is not an allowed color."}, and streaming gave the same status. OpenAI got {"text.format.strict": true}. Raw output is in the gist, the stream run beside it

Strict tool, every field required (200)
  1. Send m2b_strict_required.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000304"}, text {"answer":"yes","confidence":1}, and streaming gave the same status. OpenAI got {"text.format.strict": true}. Raw output is in the gist, the stream run beside it

speed fast (200)
  1. Send m3_speed_fast.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.00014800000000000002"}, text Hi, and streaming gave the same status. OpenAI got {"service_tier": "priority"}. Raw output is in the gist, the stream run beside it

No speed (200)
  1. Send m3_speed_none.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "7.400000000000001e-05"}, text Hi, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

speed fast, service_tier auto (200)
  1. Send m3c_speed_fast_auto.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.00014800000000000002"}, text Hi, and streaming gave the same status. OpenAI got {"service_tier": "priority"}. Raw output is in the gist, the stream run beside it

mcp_servers (200)
  1. Send m4_mcp_servers.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["mcp_tool_use", "mcp_tool_result", "text"], "cost": "0.00335"}, text The first three top-level topics in DeepWiki for BerriAI/li..., and streaming gave the same status. OpenAI got {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "require_approval": "never"}]}`. Raw output is in the gist, the stream run beside it

mcp_toolset (200)
  1. Send m5_mcp_toolset.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["mcp_tool_use", "mcp_tool_result", "text"], "cost": "0.003104"}, text The first three top-level DeepWiki topics for BerriAI/litel..., and streaming gave the same status. 2 upstream calls, the first sent {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "allowed_tools": ["read_wiki_structure"], "require_approval": "never"}]}`. Raw output is in the gist, the stream run beside it

mcp_toolset with a disabled tool (200)
  1. Send m5b_mcp_toolset_blocked_tool.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000484"}, text ASK_QUESTION_UNAVAILABLE, and streaming gave the same status. OpenAI got {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "allowed_tools": ["read_wiki_structure"], "require_approval": "never"}]}. Raw output is in the gist, the stream run beside it

mcp_toolset naming no server (400)
  1. Send m5c_orphan_toolset.json the same way as Before

  2. 400 with openai/gpt-6.2-sol is served through the OpenAI Responses API, which has no equivalent for mcp_toolset 'github' without a matching mcp_servers entry. To drop it, set 'litellm.drop_params=Tru..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

mcp_servers, drop_params model (200)
  1. Send m5d_orphan_toolset_drop.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["mcp_tool_use", "mcp_tool_result", "text"], "cost": "0.00335"}, text The first three top-level topics in DeepWiki for BerriAI/li..., and streaming gave the same status. OpenAI got {"tools": [{"type": "mcp", "server_label": "deepwiki", "server_url": "https://mcp.deepwiki.com/mcp", "require_approval": "never"}]}`. Raw output is in the gist, the stream run beside it

web_search allowed_domains (200)
  1. Send m6_websearch_domains.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.030275000000000003"}, text LiteLLM is an open-source Python SDK and self-hosted AI gate..., and streaming gave the same status. OpenAI got {"tools": [{"type": "web_search", "filters": {"allowed_domains": ["docs.litellm.ai"]}}]}. Raw output is in the gist, the stream run beside it

web_search user_location (200)
  1. Send m6b_websearch_location.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.032029999999999996"}, text San Francisco, California — Today, **Wednesday, November 25*..., and streaming gave the same status. OpenAI got {"tools": [{"type": "web_search_preview", "user_location": {"type": "approximate", "city": "San Francisco", "region": "California", "country": "US", "timezone": "America/Los_Angeles"}}]}. Raw output is in the gist, the stream run beside it

container skills (400)
  1. Send m7_container_callers.json the same way as Before

  2. 400 with openai/gpt-6.2-sol is served through the OpenAI Responses API, which has no equivalent for allowed_callers on tool 'get_weather'; container. To drop them, set 'litellm.drop_params=True', or ..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

container skills, drop_params model (200)
  1. Send m7b_container_callers_drop.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000156"}, text Hi!, and streaming gave the same status. OpenAI got {"tools": [{"type": "function", "name": "get_weather", "strict": false}]}. Raw output is in the gist, the stream run beside it

container id (400)
  1. Send r2_container_id.json the same way as Before

  2. 400 with openai/gpt-6.2-sol is served through the OpenAI Responses API, which has no equivalent for container. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' in the model's 'litel..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

container id, drop_params model (200)
  1. Send r2b_container_id_drop.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "8.400000000000001e-05"}, text Hi!, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

top_k (400)
  1. Send m8_top_k.json the same way as Before

  2. 400 with openai/gpt-6.2-sol is served through the OpenAI Responses API, which has no equivalent for top_k. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' in the model's 'litellm_p..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

top_k, drop_params model (200)
  1. Send m8b_top_k_drop.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "7.8e-05"}, text Red, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

inference_geo (400)
  1. Send m9_inference_geo.json the same way as Before

  2. 400 with openai/gpt-6.2-sol is served through the OpenAI Responses API, which has no equivalent for inference_geo. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' in the model's 'l..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

inference_geo, drop_params model (200)
  1. Send m9b_inference_geo_drop.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "7.8e-05"}, text Red, and streaming gave the same status. OpenAI got none of the case's fields. Raw output is in the gist, the stream run beside it

Schema with a root $ref (200)
  1. Send r1_root_ref.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000312"}, text {"name":"Ada","age":36}, and streaming gave the same status. OpenAI got {"text.format.strict": true}. Raw output is in the gist, the stream run beside it

Root $ref on Gemini (200)
  1. Send r1g_root_ref_gemini.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.000942"}, text {"name":"Ada","age":36}, and streaming gave the same status. nothing reached OpenAI. Raw output is in the gist, the stream run beside it

Map fields on Gemini (200)
  1. Send r3_maps_gemini.json the same way as Before

  2. 200 with {"stop_reason": "end_turn", "block_types": ["text"], "cost": "0.0009165"}, text {"name":"Ada","metadata":{},"tags":{"color":"blue"}}, and streaming gave the same status. nothing reached OpenAI. Raw output is in the gist, the stream run beside it

Malformed mcp_servers entry (400)
  1. Send r4_mcp_malformed.json the same way as Before

  2. 400 with openai/gpt-6.2-sol is served through the OpenAI Responses API, which has no equivalent for a malformed mcp_servers entry. To drop it, set 'litellm.drop_params=True', or 'drop_params: true' i..., and streaming gave the same status. Raw output is in the gist, the stream run beside it

Direct calls to OpenAI's Responses API in its documented shape, from round 1

Each is one curl with the same prompt, and every body sent and raw response is in the gist: Parallel off, No flag (control), speed: fast, mcp_servers, Domain filter, user_location and 3-turn chat. The speed: fast cost is the reply's token counts at the model's priority price

The 3-turn chat sends the system prompt as a developer item marked prompt_cache_breakpoint: {"mode": "explicit", "ttl": "12h"} and each newest user item marked {"mode": "explicit"}, resending the history every turn with the same gaps as the proxy legs

curl -sS -D - https://api.openai.com/v1/responses -H "Authorization: Bearer $OPENAI_API_KEY" -H "content-type: application/json" --data @direct_<case>.json

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • speed: "fast" asks for OpenAI's priority tier, billed about 2x, unless additional_drop_params lists speed
  • A 1h cache mark asks for 12h, whose writes cost about 2x, on direct /v1/responses calls too
  • container, top_k, inference_geo and refused domain filters answer 400 unless dropped, and drop_params now keeps mcp_servers, which a custom openai/ host may reject
  • allowed_callers with a code execution caller answers 400, and a follow-up tracks it
  • Key allowlists, tool policies and content guardrails now act on MCP on any model, by server name only, so native Anthropic requests can get 403 or 400
  • Streamed MCP blocks skip guardrails, as on native Anthropic Before, and a follow-up tracks it
  • Strict mode requires optional schema fields, and a schema it rejects goes unenforced, see Decision 5
  • Shadow eval now replays a logged tool's headers as REDACTED
  • A pre-existing gap went to security engineering

Low

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
Bugbot summary

[!NOTE]
Medium Risk
Broad changes to the Anthropic→Responses bridge affect request shaping, billing (priority tier and 12h cache), and new 400 behavior for formerly ignored params; credential redaction and guardrail coverage reduce logging/security risk but alter production semantics for MCP and allowlists.

Overview
Anthropic /v1/messages → OpenAI Responses now translates or rejects settings that were previously dropped or mishandled: disable_parallel_tool_use → parallel_tool_calls, speed: fast → service_tier: priority, web search domain filters and max_uses, MCP mcp_servers / mcp_toolset → Responses mcp tools (with allowlists and clear 400s for unmapped toolset config). Fields with no Responses equivalent (container, top_k, inference_geo, etc.) raise UnsupportedParamsError unless drop_params / additional_drop_params strips them; refused reasoning.summary and web search filters retry once under drop_params.

Caching maps Anthropic cache_control to prompt_cache_breakpoint, including 1h → 12h TTL on OpenAI Responses (not Chat Completions/Azure), top-level cache_control on the last cacheable block (before assistant prefills), and marks on tools.

MCP end-to-end: bidirectional mcp_call ↔ mcp_tool_use / mcp_tool_result in the adapter, streaming iterator, and message replay; guardrails scan MCP blocks like other tool content.

Security / logging: redact authorization, authorization_token, and headers on tools / mcp_servers in standard model-parameter logging and in Python/Rust log redaction (including quoted authorization keys).

Structured output: json_schema is sent strict only when the schema fits OpenAI strict mode; otherwise strict: false to avoid upstream 400s.

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

…ents or reject them

The Responses bridge for /v1/messages dropped several Anthropic fields and still answered 200. disable_parallel_tool_use now sets parallel_tool_calls false, speed fast asks for the priority service tier, mcp_servers become Responses mcp tools with their toolset allowlist, web_search keeps its domain filters, user_location, and max_uses, a json_schema output format goes up strict, and a 1h cache_control mark asks OpenAI for its 12h breakpoint TTL

A field with no Responses equivalent (container, allowed_callers, an unknown speed, a toolset denylist, defer_loading, max_uses next to another built-in tool) answers 400 UnsupportedParamsError naming every such field, and drop_params drops them instead

strict_json_schema moves to base_utils so the Codex harness, the chat-completions bridge, and the Responses bridge share one walker, which now leaves property names and enum, const, and examples values alone
…ai_field_mapping

# Conflicts:
#	litellm/litellm_core_utils/prompt_templates/common_utils.py
#	litellm/llms/anthropic/messages/responses_adapters/handler.py
#	litellm/llms/base_llm/base_utils.py
#	litellm/llms/openai/responses/transformation.py
#	tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_common_utils.py
…ai_field_mapping

Keep mcp_servers mapped to Responses mcp tools over the bridge 400, keep the strict schema walk over the raw schema, and send the 12h breakpoint ttl to OpenAI only
…ai_field_mapping

# Conflicts:
#	litellm/llms/anthropic/messages/adapters/transformation.py
#	litellm/llms/anthropic/messages/responses_adapters/handler.py
#	litellm/llms/anthropic/messages/responses_adapters/transformation.py
#	tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_transformation.py
#	tests/unit/llms/openai/responses/count_tokens/test_token_counter.py
…r 400 for a container id

The bridge goes back to the strict-schema helper from BerriAI#51337, so a root $ref keeps its $defs and a map keeps its
value schema on every provider. A container id string and a malformed mcp_servers entry now answer 400, or are
dropped under drop_params, instead of a 500
…ai_field_mapping

# Conflicts:
#	litellm/llms/anthropic/messages/responses_adapters/handler.py
#	litellm/llms/anthropic/messages/responses_adapters/transformation.py
#	tests/unit/llms/anthropic/messages/responses_adapters/test_responses_adapters_transformation.py
…ai_field_mapping

# Conflicts:
#	litellm/llms/anthropic/messages/responses_adapters/handler.py
@veria-ai

veria-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

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

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

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] No new blocking code issue was established.

Summary

The PR maps Anthropic Messages settings to OpenAI Responses fields and rejects settings without an equivalent.

  • Anthropic message settings reach matching OpenAI Responses fields.
  • Anthropic MCP servers run as OpenAI tools and their calls replay as MCP blocks.
  • One-hour cache marks ask OpenAI Responses for a twelve-hour cache.
  • JSON schemas OpenAI strict mode cannot accept are sent without strict mode.
  • MCP server names and blocks now reach policy and guardrail checks, and credentials are redacted.

The earlier MCP-output, dropped-cache, writable-field, test-banner, and token-prefix findings are addressed in the current code. All supplied threads are unnumbered, so they receive no numbered finding entries.

linhqm documents non-strict schema fallback as intentional and streamed MCP guardrail scanning as deferred. Neither is reported again.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Anthropic Messages request] --> B[Tool-name checks and input guardrails]
  B --> C[Translate fields and MCP tools]
  C --> D{Unsupported setting?}
  D -->|Reject| E[400 response]
  D -->|Map or drop| F[OpenAI Responses]
  F --> G{Matching refusal and drop_params?}
  G -->|Yes| H[Remove refused field and retry]
  H --> F
  G -->|No| I[Translate reply or stream]
  I --> J[Anthropic text and MCP blocks]
Loading

Reviews (8) · Last reviewed commit: "fix(anthropic): resend a web search with..." · Reviewed by Greptile

…e OpenAI bridge and redact the MCP authorization

top_k and inference_geo have no Responses equivalent, so they now answer 400 like container unless drop_params
or additional_drop_params drops them, instead of a silent 200. An mcp_toolset that names no mcp_servers entry
answers 400 the same way. The error says to set drop_params: true in the model's litellm_params or under
litellm_settings.

A forwarded service_tier of auto no longer beats speed fast, since auto asks for nothing specific. A top-level
cache_control marks the last block of the conversation the way Anthropic caches it, and an mcp_call output comes
back as mcp_tool_use and mcp_tool_result blocks that replay on the next turn.

The server token goes out as the Responses mcp tool's authorization field, so both redactors now scrub a value
under a quoted authorization key in JSON or a Python repr. A value litellm already masked, like the Authorization
header in the JSON debug log, keeps its hint, and an Authorization header name is left alone.
…ai_field_mapping

main typed the native handler's container as dict[str, object], and this branch also takes a container id string, so
the merge keeps str | dict[str, object]. main typed thinking and tool_choice the way this branch did, which left the
speed and mcp_servers keywords two unknown arguments over the type gate, so is_async is now read as a bool.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…ai_field_mapping

# Conflicts:
#	litellm/llms/anthropic/messages/responses_adapters/handler.py
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The standard logging payload copied tools and mcp_servers into
model_parameters as sent, so an MCP server's authorization or
authorization_token reached every logging callback in plain text.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

Comment thread litellm/types/llms/anthropic.py Resolved
Mark AnthropicMessagesRequestOptionalParams.container ReadOnly and pass it when the Responses adapter builds its request instead of setting it afterwards
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…arrow the authorization log pattern

OpenAI strict structured outputs reject a map or a free-form object, so a
Messages output schema that leaves an object open now goes to the Responses
API with strict false instead of answering 400.

Guardrails on /v1/messages now read mcp_tool_use input and mcp_tool_result
text in requests and replies, and write a masked result back, the way they
already handle tool_use and tool_result. That covers replayed history too.

The quoted authorization log pattern now needs a word boundary and skips
null, None and booleans, so keys like requires_authorization log as sent.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…th null or a boolean

The exception for a literal null, None, true or false authorization value now needs the whole value to be that literal, so a token such as null-<rest> is redacted in Python and Rust
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6134a53. 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 21450cd into BerriAI:main Nov 25, 2026
67 checks passed
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.

2 participants