From 039f787e77ea33e9aed223d77968a1bd9dfbb506 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Mon, 9 Mar 2026 17:30:37 -0700 Subject: [PATCH] =?UTF-8?q?[Fix]=20Strip=20output=5Fconfig=20from=20Anthro?= =?UTF-8?q?pic=20Messages=20=E2=86=92=20completion=20path=20for=20Bedrock?= =?UTF-8?q?=20Nova?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Claude Agent SDK sends `output_config` in the Anthropic Messages request body. For non-Claude Bedrock models (e.g. Nova Pro), this parameter leaked through **kwargs into litellm.completion(), causing Bedrock to reject the request with "extraneous key [output_config]". Co-Authored-By: Claude Opus 4.6 --- .../adapters/handler.py | 5 +- ...erimental_pass_through_adapters_handler.py | 57 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_handler.py diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py index 73e74c228ba..581548648ed 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py @@ -163,7 +163,10 @@ class LiteLLMMessagesToCompletionTransformationHandler: "include_usage": True, } - excluded_keys = {"anthropic_messages"} + excluded_keys = { + "anthropic_messages", + "output_config", # Anthropic-only param; Bedrock Invoke rejects it as extraneous + } extra_kwargs = extra_kwargs or {} for key, value in extra_kwargs.items(): if ( diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_handler.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_handler.py new file mode 100644 index 00000000000..e162b02fec7 --- /dev/null +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_handler.py @@ -0,0 +1,57 @@ +""" +Tests for LiteLLMMessagesToCompletionTransformationHandler +""" + +from litellm.llms.anthropic.experimental_pass_through.adapters.handler import ( + LiteLLMMessagesToCompletionTransformationHandler, +) + + +def test_prepare_completion_kwargs_excludes_output_config(): + """ + Verify that `output_config` (an Anthropic-only parameter) is stripped when + translating an Anthropic Messages request into litellm.completion() kwargs. + + The Claude Agent SDK sends `output_config` in its request body. For + non-Anthropic providers (e.g. Bedrock Nova), this parameter leaks through + **kwargs → extra_kwargs → completion_kwargs, causing Bedrock to reject the + request with "extraneous key [output_config] is not permitted". + + Regression test for: https://github.com/BerriAI/litellm/issues/22797 + """ + completion_kwargs, _ = ( + LiteLLMMessagesToCompletionTransformationHandler._prepare_completion_kwargs( + max_tokens=1024, + messages=[{"role": "user", "content": "hello"}], + model="bedrock/us.amazon.nova-pro-v1:0", + extra_kwargs={ + "output_config": {"type": "text"}, + "custom_llm_provider": "bedrock", + }, + ) + ) + assert "output_config" not in completion_kwargs, ( + "output_config should be excluded from completion kwargs; " + "it is an Anthropic-only param that Bedrock rejects." + ) + # custom_llm_provider should still be passed through + assert completion_kwargs.get("custom_llm_provider") == "bedrock" + + +def test_prepare_completion_kwargs_excludes_anthropic_messages(): + """ + Verify that `anthropic_messages` is also excluded from completion kwargs + (pre-existing behavior). + """ + completion_kwargs, _ = ( + LiteLLMMessagesToCompletionTransformationHandler._prepare_completion_kwargs( + max_tokens=1024, + messages=[{"role": "user", "content": "hello"}], + model="bedrock/us.amazon.nova-pro-v1:0", + extra_kwargs={ + "anthropic_messages": True, + "custom_llm_provider": "bedrock", + }, + ) + ) + assert "anthropic_messages" not in completion_kwargs