This commit is contained in:
jony montana 2026-10-24 06:14:31 +00:00 • committed by GitHub
commit 17212139ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 67 additions and 1 deletions

View file

@ -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,

View file

@ -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,
):