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
Merge branch 'litellm_internal_staging' into litellm_fix_bedrock_deepseek_thinking_leak
mateo-berri738896d776cc
diff --cc litellm/llms/bedrock/chat/converse_transformation.pyindex 617ce423d51,fa24f8be893..6fe69b012ca--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@@ -493,39 -509,10 +509,39 @@@ class AmazonConverseConfig(BaseConfig))thinking["budget_tokens"] = BEDROCK_MIN_THINKING_BUDGET_TOKENS+ def _model_accepts_anthropic_thinking_param(self, model: str, base_model: str) -> bool:+ """Whether the model accepts the Anthropic-shaped ``thinking`` / ``reasoning_effort`` request field.++ The Converse mapping serializes ``thinking`` into ``additionalModelRequestFields`` in Anthropic's+ shape. Only Anthropic Claude reasoning models accept that field; DeepSeek models reason natively+ and reject it (a 400 when it leaks through), even though they advertise ``supports_reasoning``.+ """+ if "deepseek" in model or "deepseek" in base_model:+ return False+ return (+ "claude-3-7" in model+ or "claude-sonnet-4" in model+ or "claude-opus-4" in model+ or supports_reasoning(model=model, custom_llm_provider=self.custom_llm_provider)+ or supports_reasoning(model=base_model, custom_llm_provider=self.custom_llm_provider)+ )++ def _model_reasons_natively_and_rejects_request_param(self, model: str, base_model: str) -> bool:+ """Whether the model reasons natively and rejects any reasoning request field on Converse.++ The Converse mapping serializes ``thinking`` into ``additionalModelRequestFields`` in Anthropic's+ shape and ``reasoning_effort`` into a provider-specific shape. DeepSeek reasons on its own and+ returns a 400 when either field is sent, even though it advertises ``supports_reasoning``, so both+ must be dropped for it. Every other model either accepts one of those shapes (Claude ``thinking``,+ gpt-oss / Nova 2 ``reasoning_effort``) or is an opaque ARN we can't introspect, so we leave those+ untouched rather than silently degrading reasoning.+ """+ return "deepseek" in model or "deepseek" in base_model+- def get_supported_openai_params(self, model: str) -> List[str]:+ def get_supported_openai_params(self, model: str) -> list[str]:from litellm.utils import supports_function_calling- supported_params = [+ supported_params: Final = ["max_tokens","max_completion_tokens","stream",@@@ -582,9 -570,20 +599,10 @@@# Nova 2 models support reasoning_effort (transformed to reasoningConfig)# These models use a different reasoning structure than Anthropic's thinking parametersupported_params.append("reasoning_effort")- elif (- "claude-3-7" in model- or "claude-sonnet-4" in model- or "claude-opus-4" in model- or "deepseek.r1" in model- or supports_reasoning(- model=model,- custom_llm_provider=self.custom_llm_provider,- )- or supports_reasoning(model=base_model, custom_llm_provider=self.custom_llm_provider)- ):+ elif self._model_accepts_anthropic_thinking_param(model=model, base_model=base_model):supported_params.append("thinking")supported_params.append("reasoning_effort")+ supported_params.append("output_config")if base_model.startswith("anthropic"):supported_params.append("context_management")@@@ -868,10 -871,7 +890,10 @@@model: str,drop_params: bool,) -> dict:- is_thinking_enabled = self.is_thinking_enabled(non_default_params)- drop_reasoning_request_param = self._model_reasons_natively_and_rejects_request_param(+ is_thinking_enabled: Final = self.is_thinking_enabled(non_default_params)++ drop_reasoning_request_param: Final = self._model_reasons_natively_and_rejects_request_param(+ model=model, base_model=BedrockModelInfo.get_base_model(model)+ )for param, value in non_default_params.items():if param == "response_format" and isinstance(value, dict):@@@ -917,16 -917,10 +939,15 @@@if _tool_choice_value is not None:optional_params["tool_choice"] = _tool_choice_valueif param == "parallel_tool_calls":- disable_parallel = not valueoptional_params["_parallel_tool_use_config"] = {- "tool_choice": {"disable_parallel_tool_use": disable_parallel}+ "tool_choice": {"type": "auto", "disable_parallel_tool_use": not value}}- if param == "thinking" and "openai.gpt-5" not in model:+ if param == "thinking" and drop_reasoning_request_param:+ verbose_logger.debug(+ "Dropping unsupported `thinking` param for Bedrock model=%s; it reasons natively and rejects it.",+ model,+ )- elif param == "thinking":++ elif param == "thinking" and "openai.gpt-5" not in model:if (isinstance(value, dict)and value.get("type") == "adaptive"@@@ -949,11 -943,9 +970,14 @@@litellm.verbose_logger.warning(DROP_UNSUPPORTED_ADAPTIVE_THINKING_WARNING, model)else:optional_params["thinking"] = value+ AnthropicModelInfo.translate_legacy_thinking_for_adaptive_model(+ model=model, optional_params=optional_params, custom_llm_provider="bedrock"+ )+ elif param == "reasoning_effort" and isinstance(value, str) and drop_reasoning_request_param:+ verbose_logger.debug(+ "Dropping unsupported `reasoning_effort` param for Bedrock model=%s; it reasons natively and rejects it.",+ model,+ )elif param == "reasoning_effort" and isinstance(value, str):self._handle_reasoning_effort_parameter(model=model, reasoning_effort=value, optional_params=optional_params