From 61118c9ab19467edeaca88919e9cdbd27fa773a7 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Sun, 3 May 2026 23:15:59 -0400 Subject: [PATCH] fix(bedrock): beta header filtering for Opus 4.7 - Filter user-provided beta headers through provider config (invoke path) - Use correct provider="bedrock_converse" for converse API beta filtering - Strip context-1m-2025-08-07 beta for Opus 4.7 (native 1M context) --- litellm/llms/bedrock/chat/converse_transformation.py | 3 +-- .../anthropic_claude3_transformation.py | 6 +++++- .../anthropic_claude3_transformation.py | 6 ++++++ litellm/proxy/types_utils/__init__.py | 0 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 litellm/proxy/types_utils/__init__.py diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py index a63476eefc5..35cefd1c0ff 100644 --- a/litellm/llms/bedrock/chat/converse_transformation.py +++ b/litellm/llms/bedrock/chat/converse_transformation.py @@ -92,7 +92,6 @@ BEDROCK_COMPUTER_USE_TOOLS = [ ] - class AmazonConverseConfig(BaseConfig): """ Reference - https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html @@ -1521,7 +1520,7 @@ class AmazonConverseConfig(BaseConfig): if anthropic_beta_list and base_model.startswith("anthropic"): filtered_betas = filter_and_transform_beta_headers( beta_headers=anthropic_beta_list, - provider="bedrock", + provider="bedrock_converse", ) if filtered_betas: additional_request_params["anthropic_beta"] = filtered_betas diff --git a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py index 8a76f972f56..87da43865f4 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py @@ -319,7 +319,11 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig): beta_headers=list(beta_set - user_beta_set), provider="bedrock", ) - return sorted(user_beta_set.union(set(auto_beta_list))) + filtered_user_betas = filter_and_transform_beta_headers( + beta_headers=list(user_beta_set), + provider="bedrock", + ) + return sorted(set(filtered_user_betas).union(set(auto_beta_list))) def _convert_document_url_sources_to_base64(self, anthropic_request: dict) -> None: """ diff --git a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py index 6eb2ec0d4b8..83621b7a241 100644 --- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py +++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py @@ -525,6 +525,12 @@ class AmazonAnthropicClaudeMessagesConfig( dropped_user_betas, ) + # Opus 4.7+ has native 1M context on Bedrock — strip the legacy beta + if any( + p in model.lower() for p in ("opus-4.7", "opus_4.7", "opus-4-7", "opus_4_7") + ): + filtered_betas = [b for b in filtered_betas if b != "context-1m-2025-08-07"] + return filtered_betas def _strip_unsupported_bedrock_invoke_fields( diff --git a/litellm/proxy/types_utils/__init__.py b/litellm/proxy/types_utils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d