From db9914287aade156c848af88a6422d6caebb7151 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Mon, 23 Mar 2026 13:20:00 +0530 Subject: [PATCH] fix(messages): drop output_config for non-anthropic completion path Prevent Anthropic `output_config` from leaking into OpenAI/Azure completion kwargs when using `/v1/messages` pass-through routing. Add a regression test to ensure Azure-routed models do not forward `output_config`. Made-with: Cursor --- .../adapters/handler.py | 5 +++- ...erimental_pass_through_messages_handler.py | 25 +++++++++++++++++++ 2 files changed, 29 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 897ca3bf893..f4de468092d 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py @@ -181,7 +181,10 @@ class LiteLLMMessagesToCompletionTransformationHandler: "include_usage": True, } - excluded_keys = {"anthropic_messages"} + excluded_keys = { + "anthropic_messages", + "output_config", + } extra_kwargs = extra_kwargs or {} for key, value in extra_kwargs.items(): if ( 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 33628e1d19d..ed90038f372 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 @@ -64,6 +64,31 @@ def test_anthropic_experimental_pass_through_messages_handler_dynamic_api_key_an assert mock_completion.call_args.kwargs["custom_key"] == "custom_value" +def test_anthropic_messages_adapter_drops_output_config_for_azure(): + """ + Test that output_config is not forwarded to litellm.completion for Azure models. + """ + from litellm.llms.anthropic.experimental_pass_through.messages.handler import ( + anthropic_messages_handler, + ) + + with patch("litellm.completion", return_value=MagicMock()) as mock_completion: + try: + anthropic_messages_handler( + max_tokens=100, + messages=[{"role": "user", "content": "Hello, how are you?"}], + model="azure/o1", + api_key="test-api-key", + output_config={"effort": "medium"}, + ) + except (ValueError, TypeError, AttributeError) as e: + print(f"Error: {e}") + + mock_completion.assert_called_once() + call_kwargs = mock_completion.call_args.kwargs + assert "output_config" not in call_kwargs + + def test_anthropic_experimental_pass_through_messages_handler_custom_llm_provider(): """ Test that litellm.completion is called when a custom LLM provider is given