From 859cde4a432f5874d3a24457f115660e1fc3ed9e Mon Sep 17 00:00:00 2001 From: Calvin Div Date: Fri, 28 Aug 2026 23:10:31 +0800 Subject: [PATCH] fix(anthropic): respect chat completions override for thinking --- .../adapters/handler.py | 4 +++- ...perimental_pass_through_messages_handler.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py index 9d61701d26d..cd07eb41623 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py @@ -322,6 +322,7 @@ class LiteLLMMessagesToCompletionTransformationHandler: completion_kwargs: _CompletionKwargs, *, thinking: Mapping[str, object] | None, + use_chat_completions_url: bool = False, ) -> None: """ When users call `litellm.anthropic.messages.*` with a non-Anthropic model and @@ -344,7 +345,7 @@ class LiteLLMMessagesToCompletionTransformationHandler: except Exception: custom_llm_provider = None - if custom_llm_provider != "openai": + if custom_llm_provider != "openai" or use_chat_completions_url: return if not isinstance(thinking, dict) or thinking.get("type") != "enabled": @@ -544,6 +545,7 @@ class LiteLLMMessagesToCompletionTransformationHandler: LiteLLMMessagesToCompletionTransformationHandler._route_openai_thinking_to_responses_api_if_needed( completion_kwargs, thinking=thinking, + use_chat_completions_url=litellm.use_chat_completions_url_for_anthropic_messages, ) return completion_kwargs, tool_name_mapping diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py index ad4c3d6bfbb..12acbd1891a 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py @@ -434,6 +434,24 @@ class TestThinkingParameterTransformation: class TestThinkingSummaryPreservation: """Tests for thinking.summary preservation and reasoning_auto_summary flag.""" + def test_thinking_respects_chat_completions_url_override(self): + from litellm.llms.anthropic.experimental_pass_through.adapters.handler import ( + LiteLLMMessagesToCompletionTransformationHandler, + ) + + completion_kwargs = { + "model": "openai/gpt-5.6", + "custom_llm_provider": "openai", + "reasoning_effort": "medium", + } + LiteLLMMessagesToCompletionTransformationHandler._route_openai_thinking_to_responses_api_if_needed( + completion_kwargs, + thinking={"type": "enabled", "budget_tokens": 5000}, + use_chat_completions_url=True, + ) + + assert completion_kwargs["model"] == "openai/gpt-5.6" + def test_thinking_summary_concise_preserved_for_openai(self): """User-provided summary='concise' should not be replaced with 'detailed'.""" from litellm.llms.anthropic.experimental_pass_through.adapters.handler import (