From 4d38915a03745be7affffd2b54604e6b48d227fe Mon Sep 17 00:00:00 2001 From: kimnamu Date: Sat, 13 Jun 2026 22:17:38 +0900 Subject: [PATCH 1/3] fix(bedrock): filter LiteLLM-internal params from invoke request bodies --- .../base_invoke_transformation.py | 6 +++++- .../test_base_invoke_transformation.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py index 8fc2375c224..8eaa798ddac 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py @@ -8,7 +8,10 @@ import httpx import litellm from litellm._logging import verbose_logger -from litellm.litellm_core_utils.core_helpers import map_finish_reason +from litellm.litellm_core_utils.core_helpers import ( + filter_internal_params, + map_finish_reason, +) from litellm.litellm_core_utils.logging_utils import track_llm_api_timing from litellm.litellm_core_utils.prompt_templates.factory import ( cohere_message_pt, @@ -168,6 +171,7 @@ class AmazonInvokeConfig(BaseConfig, BaseAWSLLM): for k, v in inference_params.items() if k not in self.aws_authentication_params } + inference_params = filter_internal_params(inference_params) request_data: dict = {} if provider == "cohere": if model.startswith("cohere.command-r"): diff --git a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py index aff89f02ff2..8dcbb99c10b 100644 --- a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py +++ b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py @@ -39,3 +39,20 @@ def test_transform_request_drops_stream_chunk_size(config, model): ) assert "stream_chunk_size" not in json.dumps(request_body) + + +def test_transform_request_drops_internal_params(): + """LiteLLM-internal MCP params (e.g. skip_mcp_handler) are control flags used + inside LiteLLM and are not valid Bedrock inference parameters. Leaking them + into the provider request body makes Bedrock reject the request. The Converse + path already filters them via filter_internal_params; the invoke path must do + the same.""" + request_body = AmazonInvokeConfig().transform_request( + model="mistral.mistral-7b-instruct-v0:2", + messages=[{"role": "user", "content": "hi"}], + optional_params={"skip_mcp_handler": True, "max_tokens": 10}, + litellm_params={}, + headers={}, + ) + + assert "skip_mcp_handler" not in json.dumps(request_body) From 113b97133092d8bf0821c9904704791cd3d1f548 Mon Sep 17 00:00:00 2001 From: kimnamu Date: Sun, 14 Jun 2026 07:10:20 +0900 Subject: [PATCH 2/3] test(bedrock): scope invoke test to filter_internal_params fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the stream_chunk_size parametrized test that came along during the cherry-pick — that behavior (#30240) isn't present on litellm_oss_branch, so the test fails here and is out of scope for this PR. Keep only the skip_mcp_handler regression test for this change. --- .../test_base_invoke_transformation.py | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py index 8dcbb99c10b..f2a47d1c5ed 100644 --- a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py +++ b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py @@ -2,45 +2,15 @@ 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) - - def test_transform_request_drops_internal_params(): """LiteLLM-internal MCP params (e.g. skip_mcp_handler) are control flags used inside LiteLLM and are not valid Bedrock inference parameters. Leaking them From 6803a6ae0e241721651cee237de53f09efb39c53 Mon Sep 17 00:00:00 2001 From: kimnamu Date: Tue, 30 Jun 2026 14:14:07 +0900 Subject: [PATCH 3/3] test(bedrock): restore invoke stream chunk coverage --- .../test_base_invoke_transformation.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py index f2a47d1c5ed..8dcbb99c10b 100644 --- a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py +++ b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py @@ -2,15 +2,45 @@ 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) + + def test_transform_request_drops_internal_params(): """LiteLLM-internal MCP params (e.g. skip_mcp_handler) are control flags used inside LiteLLM and are not valid Bedrock inference parameters. Leaking them