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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Add update_headers_with_filtered_beta in all messages API providers
Sameer Kankute3f9a7b195658
diff --git a/litellm/llms/azure_ai/anthropic/transformation.py b/litellm/llms/azure_ai/anthropic/transformation.pyindex 2d8d3b987c7..753bc9c08eb 100644--- a/litellm/llms/azure_ai/anthropic/transformation.py+++ b/litellm/llms/azure_ai/anthropic/transformation.py@@ -3,6 +3,9 @@ Azure Anthropic transformation config - extends AnthropicConfig with Azure authe"""from typing import TYPE_CHECKING, Dict, List, Optional, Union+from litellm.anthropic_beta_headers_manager import (+ update_headers_with_filtered_beta,+)from litellm.llms.anthropic.chat.transformation import AnthropicConfigfrom litellm.llms.azure.common_utils import BaseAzureLLMfrom litellm.types.llms.openai import AllMessageValues@@ -87,6 +90,12 @@ class AzureAnthropicConfig(AnthropicConfig):if "anthropic-version" not in headers:headers["anthropic-version"] = "2023-06-01"+ # Filter out unsupported beta headers for Azure AI+ headers = update_headers_with_filtered_beta(+ headers=headers,+ provider="azure_ai",+ )+return headersdef transform_request(diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.pyindex 7c6c4065782..7fc51263ebb 100644--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@ -11,6 +11,9 @@ import httpximport litellmfrom litellm._logging import verbose_logger+from litellm.anthropic_beta_headers_manager import (+ filter_and_transform_beta_headers,+)from litellm.constants import RESPONSE_FORMAT_TOOL_NAMEfrom litellm.litellm_core_utils.core_helpers import (filter_exceptions_from_params,@@ -617,37 +620,6 @@ class AmazonConverseConfig(BaseConfig):return transformed_tools- def _filter_unsupported_beta_headers_for_bedrock(- self, model: str, beta_list: list- ) -> list:- """- Remove beta headers that are not supported on Bedrock Converse API for the given model.-- Extended thinking beta headers are only supported on specific Claude 4+ models.- Some beta headers are universally unsupported on Bedrock Converse API.-- Args:- model: The model name- beta_list: The list of beta headers to filter-- Returns:- Filtered list of beta headers- """- filtered_betas = []-- # 1. Filter out beta headers that are universally unsupported on Bedrock Converse- for beta in beta_list:- should_keep = True- for unsupported_pattern in UNSUPPORTED_BEDROCK_CONVERSE_BETA_PATTERNS:- if unsupported_pattern in beta.lower():- should_keep = False- break-- if should_keep:- filtered_betas.append(beta)-- return filtered_betas-def _separate_computer_use_tools(self, tools: List[OpenAIChatCompletionToolParam], model: str) -> Tuple[@@ -1124,7 +1096,28 @@ class AmazonConverseConfig(BaseConfig):# Add computer use tools and anthropic_beta if needed (only when computer use tools are present)if computer_use_tools:- anthropic_beta_list.append("computer-use-2024-10-22")+ # Determine the correct computer-use beta header based on model+ # "computer-use-2025-11-24" for Claude Opus 4.6, Claude Opus 4.5+ # "computer-use-2025-01-24" for Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4, Opus 4, and Sonnet 3.7+ # "computer-use-2024-10-22" for older models+ model_lower = model.lower()+ if "opus-4.6" in model_lower or "opus_4.6" in model_lower or "opus-4-6" in model_lower or "opus_4_6" in model_lower:+ computer_use_header = "computer-use-2025-11-24"+ elif "opus-4.5" in model_lower or "opus_4.5" in model_lower or "opus-4-5" in model_lower or "opus_4_5" in model_lower:+ computer_use_header = "computer-use-2025-11-24"+ elif any(pattern in model_lower for pattern in [+ "sonnet-4.5", "sonnet_4.5", "sonnet-4-5", "sonnet_4_5",+ "haiku-4.5", "haiku_4.5", "haiku-4-5", "haiku_4_5",+ "opus-4.1", "opus_4.1", "opus-4-1", "opus_4_1",+ "sonnet-4", "sonnet_4",+ "opus-4", "opus_4",+ "sonnet-3.7", "sonnet_3.7", "sonnet-3-7", "sonnet_3_7"+ ]):+ computer_use_header = "computer-use-2025-01-24"+ else:+ computer_use_header = "computer-use-2024-10-22"++ anthropic_beta_list.append(computer_use_header)# Transform computer use tools to proper Bedrock formattransformed_computer_tools = self._transform_computer_use_tools(computer_use_tools@@ -1150,13 +1143,13 @@ class AmazonConverseConfig(BaseConfig):unique_betas.append(beta)seen.add(beta)- # Filter out unsupported beta headers for Bedrock Converse API- filtered_betas = self._filter_unsupported_beta_headers_for_bedrock(- model=model,- beta_list=unique_betas,+ filtered_betas = filter_and_transform_beta_headers(+ beta_headers=unique_betas,+ provider="bedrock_converse",)-- additional_request_params["anthropic_beta"] = filtered_betas++ if filtered_betas:+ additional_request_params["anthropic_beta"] = filtered_betasreturn bedrock_tools, anthropic_beta_listdiff --git a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.pyindex 90de67a822f..19fe7d8c140 100644--- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py+++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py@@ -12,6 +12,9 @@ from typing import (import httpx+from litellm.anthropic_beta_headers_manager import (+ filter_and_transform_beta_headers,+)from litellm.llms.anthropic.common_utils import AnthropicModelInfofrom litellm.llms.anthropic.experimental_pass_through.messages.transformation import (AnthropicMessagesConfig,@@ -55,10 +58,6 @@ class AmazonAnthropicClaudeMessagesConfig(# Beta header patterns that are not supported by Bedrock Invoke API# These will be filtered out to prevent 400 "invalid beta flag" errors- UNSUPPORTED_BEDROCK_INVOKE_BETA_PATTERNS = [- "advanced-tool-use", # Bedrock Invoke doesn't support advanced-tool-use beta headers- "prompt-caching-scope",- ]def __init__(self, **kwargs):BaseAnthropicMessagesConfig.__init__(self, **kwargs)@@ -276,39 +275,48 @@ class AmazonAnthropicClaudeMessagesConfig(model: The model namebeta_set: The set of beta headers to filter in-place"""- beta_headers_to_remove = set()- has_advanced_tool_use = False-- # 1. Filter out beta headers that are universally unsupported on Bedrock Invoke and track if advanced-tool-use header is present- for beta in beta_set:- for unsupported_pattern in self.UNSUPPORTED_BEDROCK_INVOKE_BETA_PATTERNS:- if unsupported_pattern in beta.lower():- beta_headers_to_remove.add(beta)- has_advanced_tool_use = True- break-- # 2. Filter out extended thinking headers for models that don't support them+ # 1. Handle header transformations BEFORE filtering+ # (advanced-tool-use -> tool-search-tool)+ # This must happen before filtering because advanced-tool-use is in the unsupported list+ has_advanced_tool_use = "advanced-tool-use-2025-11-20" in beta_set+ if has_advanced_tool_use and self._supports_tool_search_on_bedrock(model):+ beta_set.discard("advanced-tool-use-2025-11-20")+ beta_set.add("tool-search-tool-2025-10-19")+ beta_set.add("tool-examples-2025-10-29")++ # 2. Apply provider-level filtering using centralized JSON config+ beta_list = list(beta_set)+ filtered_list = filter_and_transform_beta_headers(+ beta_headers=beta_list,+ provider="bedrock",+ )++ # Update the set with filtered headers+ beta_set.clear()+ beta_set.update(filtered_list)++ # 2.1. Handle model-specific exceptions: structured-outputs is only supported on Opus 4.6+ # Re-add structured-outputs if it was in the original set and model is Opus 4.6+ model_lower = model.lower()+ is_opus_4_6 = any(pattern in model_lower for pattern in ["opus-4.6", "opus_4.6", "opus-4-6", "opus_4_6"])+ if is_opus_4_6 and "structured-outputs-2025-11-13" in beta_list:+ beta_set.add("structured-outputs-2025-11-13")++ # 3. Filter out extended thinking headers for models that don't support themextended_thinking_patterns = ["extended-thinking","interleaved-thinking",]if not self._supports_extended_thinking_on_bedrock(model):+ beta_headers_to_remove = set()for beta in beta_set:for pattern in extended_thinking_patterns:if pattern in beta.lower():beta_headers_to_remove.add(beta)break-- # Remove all filtered headers- for beta in beta_headers_to_remove:- beta_set.discard(beta)-- # 3. Translate advanced-tool-use to Bedrock-specific headers for models that support tool search- # Ref: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages-request-response.html- # Ref: https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool- if has_advanced_tool_use and self._supports_tool_search_on_bedrock(model):- beta_set.add("tool-search-tool-2025-10-19")- beta_set.add("tool-examples-2025-10-29")++ for beta in beta_headers_to_remove:+ beta_set.discard(beta)def _get_tool_search_beta_header_for_bedrock(self,diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.pyindex 9b8ff3ecc2d..918b8ecc225 100644--- a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py+++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py@@ -1,5 +1,8 @@from typing import Any, Dict, List, Optional, Tuple+from litellm.anthropic_beta_headers_manager import (+ update_headers_with_filtered_beta,+)from litellm.llms.anthropic.common_utils import AnthropicModelInfofrom litellm.llms.anthropic.experimental_pass_through.messages.transformation import (AnthropicMessagesConfig,@@ -7,7 +10,6 @@ from litellm.llms.anthropic.experimental_pass_through.messages.transformation imfrom litellm.types.llms.anthropic import (ANTHROPIC_BETA_HEADER_VALUES,ANTHROPIC_HOSTED_TOOLS,- ANTHROPIC_PROMPT_CACHING_SCOPE_BETA_HEADER,)from litellm.types.llms.anthropic_tool_search import get_tool_search_beta_headerfrom litellm.types.llms.vertex_ai import VertexPartnerProvider@@ -65,10 +67,6 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vertexisting_beta = headers.get("anthropic-beta")if existing_beta:beta_values.update(b.strip() for b in existing_beta.split(","))-- # Use the helper to remove unsupported beta headers- self.remove_unsupported_beta(headers)- beta_values.discard(ANTHROPIC_PROMPT_CACHING_SCOPE_BETA_HEADER)# Check for web search toolfor tool in tools:@@ -84,6 +82,12 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vertif beta_values:headers["anthropic-beta"] = ",".join(beta_values)+ # Filter out unsupported beta headers for Vertex AI+ headers = update_headers_with_filtered_beta(+ headers=headers,+ provider="vertex_ai",+ )+return headers, api_basedef get_complete_url(@@ -128,23 +132,3 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vert) # do not pass output_format in request body to vertex ai - vertex ai does not support output_format as yetreturn anthropic_messages_request-- def remove_unsupported_beta(self, headers: dict) -> None:- """- Helper method to remove unsupported beta headers from the beta headers.- Modifies headers in place.- """- unsupported_beta_headers = [- ANTHROPIC_PROMPT_CACHING_SCOPE_BETA_HEADER- ]- existing_beta = headers.get("anthropic-beta")- if existing_beta:- filtered_beta = [- b.strip()- for b in existing_beta.split(",")- if b.strip() not in unsupported_beta_headers- ]- if filtered_beta:- headers["anthropic-beta"] = ",".join(filtered_beta)- elif "anthropic-beta" in headers:- del headers["anthropic-beta"]