From 8a4eb7b0f97f271043723d04f0bb4a6e4f24fccb Mon Sep 17 00:00:00 2001 From: Aswath Ram A Srinivasan <22993782+aswathsr101@users.noreply.github.com> Date: Tue, 20 Oct 2026 13:20:21 -0700 Subject: [PATCH] fix(bedrock): forward the interleaved-thinking beta on Bedrock Invoke and Converse Bedrock Invoke and Converse both accept interleaved-thinking-2025-05-14, but the beta headers config mapped it to null for bedrock and bedrock_converse, so a client's header was dropped and requests with thinking.budget_tokens above max_tokens failed with a 400. Map it through like bedrock_mantle does, and keep the clear_thinking auto-injection off adaptive-thinking models, which don't need it --- litellm/anthropic_beta_headers_config.json | 4 +- .../anthropic_claude3_transformation.py | 2 +- .../test_anthropic_claude3_transformation.py | 45 +++++++++++++++++++ .../test_anthropic_beta_headers_filtering.py | 13 ++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/litellm/anthropic_beta_headers_config.json b/litellm/anthropic_beta_headers_config.json index 236b18fe428..0828a63cc0e 100644 --- a/litellm/anthropic_beta_headers_config.json +++ b/litellm/anthropic_beta_headers_config.json @@ -89,7 +89,7 @@ "fast-mode-2026-02-01": null, "files-api-2025-04-14": null, "fine-grained-tool-streaming-2025-05-14": "fine-grained-tool-streaming-2025-05-14", - "interleaved-thinking-2025-05-14": null, + "interleaved-thinking-2025-05-14": "interleaved-thinking-2025-05-14", "mcp-client-2025-11-20": null, "mcp-client-2025-04-04": null, "mcp-servers-2025-12-04": null, @@ -124,7 +124,7 @@ "fast-mode-2026-02-01": null, "files-api-2025-04-14": null, "fine-grained-tool-streaming-2025-05-14": "fine-grained-tool-streaming-2025-05-14", - "interleaved-thinking-2025-05-14": null, + "interleaved-thinking-2025-05-14": "interleaved-thinking-2025-05-14", "mcp-client-2025-11-20": null, "mcp-client-2025-04-04": null, "mcp-servers-2025-12-04": null, diff --git a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py index 12421aa94fd..2e2539761ac 100644 --- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py +++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py @@ -583,7 +583,7 @@ class AmazonAnthropicClaudeMessagesConfig( ) beta_set.update(auto_betas) - if injected_thinking_for_clear_thinking: + if injected_thinking_for_clear_thinking and not AnthropicModelInfo.is_adaptive_thinking_model(model, "bedrock"): beta_set.add("interleaved-thinking-2025-05-14") if anthropic_model_info.is_eager_input_streaming_used(tools): diff --git a/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py b/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py index 6fe32785281..496d50f2d0f 100644 --- a/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py +++ b/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py @@ -2170,6 +2170,51 @@ def test_bedrock_clear_thinking_keeps_enabled_for_non_adaptive_models(): assert "output_config" not in request +def test_bedrock_invoke_transform_forwards_client_interleaved_thinking_beta(local_beta_headers_config): + from litellm.types.router import GenericLiteLLMParams + + cfg = AmazonAnthropicClaudeMessagesConfig() + optional_params = { + "max_tokens": 2000, + "stream": False, + "thinking": {"type": "enabled", "budget_tokens": 3000}, + } + + result = cfg.transform_anthropic_messages_request( + model="us.anthropic.claude-haiku-4-5-20251001-v1:0", + messages=[{"role": "user", "content": "hi"}], + anthropic_messages_optional_request_params=copy.deepcopy(optional_params), + litellm_params=GenericLiteLLMParams(), + headers={"anthropic-beta": "interleaved-thinking-2025-05-14"}, + ) + + assert "interleaved-thinking-2025-05-14" in result["anthropic_beta"] + + +def test_bedrock_invoke_transform_adds_interleaved_beta_for_clear_thinking_on_non_adaptive_model( + local_beta_headers_config, +): + from litellm.types.router import GenericLiteLLMParams + + cfg = AmazonAnthropicClaudeMessagesConfig() + optional_params = { + "max_tokens": 32000, + "stream": False, + "context_management": {"edits": [{"type": "clear_thinking_20251015", "keep": "all"}]}, + } + + result = cfg.transform_anthropic_messages_request( + model="anthropic.claude-opus-4-5-v1:0", + messages=[{"role": "user", "content": "hi"}], + anthropic_messages_optional_request_params=copy.deepcopy(optional_params), + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + + assert result["thinking"]["type"] == "enabled" + assert "interleaved-thinking-2025-05-14" in result["anthropic_beta"] + + def test_bedrock_invoke_transform_emits_adaptive_thinking_for_opus_4_8(): """End-to-end: a Claude Code clear_thinking payload (no ``thinking`` field) on Opus 4.8 must produce a Bedrock Invoke body with adaptive thinking and an diff --git a/tests/unit/test_anthropic_beta_headers_filtering.py b/tests/unit/test_anthropic_beta_headers_filtering.py index 2a85122d91c..a7011f6bdda 100644 --- a/tests/unit/test_anthropic_beta_headers_filtering.py +++ b/tests/unit/test_anthropic_beta_headers_filtering.py @@ -458,6 +458,19 @@ class TestAnthropicBetaHeadersFiltering: assert filtered == ["dangerous-tool-use-2026-09-03"] + @pytest.mark.parametrize("provider", ["bedrock", "bedrock_converse"]) + def test_interleaved_thinking_forwarded_for_bedrock(self, provider: str) -> None: + """Bedrock InvokeModel (body `anthropic_beta`) and Converse (`additionalModelRequestFields.anthropic_beta`) + both accepted interleaved-thinking-2025-05-14 on us.anthropic.claude-haiku-4-5 when probed live on + 2026-10-20. Dropping it made every request with `thinking.budget_tokens` above `max_tokens` fail with + "`max_tokens` must be greater than `thinking.budget_tokens`" on /v1/messages and /chat/completions""" + filtered: Final = filter_and_transform_beta_headers( + beta_headers=["interleaved-thinking-2025-05-14"], + provider=provider, + ) + + assert filtered == ["interleaved-thinking-2025-05-14"] + @pytest.mark.parametrize("provider", ["anthropic", "vertex_ai"]) def test_inline_tools_forwarded(self, provider: str) -> None: """inline-tools-2026-09-15 lets a `tool_addition` system message carry a new tool mid-conversation.