litellm/tests/unit/llms/anthropic
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
..
batches feat(anthropic): workload identity federation and pluggable identity sources (#44448) 2026-10-03 17:08:30 -07:00
chat fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173) 2026-11-25 19:30:01 +00:00
files chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
messages fix(anthropic): map /v1/messages fields onto OpenAI Responses equivalents or reject them (#54173) 2026-11-25 19:30:01 +00:00
pass_through refactor(anthropic): rename llms/anthropic/pass_through to llms/anthropic/messages (#48510) 2026-10-27 10:08:25 -07:00
__init__.py
anthropic_docs_refusal.py fix(anthropic): keep refusal stop_reason and stop_details on the logged response (#46104) 2026-10-14 14:42:49 -07:00
test_anthropic_common_utils.py fix(messages): answer 400 for a non-string user or system text block and keep count_tokens in step with inference (#54165) 2026-11-25 00:48:41 +00:00
test_anthropic_count_tokens_transformation.py fix(token_counter): count an Anthropic fallback block as zero on every count route (#54006) 2026-11-24 03:32:34 -08:00
test_anthropic_files_and_batches.py feat(anthropic): workload identity federation and pluggable identity sources (#44448) 2026-10-03 17:08:30 -07:00
test_anthropic_output_format_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_prompt_cache_prediction.py fix(proxy): resolve admin oidc api_key references on batch cancel, fine-tuning listing, OCR, /v1/messages and cache prediction (#53678) 2026-11-23 10:11:10 -08:00
test_anthropic_prompt_cache_pricing.py refactor(anthropic): move prompt cache pricing helper out of the proxy package (#45753) 2026-10-10 20:32:34 +00:00
test_anthropic_reasoning_effort.py fix(anthropic): disable optional default thinking for reasoning effort none (#50541) 2026-11-07 12:51:37 -08:00
test_anthropic_schema_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_structured_output.py
test_anthropic_wif.py fix(anthropic): exchange Google identity tokens again on refresh and read oidc/ references out of ANTHROPIC_IDENTITY_TOKEN (#50583) 2026-11-07 16:48:48 -08:00
test_azure_ai_cache_pricing.py
test_cost_calculation_dict_safety.py feat(anthropic): workload identity federation and pluggable identity sources (#44448) 2026-10-03 17:08:30 -07:00
test_count_tokens_oauth.py fix(count_tokens): count a history that carries a compaction block (#44784) 2026-10-30 00:11:55 -07:00
test_message_sanitization.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_messages_http_error_retry_cases.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00