Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(bedrock): scope client_metadata drop to anthropic converse models

milaned4343a02645
diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py
index 9e40cb5ee5b..8d1d905a129 100644
--- a/litellm/llms/bedrock/chat/converse_transformation.py
+++ b/litellm/llms/bedrock/chat/converse_transformation.py
@@ -1324,7 +1324,13 @@ class AmazonConverseConfig(BaseConfig):
)
additional_request_params.pop("parallel_tool_calls", None)
- additional_request_params.pop("client_metadata", None)
+
+ if base_model.startswith("anthropic") and additional_request_params.pop("client_metadata", None) is not None:
+ litellm.verbose_logger.debug(
+ "Bedrock Converse: dropping `client_metadata` for model=%s, Anthropic rejects it with "
+ "'client_metadata: Extra inputs are not permitted'",
+ model,
+ )
# Only set the topK value in for models that support it
additional_request_params.update(self._handle_top_k_value(model, inference_params, drop_params))
diff --git a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py
index bd68857d664..3600e366b5a 100644
--- a/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py
+++ b/tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py
@@ -979,8 +979,9 @@ def test_config_blocks_do_not_leak_into_inference_config():
assert data["serviceTier"] == {"type": "priority"}
-def test_client_metadata_stripped_from_converse_request():
- """``client_metadata`` sent by codex must not reach Bedrock as a passthrough model field.
[email protected]("model", ["anthropic.claude-opus-4-8", "us.anthropic.claude-opus-4-8"])
+def test_client_metadata_stripped_for_anthropic_converse_request(model):
+ """``client_metadata`` sent by codex must not reach Anthropic as a passthrough model field.
Converse forwards ``additionalModelRequestFields`` verbatim to the model, and Anthropic
rejects the request with "client_metadata: Extra inputs are not permitted".
@@ -988,7 +989,7 @@ def test_client_metadata_stripped_from_converse_request():
config = AmazonConverseConfig()
data = config._transform_request_helper(
- model="anthropic.claude-opus-4-8",
+ model=model,
system_content_blocks=[],
optional_params={
"maxTokens": 16,
@@ -1003,6 +1004,23 @@ def test_client_metadata_stripped_from_converse_request():
assert fields["anthropic_beta"] == ["computer-use-2025-01-24"]
+def test_client_metadata_kept_for_non_anthropic_converse_request():
+ """Only Anthropic is known to reject ``client_metadata``, so other families keep the passthrough."""
+ config = AmazonConverseConfig()
+
+ data = config._transform_request_helper(
+ model="amazon.nova-pro-v1:0",
+ system_content_blocks=[],
+ optional_params={
+ "maxTokens": 16,
+ "client_metadata": {"originator": "codex_cli_rs"},
+ },
+ messages=None,
+ )
+
+ assert data["additionalModelRequestFields"]["client_metadata"] == {"originator": "codex_cli_rs"}
+
+
def test_parallel_tool_calls_config_kept_for_sonnet_5(monkeypatch):
old_env = os.environ.get("LITELLM_LOCAL_MODEL_COST_MAP")
old_cost = litellm.model_cost