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-converse): translate adaptive thinking for pre-4.6 models
Abhimanyu Kapur741220c80fea
diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.pyindex 722bf504845..83054f61ec9 100644--- a/litellm/llms/anthropic/chat/transformation.py+++ b/litellm/llms/anthropic/chat/transformation.py@@ -1498,6 +1498,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):legacy_thinking = AnthropicConfig._map_reasoning_effort(reasoning_effort="medium",model=model,+ custom_llm_provider=self.custom_llm_provider or "anthropic",llm_provider=self.custom_llm_provider or "anthropic",)capped_thinking = (diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.pyindex be904fb27be..c38b3593465 100644--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@ -33,6 +33,7 @@ from litellm.litellm_core_utils.prompt_templates.factory import (make_valid_bedrock_tool_name,)from litellm.llms.anthropic.chat.transformation import (+ DROP_UNSUPPORTED_ADAPTIVE_THINKING_WARNING,DROP_UNSUPPORTED_OUTPUT_CONFIG_WARNING,REASONING_EFFORT_TO_OUTPUT_CONFIG_EFFORT,AnthropicConfig,@@ -899,7 +900,28 @@ class AmazonConverseConfig(BaseConfig):"tool_choice": {"disable_parallel_tool_use": disable_parallel}}if param == "thinking":- optional_params["thinking"] = value+ if (+ isinstance(value, dict)+ and value.get("type") == "adaptive"+ and not AnthropicConfig._is_adaptive_thinking_model(model, "bedrock")+ ):+ max_tokens = non_default_params.get("max_completion_tokens") or non_default_params.get("max_tokens")+ legacy_thinking = AnthropicConfig._map_reasoning_effort(+ reasoning_effort="medium",+ model=model,+ custom_llm_provider="bedrock",+ )+ capped = (+ AnthropicConfig._cap_thinking_budget_to_max_tokens(legacy_thinking, max_tokens)+ if legacy_thinking is not None+ else None+ )+ if capped is not None:+ optional_params["thinking"] = capped+ else:+ litellm.verbose_logger.warning(DROP_UNSUPPORTED_ADAPTIVE_THINKING_WARNING, model)+ else:+ optional_params["thinking"] = valueelif param == "reasoning_effort" and isinstance(value, str):self._handle_reasoning_effort_parameter(model=model, reasoning_effort=value, optional_params=optional_paramsdiff --git a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.pyindex 9f2a4168dec..fe06933e249 100644--- a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py+++ b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py@@ -5767,3 +5767,52 @@ def test_message_level_cache_control_drops_ttl_for_unsupported_model(ttl_target)cache_points = _collect_cache_points(result)assert len(cache_points) == 1assert "ttl" not in cache_points[0]+++ "model",+ [+ "bedrock/converse/us.anthropic.claude-haiku-4-5",+ "bedrock/converse/us.anthropic.claude-sonnet-4-5",+ ],+)+def test_adaptive_thinking_translated_to_legacy_on_pre_46_converse(model):+ """Raw thinking={type: adaptive} from callers like Claude Code must be+ translated to legacy thinking={type: enabled, budget_tokens} for pre-4.6+ models on Bedrock Converse rather than forwarded as-is and rejected."""+ config = AmazonConverseConfig()++ optional_params = config.map_openai_params(+ non_default_params={"thinking": {"type": "adaptive"}, "max_tokens": 8192},+ optional_params={},+ model=model,+ drop_params=False,+ )++ thinking = optional_params.get("thinking")+ assert thinking is not None+ assert thinking["type"] == "enabled"+ assert isinstance(thinking.get("budget_tokens"), int)+ assert thinking["budget_tokens"] < 8192+++ "model",+ [+ "bedrock/converse/us.anthropic.claude-opus-4-7",+ "bedrock/converse/us.anthropic.claude-sonnet-4-6",+ ],+)+def test_adaptive_thinking_passes_through_on_46_plus_converse(model):+ """thinking={type: adaptive} must be forwarded unchanged for 4.6+ models+ that natively support adaptive thinking."""+ config = AmazonConverseConfig()++ optional_params = config.map_openai_params(+ non_default_params={"thinking": {"type": "adaptive"}, "max_tokens": 8192},+ optional_params={},+ model=model,+ drop_params=False,+ )++ assert optional_params.get("thinking") == {"type": "adaptive"}