From e51ccbc759bba8ea2e95bfd387b791343316c26a Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Mon, 21 Sep 2026 11:39:26 -0700 Subject: [PATCH] fix(bedrock): forward anthropic-beta headers verbatim on the Claude platform messages path --- .../messages_transformation.py | 3 ++ .../bedrock/test_claude_platform_provider.py | 35 +++++++++++++++++++ ..._github_copilot_messages_transformation.py | 6 ++-- ..._like_anthropic_messages_transformation.py | 6 ++-- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/litellm/llms/bedrock/claude_platform/messages_transformation.py b/litellm/llms/bedrock/claude_platform/messages_transformation.py index 3add682ef6d..1e3eea075f3 100644 --- a/litellm/llms/bedrock/claude_platform/messages_transformation.py +++ b/litellm/llms/bedrock/claude_platform/messages_transformation.py @@ -12,6 +12,9 @@ from .common_utils import BedrockClaudePlatformMixin, strip_claude_platform_rout class BedrockClaudePlatformMessagesConfig(BedrockClaudePlatformMixin, AnthropicMessagesConfig): + def should_filter_anthropic_beta_headers(self) -> bool: + return False + def validate_anthropic_messages_environment( self, headers: dict, diff --git a/tests/test_litellm/llms/bedrock/test_claude_platform_provider.py b/tests/test_litellm/llms/bedrock/test_claude_platform_provider.py index dbded8e0a2e..40f78c84ca3 100644 --- a/tests/test_litellm/llms/bedrock/test_claude_platform_provider.py +++ b/tests/test_litellm/llms/bedrock/test_claude_platform_provider.py @@ -313,6 +313,41 @@ async def test_anthropic_messages_routes_bedrock_claude_platform_to_messages_api assert requests[0]["body"]["model"] == "claude-sonnet-4-6" +@pytest.mark.asyncio +async def test_anthropic_messages_bedrock_claude_platform_forwards_anthropic_beta_verbatim(): + import litellm + + requests = [] + + async def mock_post(self, url, data=None, headers=None, **kwargs): + requests.append(_capture_request(url=url, headers=headers or {}, data=data)) + return _anthropic_response(url) + + try: + with patch( + "litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler.post", + new=mock_post, + ): + await litellm.anthropic_messages( + model="bedrock/claude_platform/claude-sonnet-4-6", + messages=[{"role": "user", "content": "hello"}], + max_tokens=10, + mcp_servers=[{"type": "url", "url": "https://mcp.example.com/mcp", "name": "example"}], + api_base="https://aws-external-anthropic.us-west-2.api.aws", + api_key="fake-platform-key", + workspace_id="wrkspc_test", + extra_headers={"anthropic-beta": "prompt-caching-scope-2026-01-05,mcp-client-2025-11-20"}, + ) + finally: + await litellm.close_litellm_async_clients() + + assert len(requests) == 1 + assert requests[0]["headers"]["anthropic-beta"] == "mcp-client-2025-11-20,prompt-caching-scope-2026-01-05" + assert requests[0]["body"]["mcp_servers"] == [ + {"type": "url", "url": "https://mcp.example.com/mcp", "name": "example"} + ] + + def test_sigv4_no_duplicate_content_type_when_caller_sets_lowercase(): """ Regression: get_anthropic_headers() supplies "content-type" (lowercase). diff --git a/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py b/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py index 9e9760650cf..ed67c33e04c 100644 --- a/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py +++ b/tests/unit/llms/github_copilot/messages/test_github_copilot_messages_transformation.py @@ -272,13 +272,11 @@ def test_github_copilot_config_disables_anthropic_beta_filtering(): because github_copilot has no entry in the beta headers config; a regression here would silently disable header-gated Anthropic features for Copilot.""" from litellm.anthropic_beta_headers_manager import update_headers_with_filtered_beta - from litellm.llms.anthropic.experimental_pass_through.messages.transformation import ( - AnthropicMessagesConfig, - ) + from litellm.llms.azure_ai.anthropic.messages_transformation import AzureAnthropicMessagesConfig config = GithubCopilotAnthropicMessagesConfig() assert config.should_filter_anthropic_beta_headers() is False - assert AnthropicMessagesConfig().should_filter_anthropic_beta_headers() is True + assert AzureAnthropicMessagesConfig().should_filter_anthropic_beta_headers() is True config.authenticator = MagicMock() config.authenticator.get_api_key.return_value = "gh.test-key" diff --git a/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py b/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py index 67a56fdcd79..07f06c9084c 100644 --- a/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py +++ b/tests/unit/llms/openai_like/messages/test_openai_like_anthropic_messages_transformation.py @@ -268,12 +268,10 @@ def test_request_maps_reasoning_effort_to_thinking(config): def test_passthrough_disables_anthropic_beta_filtering(config): - from litellm.llms.anthropic.experimental_pass_through.messages.transformation import ( - AnthropicMessagesConfig, - ) + from litellm.llms.azure_ai.anthropic.messages_transformation import AzureAnthropicMessagesConfig assert config.should_filter_anthropic_beta_headers() is False - assert AnthropicMessagesConfig().should_filter_anthropic_beta_headers() is True + assert AzureAnthropicMessagesConfig().should_filter_anthropic_beta_headers() is True def test_anthropic_beta_survives_provider_filter_on_passthrough_path(config):