The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(anthropic): carry the effort tier only where the target declares reasoning_effort (#38592)
tin-berri1ab6fd89d229
diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.pyindex de77a74e3f4..754f0128a8a 100644--- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py+++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py@@ -890,6 +890,31 @@ class LiteLLMAnthropicMessagesAdapter:)return "prompt_cache_key" in (supported_params or ())+ @staticmethod+ def _target_declares_reasoning_effort(model: str, custom_llm_provider: str | None) -> bool:+ """Whether the target declares ``reasoning_effort`` among its supported params.++ A Claude-family target is recognized by name, which says nothing about the carrier the+ provider serving it accepts: Snowflake serves Claude over the Anthropic dialect and+ declares ``thinking`` alone, so storing the tier there raises before the request reaches+ the wire.++ Without a resolved provider the tier stays behind, which is what this bridge sent before+ it carried one at all. Reading the declaration from the model's own prefix instead would+ resolve the provider through a lookup that runs an OAuth device flow for two of them, and+ this runs inside a logging callback as well as on the request path.++ Unlike ``_supports_prompt_cache_key`` this does not exclude a provider that proxies an+ unknown backend, because that provider declares this param and forwards it to a proxy+ that resolves the real target itself, where a derived cache key has no such guarantee.+ """+ if not model or not custom_llm_provider:+ return False+ supported_params: Final = litellm.get_supported_openai_params(+ model=model, custom_llm_provider=custom_llm_provider+ )+ return "reasoning_effort" in (supported_params or ())+def _translate_metadata_to_openai(self,anthropic_message_request: AnthropicMessagesRequest,@@ -978,6 +1003,8 @@ class LiteLLMAnthropicMessagesAdapter:self,anthropic_message_request: AnthropicMessagesRequest,new_kwargs: ChatCompletionRequest,+ *,+ custom_llm_provider: str | None = None,) -> None:"""Translate Anthropic thinking to either thinking or reasoning_effort.@@ -986,11 +1013,15 @@ class LiteLLMAnthropicMessagesAdapter:because the two are not interchangeable at the provider mapping below.Bedrock takes ``output_config`` directly, which attaches the tier and leaves ``thinking``- alone. Every other bridged Claude target takes ``reasoning_effort``, and used to be sent no- tier at all, so an adaptive request arrived byte-identical whichever effort the caller- asked for. That tier stays a plain string there, since the summary it would otherwise be- wrapped with already travels inside the forwarded ``thinking`` block, and the wrapped dict- is rejected outright by some of these providers.+ alone. Another bridged Claude target takes ``reasoning_effort`` if it declares that param,+ and used to be sent no tier at all, so an adaptive request arrived byte-identical whichever+ effort the caller asked for. That tier stays a plain string there, since the summary it+ would otherwise be wrapped with already travels inside the forwarded ``thinking`` block,+ and the wrapped dict is rejected outright by some of these providers.++ A target declaring neither carrier keeps its bare ``thinking`` block. Being Claude-family+ is a fact about the model, not about the params the provider in front of it accepts, so+ the tier is offered only where the target says it is taken.``reasoning_effort`` is not a substitute for ``output_config`` on the Bedrock side: anapplication inference profile ARN resolves to neither, so the tier is dropped, and providers@@ -1020,6 +1051,8 @@ class LiteLLMAnthropicMessagesAdapter:if effort_config:new_kwargs["output_config"] = effort_config # rebind-ok: out-param store like thinking abovereturn+ if not self._target_declares_reasoning_effort(model, custom_llm_provider):+ returnthinking_type: Final = thinking.get("type") if isinstance(thinking, dict) else Nonedeclared_effort: Final = (@@ -1133,6 +1166,7 @@ class LiteLLMAnthropicMessagesAdapter:self._translate_thinking_to_openai(anthropic_message_request=anthropic_message_request,new_kwargs=new_kwargs,+ custom_llm_provider=custom_llm_provider,)## CONVERT STOP_SEQUENCESself._translate_stop_sequences_to_openai(diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.pyindex cb7e540f843..e6e5cd02a45 100644--- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py+++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py@@ -2054,7 +2054,7 @@ def test_adaptive_thinking_output_config_not_forwarded_for_non_bedrock_claude_mofrom litellm.types.llms.anthropic import AnthropicMessagesRequestanthropic_request = AnthropicMessagesRequest(- model="openrouter/anthropic/claude-opus-4-7",+ model="openrouter/anthropic/claude-opus-4.7",max_tokens=1024,messages=[{"role": "user", "content": "hi"}],thinking={"type": "adaptive"},@@ -2062,7 +2062,9 @@ def test_adaptive_thinking_output_config_not_forwarded_for_non_bedrock_claude_mo)adapter = LiteLLMAnthropicMessagesAdapter()- openai_request, _ = adapter.translate_anthropic_to_openai(anthropic_message_request=anthropic_request)+ openai_request, _ = adapter.translate_anthropic_to_openai(+ anthropic_message_request=anthropic_request, custom_llm_provider="openrouter"+ )assert openai_request["thinking"] == {"type": "adaptive"}assert "output_config" not in openai_request@@ -2079,12 +2081,13 @@ def test_every_adaptive_effort_tier_reaches_a_bridged_claude_target(effort):adapter = LiteLLMAnthropicMessagesAdapter()openai_request, _ = adapter.translate_anthropic_to_openai(anthropic_message_request=AnthropicMessagesRequest(- model="openrouter/anthropic/claude-opus-4-7",+ model="openrouter/anthropic/claude-opus-4.7",max_tokens=1024,messages=[{"role": "user", "content": "hi"}],thinking={"type": "adaptive"},output_config={"effort": effort},- )+ ),+ custom_llm_provider="openrouter",)assert openai_request["reasoning_effort"] == effort@@ -4295,7 +4298,7 @@ def test_completion_cost_on_translated_anthropic_response_includes_web_search():"model, provider, carried",[("databricks/databricks-claude-opus-4-7", "databricks", "max"),- ("openrouter/anthropic/claude-opus-4-7", "openrouter", "xhigh"),+ ("openrouter/anthropic/claude-opus-4.7", "openrouter", "xhigh"),],)def test_a_summary_bearing_adaptive_request_still_delivers_its_tier(model, provider, carried):@@ -4318,7 +4321,8 @@ def test_a_summary_bearing_adaptive_request_still_delivers_its_tier(model, provimessages=[{"role": "user", "content": "hi"}],thinking={"type": "adaptive", "summary": "detailed"},output_config={"effort": "max"},- )+ ),+ custom_llm_provider=provider,)assert openai_request["reasoning_effort"] == "max"@@ -4435,7 +4439,8 @@ def test_a_databricks_target_trades_its_thinking_display_for_the_tier():messages=[{"role": "user", "content": "hi"}],thinking={"type": "adaptive", "display": "omitted"},output_config={"effort": "max"},- )+ ),+ custom_llm_provider="databricks",)on_the_wire = get_optional_params(@@ -4447,3 +4452,147 @@ def test_a_databricks_target_trades_its_thinking_display_for_the_tier():assert on_the_wire["output_config"] == {"effort": "max"}assert on_the_wire["thinking"]["display"] == "summarized"+++ "thinking, output_config",+ [+ ({"type": "adaptive"}, {"effort": "max"}),+ ({"type": "adaptive"}, {"effort": "minimal"}),+ ({"type": "adaptive", "summary": "detailed"}, {"effort": "high"}),+ ({"type": "adaptive", "display": "omitted"}, {"effort": "high"}),+ ],+)+def test_a_target_declaring_no_reasoning_effort_is_sent_none(thinking, output_config):+ """Regression: snowflake serves Claude over the Anthropic dialect and declares `thinking`+ alone, so storing the tier raised `UnsupportedParamsError` in `get_optional_params` before the+ request reached the wire. Every adaptive shape carrying a tier turned a 200 into a 400.++ Being Claude-family is a fact about the model, not about the params the provider in front of+ it accepts. The tier stays behind and the caller's `thinking` block travels untouched."""+ from litellm.types.llms.anthropic import AnthropicMessagesRequest+ from litellm.utils import get_optional_params++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(+ anthropic_message_request=AnthropicMessagesRequest(+ model="snowflake/claude-sonnet-4-6",+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking=thinking,+ output_config=output_config,+ ),+ custom_llm_provider="snowflake",+ )++ assert "reasoning_effort" not in openai_request+ assert "output_config" not in openai_request+ assert openai_request["thinking"] == thinking++ on_the_wire = get_optional_params(+ model="snowflake/claude-sonnet-4-6",+ custom_llm_provider="snowflake",+ thinking=openai_request["thinking"],+ )++ assert on_the_wire["thinking"] == thinking+++def test_a_target_declaring_reasoning_effort_still_gets_its_tier():+ """The negative class for the gate. Same request shape, a provider that does declare the+ param, so the tier must still travel: the gate must drop it for snowflake alone, not for+ every Claude target, or it would undo the fix it is protecting."""+ from litellm.types.llms.anthropic import AnthropicMessagesRequest++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(+ anthropic_message_request=AnthropicMessagesRequest(+ model="databricks/databricks-claude-opus-4-7",+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking={"type": "adaptive"},+ output_config={"effort": "max"},+ ),+ custom_llm_provider="databricks",+ )++ assert openai_request["reasoning_effort"] == "max"+++ "model",+ ["snowflake/claude-sonnet-4-6", "databricks/databricks-claude-opus-4-7", "github_copilot/claude-sonnet-4"],+)+def test_a_caller_that_names_no_provider_carries_no_tier(model):+ """`translate_anthropic_to_openai` is also called without a provider, by `adapter_completion`+ and by the shadow-eval logger. There is no declaration to read there, so the tier stays behind+ rather than being offered to a target that may reject it, which is what this bridge sent+ before it carried a tier at all.++ The databricks arm is the cost of that, stated rather than hidden: a provider that does take+ the tier does not get one from these two callers. The copilot arm is why the cost is worth+ paying, and why this must not be "fixed" by resolving the provider from the model prefix.+ That resolution runs an OAuth device flow for copilot and chatgpt, which would block this+ call for minutes, and one of the two callers is a logging callback. A test asserting the+ absence here is also a test that this stays fast."""+ from litellm.types.llms.anthropic import AnthropicMessagesRequest++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(+ anthropic_message_request=AnthropicMessagesRequest(+ model=model,+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking={"type": "adaptive"},+ output_config={"effort": "max"},+ )+ )++ assert openai_request["thinking"] == {"type": "adaptive"}+ assert "reasoning_effort" not in openai_request+++def test_a_chained_litellm_proxy_target_still_takes_the_tier():+ """The one place this deliberately parts company with `_supports_prompt_cache_key`, which+ excludes a provider that proxies an unknown backend. That exclusion is right for a derived+ cache key and wrong here: the downstream proxy declares this param and resolves the real+ target itself, so excluding it would drop a tier that arrives perfectly well."""+ from litellm.types.llms.anthropic import AnthropicMessagesRequest++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(+ anthropic_message_request=AnthropicMessagesRequest(+ model="litellm_proxy/claude-sonnet-4-6",+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking={"type": "adaptive"},+ output_config={"effort": "max"},+ ),+ custom_llm_provider="litellm_proxy",+ )++ assert openai_request["reasoning_effort"] == "max"+ assert openai_request["thinking"] == {"type": "adaptive"}+++def test_a_bedrock_target_still_takes_output_config_not_the_declared_gate():+ """Bedrock declares both carriers, so the gate must not change which one it gets: the tier+ rides in `output_config`, which leaves `thinking` alone, and `reasoning_effort` is never+ stored alongside it."""+ from litellm.types.llms.anthropic import AnthropicMessagesRequest++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(+ anthropic_message_request=AnthropicMessagesRequest(+ model="bedrock/converse/us.anthropic.claude-opus-4-7",+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking={"type": "adaptive", "display": "omitted"},+ output_config={"effort": "max"},+ ),+ custom_llm_provider="bedrock",+ )++ assert openai_request["output_config"] == {"effort": "max"}+ assert "reasoning_effort" not in openai_request+ assert openai_request["thinking"] == {"type": "adaptive", "display": "omitted"}