litellm/tests/integration/translation
tavren27 b2e1ccca8d
fix(anthropic)!: keep thinking disabled, display, between_tools, and effort on /v1/messages to OpenAI (#49765)
* fix(anthropic): keep thinking disabled, display, between_tools, and effort on /v1/messages to OpenAI

The Messages to Responses bridge only built reasoning for adaptive and enabled thinking, so disabled, between_tools, and output_config.effort alone reached OpenAI as nothing, and display never asked for a summary. Disabled now maps to effort none, between_tools thinks only after tool results, effort alone maps to reasoning.effort, and display shares the chat route's summary rule

* fix(anthropic): drop an unconfirmed reasoning off switch under drop_params and read the whole final user turn

between_tools now treats every user message after the last assistant message as the final turn, so a
tool_result followed by a separate text message still counts as between tool calls, and it asks for a
reasoning summary there the way Anthropic returns progress updates.

thinking disabled or a first-turn between_tools on a reasoning model whose cost map row does not set
supports_none_reasoning_effort (o3, o4-mini) no longer sends effort none under drop_params, which
OpenAI refused with a 400.

* fix(anthropic): keep reasoning off for a bare effort on models that reason only when asked

A request with output_config.effort and no thinking now leaves reasoning
off on a model whose cost map row sets default_reasoning_effort none
(gpt-5.1, gpt-5.2, the gpt-5.4 family). Turning it on there made Claude
Code with thinking off pay for reasoning, and made a temperature the
model accepts at none answer 400. Models that reason by default still
get the effort.

between_tools now honors thinking.summary and display omitted before
falling back to summary auto, and the new helpers lose their docstrings.

* fix(anthropic): let a bare effort yield to reasoning_effort and unmapped models, drop an undefined effort under drop_params

* fix(anthropic): retry an unverified org without the reasoning summary, keep disabled reasoning off at the lowest tier, and match between_tools on the chat route

Under drop_params, the Responses bridge now retries once without reasoning.summary when OpenAI refuses summaries to an unverified organization. It drops an effort the model's own levels exclude unless the deployment rounds efforts itself. It sends minimal or low for disabled when the model lists no none.

The chat-completions route now maps between_tools and a bare output_config.effort for non-Claude targets the same way the bridge does, through a shared tool-turn check

* fix(anthropic): limit the chat route's between_tools and bare effort mapping to OpenAI, keep reasoning off at the lowest level the model takes, and ignore a bare effort on a model that cannot reason

* fix(anthropic): drop an unconfirmed reasoning off switch under drop_params on the OpenAI chat route too, through one helper both routes share

* fix(anthropic): keep sending reasoning_effort none on the chat route to an openai/ deployment the cost map does not list

The router registers an unlisted deployment as a stub row with no mode, which made its reasoning levels read as known-empty, so thinking disabled stopped sending none on the chat-completions route. The levels now read as unknown for such a row. The Responses bridge keeps sending no reasoning there, since the Responses transformation answers 400 to reasoning.effort on a row without supports_reasoning.

* fix(anthropic): send reasoning effort none wherever the Responses transformation accepts it

An openai/ deployment the cost map does not list now gets effort none for
disabled thinking on the chat route even when its model_info sets a mode,
since the off level now asks whether the loaded cost map lists the model
instead of reading the row the router registers. On the Responses bridge
the off switch is dropped only where the Responses transformation itself
would refuse reasoning.effort, so a slash-named model it accepts gets none
again for adaptive effort none and disabled thinking.

* fix(anthropic): leave reasoning to the model on a first-turn between_tools when its levels are unlisted

A first-turn between_tools request sent reasoning effort none to every
openai/ deployment whose cost map row lists no effort levels, so a backend
that requires reasoning answered 400 where main answered 200. That turn
now sends no reasoning unless the row or the deployment's model_info lists
the model's levels. The OpenAI integration fixture now expects the summary
that display summarized asks for.

* fix(anthropic): read each deployment's own model_info for the off switch and guard a non-object thinking

* fix(anthropic): keep a client's effort none on the unsupported-value path and send minimal as the off level only where confirmed

* fix(anthropic): drop a client's unconfirmed effort none under drop_params and keep the pin out

Under drop_params, a client's own effort none, bare or adaptive or after a tool
result, on a reasoning deployment that lists no levels and does not set
supports_none_reasoning_effort (o3) is now dropped on both routes instead of
going to OpenAI, which answers 400. A client effort the bridge drops also keeps
a deployment's pinned reasoning_effort out, as the chat route and main do

* fix(anthropic): keep a pinned effort out when drop_params drops disabled

Under drop_params, disabled on a reasoning deployment that does not confirm
effort none (o3) is dropped on both routes. The deployment's pinned
reasoning_effort no longer comes back in its place, so the model answers at
its default effort instead of the pinned one the client turned off

* fix(anthropic): keep the refused summary attempt out of failure logs and drop unknown efforts on the chat route

Under drop_params the refused summary attempt is marked as sent again, so it is not logged as the turn failing and num_retries does not resend it. A name only a model-family rule matches counts as unlisted. The chat route drops an effort no reasoning API defines, and a bare effort skips a model whose chat config takes no reasoning_effort

* fix(anthropic): keep family-rule info when normalizing a client's effort

The listed-effort check now skips info that only the OpenAI reasoning family rule supplies, but effort normalization still reads it, so a name only that rule matches normalizes its effort as before. Adds a test for a summary refused while replayed reasoning is resent.

* refactor(anthropic): move the client effort drop check into one helper and refresh dashboard API types

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-24 01:43:29 +00:00
..
chat_completions test(vertex_ai): expect the default service tier on Vertex Gemini chat responses (#53847) 2026-11-23 18:22:12 +00:00
decisions test: update stale integration and e2e expectations for intended changes (#53940) 2026-11-23 14:27:20 -08:00
messages test(translation): expect the bridged Messages system prompt as input and unsigned thinking dropped before Claude (#53243) 2026-11-20 17:58:10 -08:00
responses
templates fix(anthropic)!: keep thinking disabled, display, between_tools, and effort on /v1/messages to OpenAI (#49765) 2026-11-24 01:43:29 +00:00
__init__.py
AGENTS.md
case.py
conftest.py
gemini_thoughts.py
README.md
response_contracts.py
response_scenarios.py
runner.py
test_triton.py

Translation tests

These tests check one request through the proxy as literals on a TranslationTestCase: the litellm_endpoint and litellm_request the test sends, the expected_provider_endpoint, expected_provider_headers and expected_provider_request the fake provider must receive, the mock_provider_response it answers with, and the expected_litellm_status_code and expected_litellm_response the test must get back. The runner compares the provider request body, every provider header other than transport headers, and the LiteLLM response body in full, so an added, removed, renamed or moved field fails. Folders follow the client endpoint and then the feature, for example translation/messages/reasoning/. Each endpoint keeps one complete base case per model in <endpoint>/bases/<provider>.py, named <MODEL>_TEST_CASE (for example CLAUDE_SONNET_4_6_TEST_CASE), which <endpoint>/basic/ runs on its own. A feature case is <MODEL>_<SCENARIO>_TEST_CASE = dataclasses.replace(<MODEL>_TEST_CASE, ...), imports the base under its own name rather than as BASE, and lists only the fields it changes

Some response fields are generated by LiteLLM on every run, such as a chat completion's id and created or a response's id, created_at and output message id. A case writes those as unittest.mock.ANY, so the field must still be present but any value passes. Use ANY only for a value LiteLLM generates, never for one copied from the provider reply

Shared templates

Each client endpoint has a request and an expected response in <endpoint>/templates.py. Each upstream provider endpoint has a request and a captured response in templates/<provider>.py. All three client endpoints in the Anthropic pilot share the /v1/messages provider templates. Native Messages reuses the provider response shape. These are plain dictionaries, not builders that call production translators

The base template count is twice the number of client endpoints plus twice the total number of supported upstream endpoint formats. Models select templates and override their differing fields, rather than creating another template per model. Streaming and other distinct shapes need variants

For example, the Chat Completions Sonnet base binds four templates

litellm_request={**CHAT_COMPLETIONS_REQUEST, "model": "anthropic/claude-sonnet-5-5"},
expected_provider_request={**ANTHROPIC_MESSAGES_REQUEST, "model": "claude-sonnet-5-5"},
mock_provider_response={**ANTHROPIC_MESSAGES_RESPONSE, "model": "claude-sonnet-5-5"},
expected_litellm_response={**CHAT_COMPLETIONS_RESPONSE, "model": "anthropic/claude-sonnet-5-5"},

The shared samples come from the Sonnet 5.5 captures. Adding another model reuses the endpoint request, with small explicit overrides for unsupported features. Make a live capture with that exact request, inspect its translation, then override differing provider and client response fields in the model's case. Do not relabel the Sonnet capture as live evidence for another model. A new provider endpoint needs its own wire templates, not another client conversation

The templates omit model, so the case binds the deployment, provider model and returned model explicitly. Keep captured IDs, content, thinking signatures and usage exact. The Messages and Responses pilot cases retain their endpoint-specific capture differences. Native Messages can share unchanged content and usage between the provider and client response, while translated response fields remain independently recorded expectations

Build overrides with dictionary unpacking and new nested values, never mutate a template or its nested values. Do not compute expected translations by calling LiteLLM. When editing a shared template, review and run every case that uses it. Older bases keep their existing captures until migrated with matching live evidence

Rich capture examples

Use the Anthropic CLAUDE_SONNET_5_5_TEST_CASE bases as the rich conversation examples. They contain synthetic system instructions, multiple turns, two read-only tool definitions, a prior tool call and result, and a follow-up request with cache_control. Explicit high reasoning effort uses reasoning_effort for Chat Completions, reasoning.effort for Responses, and native thinking plus output_config.effort for Messages. Their provider bodies were captured separately for each client endpoint, including tool calls, thinking signatures and full usage. Keep the endpoint's native request shape and inspect the translation before recording its expected output. A changed LiteLLM output is not automatically correct just because the proxy returned it

Each rich base captures a real provider cache write. Its derived CLAUDE_SONNET_5_5_CACHE_HIT_TEST_CASE in prompt_caching/ uses the identical request and the subsequent real cache-hit response. CI replays these bodies independently through the fake provider, checking request translation and usage conversion without requiring a live cache or test ordering. cache_control configures the provider's prompt cache, while cache: {"no-cache": true} prevents LiteLLM's response cache from bypassing the provider

Keep specialized feature captures paired with their original requests. If enriching a base changes an inherited request, recapture that feature or override its request explicitly, as the separate Anthropic streaming case does. The maintained provider/model target list lives only in the daily translation-sync automation prompt, not in a second repository manifest

StreamingTranslationTestCase stores the stream request, exact provider request and provider and LiteLLM SSE frames. The runner compares parsed frames exactly and checks the final message they join into against expected_litellm_response, with streaming cases living in <endpoint>/streaming/

Deployments used by translation tests are shared by the whole suite and declared in proxy_config.yaml under model_list, with model_name equal to the litellm model string, api_base: http://127.0.0.1:8191 and a synthetic key. A case names the deployment literally in its client request. The fake provider behind them is the provider fixture: one wire_server on port 8191 inside the pytest process, started the first time a test asks for it. A test queues its replies with provider.expect(...) and reads what the proxy sent with provider.received(). Tests that use it run one at a time. After each test the fixture fails if a queued reply was never requested or a received request was never read, and before each test it fails if a request arrived in between, naming the previous test. It refuses to start under pytest-xdist, so the mcp and cost groups cannot use it. Client requests carry "cache": {"no-cache": True} because the proxy caches responses in Redis

Provider responses in translation cases are captured once from the real provider and stored verbatim. First run the new case against the fake provider; the body the proxy sends is the case's expected_provider_request. Send that exact body to the real provider endpoint with a key from the 1Password Shared vault (/qa-keys), and only store the case when the provider answers 2xx. Keep only the response body and drop every response header, since headers carry account identifiers such as the organization id and rate limits. Never print or save the request headers you sent. Before committing, check the body contains no key and no account identifier, such as an organization id, an AWS account id inside an ARN, a GCP project id or an Azure resource name, and that the prompt is synthetic. Paste the body as the case's mock_provider_response without shortening ids, token counts or signatures, and move long opaque values such as thinking signatures into module-level constants used by both mock_provider_response and expected_litellm_response. Do not commit the script used for the capture