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(bedrock): preserve adaptive thinking effort through the /v1/messages bridge
mateo-berri929ee52b873d
diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.pyindex 22f9bfd30ea..3640f9fd2b8 100644--- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py+++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py@@ -976,6 +976,17 @@ class LiteLLMAnthropicMessagesAdapter:model: Final = new_kwargs.get("model", "")if self.is_anthropic_claude_model(model) or self.is_bedrock_arn_model(model):new_kwargs["thinking"] = thinking+ # Adaptive thinking without its effort tier makes Bedrock Converse+ # return zero reasoning blocks, so forward output_config (minus+ # `format`, already translated to response_format) for Bedrock+ # targets only: other bridged providers reject the raw param, and+ # get_llm_provider strips the `bedrock/` prefix before this runs.+ if model.startswith(("bedrock/", "converse/", "invoke/")) or self.is_bedrock_arn_model(model):+ claude_output_config: Final = anthropic_message_request.get("output_config")+ if isinstance(claude_output_config, dict):+ effort_config: Final = {k: v for k, v in claude_output_config.items() if k != "format"}+ if effort_config:+ new_kwargs["output_config"] = effort_config # rebind-ok: out-param store like thinking abovereturnreasoning_effort = self.translate_anthropic_thinking_to_reasoning_effort(cast(dict[str, Any], thinking))diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.pyindex 193987a3543..f7f240af54f 100644--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@ -514,6 +514,7 @@ class AmazonConverseConfig(BaseConfig):supported_params.append("tool_choice")supported_params.append("thinking")supported_params.append("reasoning_effort")+ supported_params.append("output_config")# For nova imported models, also add web_search_optionsif "nova" in model.lower():supported_params.append("web_search_options")@@ -564,6 +565,7 @@ class AmazonConverseConfig(BaseConfig):):supported_params.append("thinking")supported_params.append("reasoning_effort")+ supported_params.append("output_config")if base_model.startswith("anthropic"):supported_params.append("context_management")@@ -919,6 +921,10 @@ class AmazonConverseConfig(BaseConfig):self._handle_reasoning_effort_parameter(model=model, reasoning_effort=value, optional_params=optional_params)+ elif param == "output_config" and isinstance(value, dict):+ mapped_output_config = dict(value)+ normalize_bedrock_opus_output_config_effort(model=model, output_config=mapped_output_config)+ optional_params["output_config"] = mapped_output_config # rebind-ok: out-param store like siblingselif param == "context_management" and isinstance(value, (dict, list)):self._map_context_management_param(value, optional_params)if param == "requestMetadata":diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex da0592e6bb2..4eec48c9c89 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -929,6 +929,7 @@ class ChatCompletionRequest(TypedDict, total=False):user: strmetadata: dict # litellm specific paramreasoning_effort: str # OpenAI o1/o3 reasoning parameter+ output_config: Mapping[str, object] # Anthropic adaptive-thinking effort, bridged for Bedrock Claudeclass ChatCompletionDeltaChunk(TypedDict, total=False):diff --git a/tests/e2e/claude_code/thinking/test_bedrock_converse.py b/tests/e2e/claude_code/thinking/test_bedrock_converse.pyindex 3b1449d8cb7..0b409f18ea7 100644--- a/tests/e2e/claude_code/thinking/test_bedrock_converse.py+++ b/tests/e2e/claude_code/thinking/test_bedrock_converse.py@@ -54,10 +54,6 @@ def _has_thinking_block(events: Sequence[Mapping[str, Any]]) -> bool:return False- reason="product bug LIT-4524: Bedrock Converse streaming Content block is not a text block; "- "re-enable when empty/mismatched content_block_delta is fixed"-)@pytest.mark.covers("llm.messages.bedrock_converse.thinking.nonstream.works")def test_thinking_bedrock_converse(compat_result):"""Drive the `claude` CLI against the LiteLLM proxy with thinkingdiff --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 c0c6e315b5b..1ade9a19f35 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@@ -1610,6 +1610,88 @@ def test_thinking_disabled_stays_plain_string_when_auto_summary_enabled():assert new_kwargs["reasoning_effort"] == "none"+ "model",+ [+ # SDK-style model with the provider prefix intact+ "bedrock/converse/us.anthropic.claude-opus-4-7",+ # what the bridge actually sees in the proxy: get_llm_provider has+ # already stripped the `bedrock/` prefix by the time it translates+ "converse/us.anthropic.claude-opus-4-7",+ ],+)+def test_adaptive_thinking_output_config_effort_preserved_for_claude_model(model):+ """+ Regression: Claude Code drives adaptive thinking as `thinking: {"type": "adaptive"}`+ plus `output_config: {"effort": "max"}`. The Claude branch of the thinking translator+ forwarded `thinking` verbatim but returned early without reading `output_config`, and+ the handler strips the raw key from extra_kwargs, so the effort tier never reached the+ backend. On Bedrock Converse, adaptive thinking without effort streams zero reasoning+ blocks. The `format` subkey must still be excluded (it is translated to+ `response_format` separately).+ """+ from litellm.types.llms.anthropic import AnthropicMessagesRequest++ anthropic_request = AnthropicMessagesRequest(+ model=model,+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking={"type": "adaptive"},+ output_config={+ "effort": "max",+ "format": {"type": "json_schema", "schema": {"type": "object", "properties": {}}},+ },+ )++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(anthropic_message_request=anthropic_request)++ assert openai_request["thinking"] == {"type": "adaptive"}+ assert openai_request["output_config"] == {"effort": "max"}+ assert "response_format" in openai_request+++def test_adaptive_thinking_format_only_output_config_not_forwarded_for_claude_model():+ """When `output_config` carries only `format`, nothing effort-bearing remains, so the+ translator must not forward an empty `output_config` dict."""+ from litellm.types.llms.anthropic import AnthropicMessagesRequest++ anthropic_request = AnthropicMessagesRequest(+ model="bedrock/converse/us.anthropic.claude-opus-4-7",+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking={"type": "adaptive"},+ output_config={"format": {"type": "json_schema", "schema": {"type": "object", "properties": {}}}},+ )++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(anthropic_message_request=anthropic_request)++ assert openai_request["thinking"] == {"type": "adaptive"}+ assert "output_config" not in openai_request+++def test_adaptive_thinking_output_config_not_forwarded_for_non_bedrock_claude_model():+ """`output_config` is forwarded only for Bedrock-destined Claude models. Other+ Claude-through-bridge providers (e.g. openrouter) accept `thinking` but reject a raw+ `output_config` param with UnsupportedParamsError when drop_params is off."""+ from litellm.types.llms.anthropic import AnthropicMessagesRequest++ anthropic_request = AnthropicMessagesRequest(+ model="openrouter/anthropic/claude-opus-4-7",+ max_tokens=1024,+ messages=[{"role": "user", "content": "hi"}],+ thinking={"type": "adaptive"},+ output_config={"effort": "max"},+ )++ adapter = LiteLLMAnthropicMessagesAdapter()+ openai_request, _ = adapter.translate_anthropic_to_openai(anthropic_message_request=anthropic_request)++ assert openai_request["thinking"] == {"type": "adaptive"}+ assert "output_config" not in openai_request++def test_stop_sequences_translated_to_stop_for_non_claude_model():from litellm.types.llms.anthropic import AnthropicMessagesRequestdiff --git a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.pyindex 7b7796fb01b..cba87427bee 100644--- a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py+++ b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py@@ -370,6 +370,46 @@ def test_output_config_effort_forwarded_into_additional_request_fields(model):assert additional.get("output_config") == {"effort": "high"}+ "model,effort,expected_effort",+ [+ ("bedrock/converse/us.anthropic.claude-opus-4-7", "max", "max"),+ ("bedrock/converse/us.anthropic.claude-opus-4-6-v1", "xhigh", "max"),+ ],+)+def test_explicit_output_config_effort_mapped_for_adaptive_thinking_converse(model, effort, expected_effort):+ """Regression: Claude Code drives adaptive thinking as ``thinking: {"type":+ "adaptive"}`` plus ``output_config: {"effort": ...}``. ``output_config`` must+ be a supported openai param and survive ``map_openai_params`` (clamped to the+ model's Bedrock effort ceiling), otherwise the Converse request carries+ adaptive thinking without an effort tier and Bedrock streams zero+ ``reasoningContent`` blocks."""+ config = AmazonConverseConfig()++ assert "output_config" in config.get_supported_openai_params(model)++ optional_params = config.map_openai_params(+ non_default_params={+ "thinking": {"type": "adaptive"},+ "output_config": {"effort": effort},+ },+ optional_params={},+ model=model,+ drop_params=False,+ )++ assert optional_params["thinking"] == {"type": "adaptive"}+ assert optional_params["output_config"] == {"effort": expected_effort}+++def test_output_config_supported_param_for_arn_models_converse():+ """ARN model ids hide the underlying Claude model, so ``output_config`` must+ be in the blanket ARN supported-params list too."""+ config = AmazonConverseConfig()+ arn_model = "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abcdef123456"+ assert "output_config" in config.get_supported_openai_params(arn_model)++def test_output_config_format_translated_to_native_output_config_converse():"""``output_config.format`` becomes Bedrock ``outputConfig`` and is not forwarded raw."""config = AmazonConverseConfig()