fix(bedrock): filter LiteLLM-internal params from invoke request bodies

This commit is contained in:
kimnamu 2026-06-13 22:17:38 +09:00
parent f12c9bec48
commit 4d38915a03
2 changed files with 22 additions and 1 deletions

View file

@ -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"):

View file

@ -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)