litellm/tests/unit/llms/openai/responses
linhqm 21450cdefc
fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173)
* fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents 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

* fix(openai): keep the 1h cache ttl to the Responses API, since Chat Completions rejects a breakpoint ttl

* test(openai): expect the 12h breakpoint ttl a 1h cache mark now sends on the Responses wire

* refactor(anthropic): read the new /v1/messages fields through typed views

* fix(anthropic): keep schema refs and maps in strict output, and answer 400 for a container id

The bridge goes back to the strict-schema helper from #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

* fix(anthropic): leave out speed and container when additional_drop_params lists them

* fix(anthropic): reject or map the remaining /v1/messages fields on the 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.

* fix(anthropic): leave the top-level cache mark off when the deployment drops cache_control

* fix(proxy): count mcp_servers by name in the /v1/messages tool allowlist

* fix(logging): redact MCP server tokens from logged model parameters

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.

* fix(anthropic): keep the Messages container field read-only

Mark AnthropicMessagesRequestOptionalParams.container ReadOnly and pass it when the Responses adapter builds its request instead of setting it afterwards

* fix(anthropic): send open schemas non-strict, guard MCP blocks, and narrow 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.

* fix(anthropic): pair a replayed MCP result with its use by id and keep a top-level cache mark before a prefill

* fix(redaction): redact an MCP authorization value that only starts with 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

* fix(anthropic): send a structured output schema non-strict when OpenAI strict mode would reject it

* fix(anthropic): resend a web search without domain filters when OpenAI refuses them under drop_params

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 19:30:01 +00:00
..
count_tokens fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173) 2026-11-25 19:30:01 +00:00
__init__.py
test_openai_count_tokens_transformation.py fix(responses): send bridged system prompts as input messages so GPT-6.2 caches them (#52599) 2026-11-18 21:12:55 +00:00
test_openai_responses_data_residency.py feat(openai): bill gov.api.openai.com FedRAMP endpoint with 1.1x uplift (#49951) 2026-11-04 08:57:42 -08:00
test_openai_responses_guardrail_handler.py fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169) 2026-11-25 06:56:15 +00:00
test_openai_responses_guardrail_tool_merge.py fix(responses): keep sent tool names in cold storage replay and guardrail rewrites (#54240) 2026-11-25 05:41:32 +00:00
test_openai_responses_http.py fix(responses): preserve typed parts when logprobs is omitted (#48686) 2026-10-27 18:33:39 -07:00
test_openai_responses_transformation.py fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173) 2026-11-25 19:30:01 +00:00