mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-13 02:22:50 +00:00
fix(bedrock): stop stream_chunk_size leaking into invoke request bodies (#30240)
stream_chunk_size is a LiteLLM-internal knob for re-chunking the HTTP response stream. The invoke transformations splat optional_params into the provider request body without dropping it, and Bedrock rejects unknown fields, so any bedrock/invoke request that sets the parameter fails with ValidationException: stream_chunk_size: Extra inputs are not permitted. Drop it in the invoke dispatcher (covers cohere, titan, mistral, meta, ai21) and in the Claude messages-format request builder (the route used for bedrock/invoke Anthropic models)
This commit is contained in:
@@ -215,6 +215,7 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig):
|
||||
|
||||
anthropic_request.pop("model", None)
|
||||
anthropic_request.pop("stream", None)
|
||||
anthropic_request.pop("stream_chunk_size", None)
|
||||
output_format = anthropic_request.pop("output_format", None)
|
||||
output_config_format = pop_bedrock_invoke_output_config_format(
|
||||
anthropic_request
|
||||
|
||||
@@ -150,6 +150,7 @@ class AmazonInvokeConfig(BaseConfig, BaseAWSLLM):
|
||||
) -> dict:
|
||||
## SETUP ##
|
||||
stream = optional_params.pop("stream", None)
|
||||
optional_params.pop("stream_chunk_size", None)
|
||||
custom_prompt_dict: dict = litellm_params.pop("custom_prompt_dict", None) or {}
|
||||
hf_model_name = litellm_params.get("hf_model_name", None)
|
||||
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../../../../../..")
|
||||
) # Adds the parent directory to the system path
|
||||
|
||||
from litellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformation import (
|
||||
AmazonAnthropicClaudeConfig,
|
||||
)
|
||||
from litellm.llms.bedrock.chat.invoke_transformations.base_invoke_transformation import (
|
||||
AmazonInvokeConfig,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"config,model",
|
||||
[
|
||||
(AmazonInvokeConfig, "anthropic.claude-3-sonnet-20240229-v1:0"),
|
||||
(AmazonInvokeConfig, "amazon.titan-text-express-v1"),
|
||||
(AmazonInvokeConfig, "mistral.mistral-7b-instruct-v0:2"),
|
||||
(AmazonAnthropicClaudeConfig, "anthropic.claude-sonnet-4-6"),
|
||||
],
|
||||
)
|
||||
def test_transform_request_drops_stream_chunk_size(config, model):
|
||||
"""stream_chunk_size is a LiteLLM-internal knob for re-chunking the HTTP
|
||||
response stream. Leaking it into the provider request body makes Bedrock
|
||||
reject the whole request: ValidationException 'stream_chunk_size: Extra
|
||||
inputs are not permitted'."""
|
||||
request_body = config().transform_request(
|
||||
model=model,
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
optional_params={"stream": True, "stream_chunk_size": 2048, "max_tokens": 10},
|
||||
litellm_params={},
|
||||
headers={},
|
||||
)
|
||||
|
||||
assert "stream_chunk_size" not in json.dumps(request_body)
|
||||
Reference in New Issue
Block a user