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
Update new feats as reviewed
Sameer Kankutedba9946b989a
diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.pyindex ac1c9b1e000..4221dfacf34 100644--- a/litellm/llms/anthropic/chat/transformation.py+++ b/litellm/llms/anthropic/chat/transformation.py@@ -119,6 +119,10 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):def get_config(cls):return super().get_config()+ def _is_claude_opus_4_5(self, model: str) -> bool:+ """Check if the model is Claude Opus 4.5."""+ return "opus-4-5" in model.lower() or "opus_4_5" in model.lower()+def get_supported_openai_params(self, model: str):params = ["stream",@@ -626,7 +630,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):return hosted_web_search_tool- def map_openai_params(+ def map_openai_params( # noqa: PLR0915self,non_default_params: dict,optional_params: dict,@@ -712,9 +716,14 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):if param == "thinking":optional_params["thinking"] = valueelif param == "reasoning_effort" and isinstance(value, str):- optional_params["thinking"] = AnthropicConfig._map_reasoning_effort(- value- )+ # For Claude Opus 4.5, map reasoning_effort to output_config+ if self._is_claude_opus_4_5(model):+ optional_params["output_config"] = {"effort": value}+ else:+ # For other models, map to thinking parameter+ optional_params["thinking"] = AnthropicConfig._map_reasoning_effort(+ value+ )elif param == "web_search_options" and isinstance(value, dict):hosted_web_search_tool = self.map_web_search_tool(cast(OpenAIWebSearchOptions, value)diff --git a/litellm/llms/anthropic/common_utils.py b/litellm/llms/anthropic/common_utils.pyindex 9f5688f9e01..6b339f169cd 100644--- a/litellm/llms/anthropic/common_utils.py+++ b/litellm/llms/anthropic/common_utils.py@@ -151,15 +151,22 @@ class AnthropicModelInfo(BaseLLMModelInfo):return False- def is_effort_used(self, optional_params: Optional[dict]) -> bool:+ def is_effort_used(self, optional_params: Optional[dict], model: Optional[str] = None) -> bool:"""- Check if effort parameter is being used via output_config.+ Check if effort parameter is being used.- Returns True if output_config with effort field is present.+ Returns True if effort-related parameters are present."""if not optional_params:return False+ # Check if reasoning_effort is provided for Claude Opus 4.5+ if model and ("opus-4-5" in model.lower() or "opus_4_5" in model.lower()):+ reasoning_effort = optional_params.get("reasoning_effort")+ if reasoning_effort and isinstance(reasoning_effort, str):+ return True++ # Check if output_config is directly providedoutput_config = optional_params.get("output_config")if output_config and isinstance(output_config, dict):effort = output_config.get("effort")@@ -193,6 +200,75 @@ class AnthropicModelInfo(BaseLLMModelInfo):computer_tool_version, "computer-use-2024-10-22" # Default fallback)+ def get_anthropic_beta_list(+ self,+ model: str,+ custom_llm_provider: str,+ tools: Optional[List] = None,+ optional_params: Optional[dict] = None,+ computer_tool_used: Optional[str] = None,+ prompt_caching_set: bool = False,+ file_id_used: bool = False,+ mcp_server_used: bool = False,+ ) -> List[str]:+ """+ Get list of beta headers based on provider and features used.++ This method provides provider-specific beta header values for different Anthropic features.+ Different providers (Anthropic API, Bedrock, VertexAI, Microsoft Foundry) may require+ different beta header values for the same feature.++ Returns:+ List of beta header strings+ """+ from litellm.types.llms.anthropic import (+ ANTHROPIC_EFFORT_BETA_HEADER,+ ANTHROPIC_TOOL_SEARCH_BETA_HEADER,+ )++ betas = []++ # Detect features+ tool_search_used = self.is_tool_search_used(tools)+ programmatic_tool_calling_used = self.is_programmatic_tool_calling_used(tools)+ input_examples_used = self.is_input_examples_used(tools)+ effort_used = self.is_effort_used(optional_params, model)++ # Add beta headers based on provider+ if custom_llm_provider in ["vertex_ai", "vertex_ai_beta"]:+ if tool_search_used:+ betas.append("tool-search-tool-2025-10-19")+ # VertexAI doesn't support programmatic tool calling or input_examples yet+ elif custom_llm_provider == "bedrock":+ # Bedrock: tool-search only for Opus 4.5, advanced-tool-use for programmatic/input_examples+ if tool_search_used and ("opus-4" in model.lower() or "opus_4" in model.lower()):+ betas.append("tool-search-tool-2025-10-19")+ if programmatic_tool_calling_used or input_examples_used:+ betas.append(ANTHROPIC_TOOL_SEARCH_BETA_HEADER) # advanced-tool-use-2025-11-20+ else: # anthropic, azure (Microsoft Foundry), and others+ # Direct API and Microsoft Foundry use advanced-tool-use for all+ if tool_search_used or programmatic_tool_calling_used or input_examples_used:+ betas.append(ANTHROPIC_TOOL_SEARCH_BETA_HEADER) # advanced-tool-use-2025-11-20++ if effort_used:+ betas.append(ANTHROPIC_EFFORT_BETA_HEADER) # effort-2025-11-24++ if computer_tool_used:+ beta_header = self.get_computer_tool_beta_header(computer_tool_used)+ betas.append(beta_header)++ if prompt_caching_set:+ betas.append("prompt-caching-2024-07-31")++ if file_id_used:+ betas.append("files-api-2025-04-14")+ betas.append("code-execution-2025-05-22")++ if mcp_server_used:+ betas.append("mcp-client-2025-04-04")++ return list(set(betas))+def get_anthropic_headers(self,api_key: str,@@ -278,7 +354,7 @@ class AnthropicModelInfo(BaseLLMModelInfo):tool_search_used = self.is_tool_search_used(tools=tools)programmatic_tool_calling_used = self.is_programmatic_tool_calling_used(tools=tools)input_examples_used = self.is_input_examples_used(tools=tools)- effort_used = self.is_effort_used(optional_params=optional_params)+ effort_used = self.is_effort_used(optional_params=optional_params, model=model)user_anthropic_beta_headers = self._get_user_anthropic_beta_headers(anthropic_beta_header=headers.get("anthropic-beta"))diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.pyindex d76a3c31b51..759311c38fe 100644--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@ -815,11 +815,21 @@ class AmazonConverseConfig(BaseConfig):user_betas = get_anthropic_beta_from_headers(headers)anthropic_beta_list.extend(user_betas)+ # Filter out tool search tools - Bedrock Converse API doesn't support them+ filtered_tools = []+ if original_tools:+ for tool in original_tools:+ tool_type = tool.get("type", "")+ if tool_type in ("tool_search_tool_regex_20251119", "tool_search_tool_bm25_20251119"):+ # Tool search not supported in Converse API - skip it+ continue+ filtered_tools.append(tool)+# Only separate tools if computer use tools are actually present- if original_tools and self.is_computer_use_tool_used(original_tools, model):+ if filtered_tools and self.is_computer_use_tool_used(filtered_tools, model):# Separate computer use tools from regular function toolscomputer_use_tools, regular_tools = self._separate_computer_use_tools(- original_tools, model+ filtered_tools, model)# Process regular function tools using existing logic@@ -835,7 +845,7 @@ class AmazonConverseConfig(BaseConfig):additional_request_params["tools"] = transformed_computer_toolselse:# No computer use tools, process all tools as regular tools- bedrock_tools = _bedrock_tools_pt(original_tools)+ bedrock_tools = _bedrock_tools_pt(filtered_tools)# Set anthropic_beta in additional_request_params if we have any beta featuresif anthropic_beta_list:diff --git a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.pyindex 02b8fd57115..d618451f73e 100644--- a/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py+++ b/litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py@@ -76,6 +76,7 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig):for k, v in optional_params.items()if k not in self.aws_authentication_params}+ filtered_params = self._normalize_bedrock_tool_search_tools(filtered_params)_anthropic_request = AnthropicConfig.transform_request(self,@@ -91,13 +92,58 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig):if "anthropic_version" not in _anthropic_request:_anthropic_request["anthropic_version"] = self.anthropic_version- # Handle anthropic_beta from user headers- anthropic_beta_list = get_anthropic_beta_from_headers(headers)+ anthropic_beta_list = []++ user_betas = get_anthropic_beta_from_headers(headers)+ if user_betas:+ anthropic_beta_list.extend(user_betas)++ # Auto-detect and add beta headers using the new method+ tools = optional_params.get("tools")+ auto_betas = self.get_anthropic_beta_list(+ model=model,+ custom_llm_provider=self.custom_llm_provider or "bedrock",+ tools=tools,+ optional_params=optional_params,+ computer_tool_used=self.is_computer_tool_used(tools),+ prompt_caching_set=self.is_cache_control_set(messages),+ file_id_used=self.is_file_id_used(messages),+ mcp_server_used=self.is_mcp_server_used(optional_params.get("mcp_servers")),+ )+ anthropic_beta_list.extend(auto_betas)+if anthropic_beta_list:- _anthropic_request["anthropic_beta"] = anthropic_beta_list+ _anthropic_request["anthropic_beta"] = list(set(anthropic_beta_list))return _anthropic_request+ def _normalize_bedrock_tool_search_tools(self, optional_params: dict) -> dict:+ """+ Convert tool search entries to the format supported by the Bedrock Invoke API.+ """+ tools = optional_params.get("tools")+ if not tools or not isinstance(tools, list):+ return optional_params++ normalized_tools = []+ for tool in tools:+ tool_type = tool.get("type")+ if tool_type == "tool_search_tool_bm25_20251119":+ # Bedrock Invoke does not support the BM25 variant, so skip it.+ continue+ if tool_type == "tool_search_tool_regex_20251119":+ normalized_tool = tool.copy()+ normalized_tool["type"] = "tool_search_tool_regex"+ normalized_tool["name"] = normalized_tool.get(+ "name", "tool_search_tool_regex"+ )+ normalized_tools.append(normalized_tool)+ continue+ normalized_tools.append(tool)++ optional_params["tools"] = normalized_tools+ return optional_params+def transform_response(self,model: str,diff --git a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.pyindex be782d35766..6f5165241ca 100644--- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py+++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py@@ -1,7 +1,18 @@-from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, List, Optional, Tuple, Union+from typing import (+ TYPE_CHECKING,+ Any,+ AsyncIterator,+ Dict,+ List,+ Optional,+ Tuple,+ Union,+ cast,+)import httpx+from litellm.llms.anthropic.common_utils import AnthropicModelInfofrom litellm.llms.anthropic.experimental_pass_through.messages.transformation import (AnthropicMessagesConfig,)@@ -13,6 +24,7 @@ from litellm.llms.bedrock.chat.invoke_transformations.base_invoke_transformationAmazonInvokeConfig,)from litellm.llms.bedrock.common_utils import get_anthropic_beta_from_headers+from litellm.types.llms.openai import AllMessageValuesfrom litellm.types.router import GenericLiteLLMParamsfrom litellm.types.utils import GenericStreamingChunkfrom litellm.types.utils import GenericStreamingChunk as GChunk@@ -129,10 +141,32 @@ class AmazonAnthropicClaudeMessagesConfig(if "model" in anthropic_messages_request:anthropic_messages_request.pop("model", None)- # 4. Handle anthropic_beta from user headers- anthropic_beta_list = get_anthropic_beta_from_headers(headers)+ # 4. AUTO-INJECT beta headers based on features used+ anthropic_beta_list = []++ # Get user-provided beta headers first+ user_betas = get_anthropic_beta_from_headers(headers)+ if user_betas:+ anthropic_beta_list.extend(user_betas)++ anthropic_model_info = AnthropicModelInfo()+ tools = anthropic_messages_optional_request_params.get("tools")+ messages_typed = cast(List[AllMessageValues], messages)+ auto_betas = anthropic_model_info.get_anthropic_beta_list(+ model=model,+ custom_llm_provider="bedrock",+ tools=tools,+ optional_params=anthropic_messages_optional_request_params,+ computer_tool_used=anthropic_model_info.is_computer_tool_used(tools),+ prompt_caching_set=anthropic_model_info.is_cache_control_set(messages_typed),+ file_id_used=anthropic_model_info.is_file_id_used(messages_typed),+ mcp_server_used=anthropic_model_info.is_mcp_server_used(anthropic_messages_optional_request_params.get("mcp_servers")),+ )+ anthropic_beta_list.extend(auto_betas)++ # Remove duplicates and set in request body if any beta headers existif anthropic_beta_list:- anthropic_messages_request["anthropic_beta"] = anthropic_beta_list+ anthropic_messages_request["anthropic_beta"] = list(set(anthropic_beta_list))return anthropic_messages_requestdiff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.pyindex 7ba788e335c..69651ca4358 100644--- a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py+++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py@@ -68,6 +68,26 @@ class VertexAIAnthropicConfig(AnthropicConfig):)data.pop("model", None) # vertex anthropic doesn't accept 'model' parameter++ tools = optional_params.get("tools")+ anthropic_beta_list = []++ auto_betas = self.get_anthropic_beta_list(+ model=model,+ custom_llm_provider=self.custom_llm_provider or "vertex_ai",+ tools=tools,+ optional_params=optional_params,+ computer_tool_used=self.is_computer_tool_used(tools),+ prompt_caching_set=self.is_cache_control_set(messages),+ file_id_used=self.is_file_id_used(messages),+ mcp_server_used=self.is_mcp_server_used(optional_params.get("mcp_servers")),+ )+ anthropic_beta_list.extend(auto_betas)++ # Note: VertexAI uses tool-search-tool-2025-10-19 for tool search (different from direct API)+ if anthropic_beta_list:+ data["anthropic_beta"] = list(set(anthropic_beta_list))+return datadef transform_response(