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): upgrade legacy thinking after the Bedrock Invoke and Vertex structured-output stub swap
mateo-berrifd4b15fae6d8
diff --git a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.pyindex 2a4c38e71ea..67720451c00 100644--- a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py+++ b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py@@ -107,6 +107,10 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig):# Restore original model namemodel = original_model+ AnthropicModelInfo.translate_legacy_thinking_for_adaptive_model(+ model=original_model, optional_params=optional_params, custom_llm_provider="bedrock"+ )+# The stub model hides the original model from the parent's forced-tool-use backstopresponse_format_tool_choice: Final = optional_params.get("tool_choice")if (diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.pyindex ef03e61a858..7579bc8c02e 100644--- a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py+++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py@@ -177,6 +177,10 @@ class VertexAIAnthropicConfig(AnthropicConfig):# Restore original model name for any other processingmodel = original_model+ AnthropicModelInfo.translate_legacy_thinking_for_adaptive_model(+ model=original_model, optional_params=optional_params, custom_llm_provider="vertex_ai"+ )+return optional_paramsdef transform_response(diff --git a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude3_transformation.py b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude3_transformation.pyindex 41d82e4f960..4a1e97ca170 100644--- a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude3_transformation.py+++ b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_bedrock_chat_invoke_transformations_anthropic_claude3_transformation.py@@ -671,3 +671,27 @@ def test_bedrock_chat_invoke_fable_5_1_response_format_avoids_forced_tool_choiceassert "output_format" not in resultassert "tools" in resultassert "tool_choice" not in result++[email protected]("model", ["us.anthropic.claude-sonnet-5", "us.anthropic.claude-fable-5-1"])+def test_bedrock_chat_invoke_tool_based_response_format_still_upgrades_legacy_thinking(local_model_cost_map, model):+ result = AmazonAnthropicClaudeConfig().map_openai_params(+ non_default_params={+ "response_format": {+ "type": "json_schema",+ "json_schema": {+ "name": "test_schema",+ "schema": {"type": "object", "properties": {"result": {"type": "string"}}},+ },+ },+ "thinking": {"type": "enabled", "budget_tokens": 4096},+ "max_tokens": 8192,+ },+ optional_params={},+ model=model,+ drop_params=False,+ )++ assert "tools" in result+ assert result["thinking"] == {"type": "adaptive"}+ assert result["output_config"] == {"effort": "high"}diff --git a/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_transformation.py b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_transformation.pyindex 9419f88a981..a57672cfbfb 100644--- a/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_transformation.py+++ b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_transformation.py@@ -752,3 +752,26 @@ def test_vertex_ai_fable_5_1_response_format_uses_native_output_format(local_modassert "output_format" in result_paramsassert "tool_choice" not in result_paramsassert "tools" not in result_params+++def test_vertex_ai_anthropic_tool_based_response_format_still_upgrades_legacy_thinking(local_model_cost_map):+ result_params = VertexAIAnthropicConfig().map_openai_params(+ non_default_params={+ "response_format": {+ "type": "json_schema",+ "json_schema": {+ "name": "test_schema",+ "schema": {"type": "object", "properties": {"result": {"type": "string"}}},+ },+ },+ "thinking": {"type": "enabled", "budget_tokens": 4096},+ "max_tokens": 8192,+ },+ optional_params={},+ model="claude-opus-4-8",+ drop_params=False,+ )++ assert "tools" in result_params+ assert result_params["thinking"] == {"type": "adaptive"}+ assert result_params["output_config"] == {"effort": "high"}