diff --git a/litellm/llms/anthropic/messages/adapters/transformation.py b/litellm/llms/anthropic/messages/adapters/transformation.py index afcd94c5b2c..ba0d01f2268 100644 --- a/litellm/llms/anthropic/messages/adapters/transformation.py +++ b/litellm/llms/anthropic/messages/adapters/transformation.py @@ -211,7 +211,7 @@ from litellm.types.llms.openai import ( ToolMessageContentPart, ) from litellm.types.utils import Choices, LlmProviders, ModelResponse, StreamingChoices, Usage -from litellm.utils import supports_mid_conversation_system +from litellm.utils import is_explicitly_disabled_factory, supports_mid_conversation_system from .streaming_iterator import AnthropicSSEStream, AnthropicStreamWrapper @@ -1227,6 +1227,10 @@ class LiteLLMAnthropicMessagesAdapter: ) if not reasoning_effort: return + if reasoning_effort == "none" and is_explicitly_disabled_factory( + model=model, custom_llm_provider=custom_llm_provider, key="supports_none_reasoning_effort" + ): + return new_kwargs["reasoning_effort"] = ( reasoning_effort diff --git a/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py b/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py index cc366dcde4c..56b737539c2 100644 --- a/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py @@ -2432,6 +2432,30 @@ def test_thinking_disabled_stays_plain_string_when_auto_summary_enabled(): assert new_kwargs["reasoning_effort"] == "none" +@pytest.mark.parametrize( + ("model", "custom_llm_provider", "expected_effort"), + [ + pytest.param("us.openai.gpt-6-astra", "bedrock", None, id="bedrock-gpt-6-astra"), + pytest.param("global.openai.gpt-6-astra", "bedrock", None, id="bedrock-gpt-6-astra-global"), + pytest.param("openai.gpt-6-astra", "bedrock_mantle", None, id="mantle-gpt-6-astra"), + pytest.param("us.openai.gpt-6-sol", "bedrock", "none", id="bedrock-gpt-6-sol"), + pytest.param("converse/global.openai.gpt-6-luna", "bedrock", "none", id="bedrock-converse-gpt-6-luna"), + pytest.param("openai.gpt-6-sol", "bedrock_mantle", "none", id="mantle-gpt-6-sol"), + pytest.param("converse/us.openai.gpt-5.6-sol", "bedrock", "none", id="bedrock-gpt-5.6-sol-without-flag"), + ], +) +def test_thinking_disabled_sends_effort_none_only_to_targets_that_take_it( + model: str, custom_llm_provider: str, expected_effort: str | None, local_model_cost_map: None +) -> None: + new_kwargs: Final[dict[str, object]] = {"model": model} + LiteLLMAnthropicMessagesAdapter()._translate_thinking_to_openai( + cast(Any, {"thinking": {"type": "disabled"}}), cast(Any, new_kwargs), custom_llm_provider=custom_llm_provider + ) + + assert "thinking" not in new_kwargs + assert new_kwargs.get("reasoning_effort") == expected_effort + + @pytest.mark.parametrize( "model", [