From 0d399196f4631ebfca15874a2a36f448c3c70108 Mon Sep 17 00:00:00 2001 From: jony montana Date: Tue, 20 Oct 2026 08:02:04 +0000 Subject: [PATCH] fix(bedrock): translate thinking.type=enabled for Opus 5.5 messages Bedrock rejects the classic enabled shape on Opus 5.5. Claude Code still sends it on /v1/messages, and that path only rewrote it when a clear_thinking edit was present. Translate it to adaptive before the request is copied, and keep a caller-supplied output_config.effort. --- .../anthropic_claude3_transformation.py | 19 ++++++- .../test_anthropic_claude3_transformation.py | 49 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) 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..24ad738dc65 100644 --- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py +++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py @@ -1,4 +1,4 @@ -from collections.abc import AsyncIterator, Mapping +from collections.abc import AsyncIterator, Mapping, MutableMapping from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, cast @@ -721,6 +721,23 @@ class AmazonAnthropicClaudeMessagesConfig( requested_thinking: Final = anthropic_messages_optional_request_params.get("thinking") requested_display_updates: Final = AnthropicModelInfo().is_thinking_display_updates_used(requested_thinking) drop_params: Final = getattr(litellm_params, "drop_params", None) is True + # Opus 5.5 and the other adaptive models that reject thinking.type=enabled + # still receive that shape from Claude Code. Translate it before the shared + # Messages transform copies it into the Bedrock body. Models that still + # accept the legacy shape (the 4.6 family) are left alone. + # The messages boundary still types this payload as a bare dict. Name the + # mapping the translator mutates so basedpyright does not count an unknown + # argument, without putting MutableMapping in an annotation. + typed_optional_params: Final = cast( # cast-ok: [LIT006] untyped messages params dict at this boundary + MutableMapping[str, object], + anthropic_messages_optional_request_params, + ) + AnthropicModelInfo.translate_legacy_thinking_for_adaptive_model( + model=model, + optional_params=typed_optional_params, + custom_llm_provider="bedrock", + drop_params=drop_params, + ) self._clamp_adaptive_reasoning_effort_for_bedrock( model=model, optional_params=anthropic_messages_optional_request_params, 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..7711e6fa647 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 @@ -706,6 +706,55 @@ def test_bedrock_invoke_messages_transform_adds_name_when_tool_missing_name(): assert result["tools"][0]["name"] == "litellm_unnamed_tool_0" +def test_bedrock_invoke_messages_translates_enabled_thinking_for_opus_5_5( + local_model_cost_map, +): + """Opus 5.5 rejects thinking.type=enabled. Claude Code still sends it, with no + clear_thinking edit, so the translation has to happen on the plain request.""" + from litellm.types.router import GenericLiteLLMParams + + cfg = AmazonAnthropicClaudeMessagesConfig() + optional_params = { + "max_tokens": 32000, + "stream": False, + "thinking": {"type": "enabled", "budget_tokens": 2048}, + } + result = cfg.transform_anthropic_messages_request( + model="eu.anthropic.claude-opus-5-5", + messages=[{"role": "user", "content": "hi"}], + anthropic_messages_optional_request_params=copy.deepcopy(optional_params), + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + assert result["thinking"]["type"] == "adaptive" + assert "budget_tokens" not in result["thinking"] + assert result["output_config"]["effort"] + assert "output_config" in result + + +def test_bedrock_invoke_messages_keeps_caller_output_config_effort_for_opus_5_5( + local_model_cost_map, +): + from litellm.types.router import GenericLiteLLMParams + + cfg = AmazonAnthropicClaudeMessagesConfig() + optional_params = { + "max_tokens": 32000, + "stream": False, + "thinking": {"type": "enabled", "budget_tokens": 2048}, + "output_config": {"effort": "low"}, + } + result = cfg.transform_anthropic_messages_request( + model="eu.anthropic.claude-opus-5-5", + messages=[{"role": "user", "content": "hi"}], + anthropic_messages_optional_request_params=copy.deepcopy(optional_params), + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + assert result["thinking"]["type"] == "adaptive" + assert result["output_config"]["effort"] == "low" + + def test_bedrock_invoke_messages_skips_thinking_injection_when_already_enabled( local_model_cost_map, ):