mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
[Fix] Strip output_config from Anthropic Messages → completion path for Bedrock Nova
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 <noreply@anthropic.com>
This commit is contained in:
parent
6fe82d3886
commit
039f787e77
2 changed files with 61 additions and 1 deletions
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue