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 filtering at handler level
Sameer Kankute6f2de0542d22
diff --git a/litellm/llms/anthropic/chat/handler.py b/litellm/llms/anthropic/chat/handler.pyindex e85c0d0d017..f51adf96102 100644--- a/litellm/llms/anthropic/chat/handler.py+++ b/litellm/llms/anthropic/chat/handler.py@@ -58,6 +58,9 @@ from litellm.types.utils import (from ...base import BaseLLMfrom ..common_utils import AnthropicError, process_anthropic_headers+from litellm.anthropic_beta_headers_manager import (+ update_headers_with_filtered_beta,+)from .transformation import AnthropicConfigif TYPE_CHECKING:@@ -333,6 +336,10 @@ class AnthropicChatCompletion(BaseLLM):litellm_params=litellm_params,)+ headers = update_headers_with_filtered_beta(+ headers=headers, provider=custom_llm_provider+ )+config = ProviderConfigManager.get_provider_chat_config(model=model,provider=LlmProviders(custom_llm_provider),diff --git a/litellm/llms/bedrock/chat/converse_handler.py b/litellm/llms/bedrock/chat/converse_handler.pyindex d5bd054118d..25af852e09c 100644--- a/litellm/llms/bedrock/chat/converse_handler.py+++ b/litellm/llms/bedrock/chat/converse_handler.py@@ -13,7 +13,9 @@ from litellm.llms.custom_httpx.http_handler import ()from litellm.types.utils import ModelResponsefrom litellm.utils import CustomStreamWrapper-+from litellm.anthropic_beta_headers_manager import (+ update_headers_with_filtered_beta,+ )from ..base_aws_llm import BaseAWSLLM, Credentialsfrom ..common_utils import BedrockErrorfrom .invoke_handler import AWSEventStreamDecoder, MockResponseIterator, make_call@@ -337,7 +339,11 @@ class BedrockConverseLLM(BaseAWSLLM):headers = {"Content-Type": "application/json"}if extra_headers is not None:headers = {"Content-Type": "application/json", **extra_headers}-++ # Filter beta headers in HTTP headers before making the request+ headers = update_headers_with_filtered_beta(+ headers=headers, provider="bedrock_converse"+ )### ROUTING (ASYNC, STREAMING, SYNC)if acompletion:if isinstance(client, HTTPHandler):diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.pyindex 95db8ec64b3..30927ec7bf0 100644--- a/litellm/llms/custom_httpx/llm_http_handler.py+++ b/litellm/llms/custom_httpx/llm_http_handler.py@@ -81,6 +81,9 @@ from litellm.types.llms.anthropic_skills import (ListSkillsResponse,Skill,)+from litellm.anthropic_beta_headers_manager import (+ update_headers_with_filtered_beta,+ )from litellm.types.llms.openai import (CreateBatchRequest,CreateFileRequest,@@ -1858,6 +1861,13 @@ class BaseLLMHTTPHandler:api_key=api_key,api_base=api_base,)++ print( "🔥headers before filtering", headers )+ print( "🔥custom_llm_provider", custom_llm_provider )+ headers = update_headers_with_filtered_beta(+ headers=headers, provider=custom_llm_provider+ )+ print( "🔥headers after filtering", headers )logging_obj.update_environment_variables(model=model,