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
fix(litellm_pre_call_utils.py): forward headers by model group at litellm pre call utils level
Krrish Dholakia06d05c691d1f
diff --git a/litellm/proxy/_experimental/out/model_hub_table.html b/litellm/proxy/_experimental/out/model_hub_table/index.htmlsimilarity index 100%rename from litellm/proxy/_experimental/out/model_hub_table.htmlrename to litellm/proxy/_experimental/out/model_hub_table/index.htmldiff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.htmldeleted file mode 100644index 4015c1b815a..00000000000--- a/litellm/proxy/_experimental/out/onboarding.html+++ /dev/null@@ -1 +0,0 @@-<!DOCTYPE html><html id="__next_error__"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" as="script" fetchPriority="low" href="/litellm-asset-prefix/_next/static/chunks/webpack-a426aae3231a8df1.js"/><script src="/litellm-asset-prefix/_next/static/chunks/fd9d1056-205af899b895cbac.js" async=""></script><script src="/litellm-asset-prefix/_next/static/chunks/117-a0da667066d322b6.js" async=""></script><script src="/litellm-asset-prefix/_next/static/chunks/main-app-475d6efe4080647d.js" async=""></script><title>LiteLLM Dashboard</title><meta name="description" content="LiteLLM Proxy Admin UI"/><link rel="icon" href="/favicon.ico" type="image/x-icon" sizes="16x16"/><link rel="icon" href="./favicon.ico"/><meta name="next-size-adjust"/><script src="/litellm-asset-prefix/_next/static/chunks/polyfills-42372ed130431b0a.js" noModule=""></script></head><body><script src="/litellm-asset-prefix/_next/static/chunks/webpack-a426aae3231a8df1.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])</script><script>self.__next_f.push([1,"1:HL[\"/litellm-asset-prefix/_next/static/media/e4af272ccee01ff0-s.p.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n2:HL[\"/litellm-asset-prefix/_next/static/css/31b7f215e119031e.css\",\"style\"]\n3:HL[\"/litellm-asset-prefix/_next/static/css/618290a32b9bb91a.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"4:I[12846,[],\"\"]\n6:I[19107,[],\"ClientPageRoot\"]\n7:I[12011,[\"665\",\"static/chunks/3014691f-b7b79b78e27792f3.js\",\"50\",\"static/chunks/50-d0da2dd7acce2eb9.js\",\"154\",\"static/chunks/154-686bf7931b450e3d.js\",\"461\",\"static/chunks/app/onboarding/page-3c5840c907b0a5c8.js\"],\"default\",1]\n8:I[4707,[],\"\"]\n9:I[36423,[],\"\"]\nb:I[61060,[],\"\"]\nc:[]\n"])</script><script>self.__next_f.push([1,"0:[\"$\",\"$L4\",null,{\"buildId\":\"cx_klKzFUqmg6FLvftwd4\",\"assetPrefix\":\"/litellm-asset-prefix\",\"urlParts\":[\"\",\"onboarding\"],\"initialTree\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{}]}]},\"$undefined\",\"$undefined\",true],\"initialSeedData\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{},[[\"$L5\",[\"$\",\"$L6\",null,{\"props\":{\"params\":{},\"searchParams\":{}},\"Component\":\"$7\"}],null],null],null]},[null,[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"onboarding\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\"}]],null]},[[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/litellm-asset-prefix/_next/static/css/31b7f215e119031e.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/litellm-asset-prefix/_next/static/css/618290a32b9bb91a.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"children\":[\"$\",\"body\",null,{\"className\":\"__className_b0dd8a\",\"children\":[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"padding\":\"0 23px 0 0\",\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\",\"lineHeight\":\"49px\"},\"children\":\"404\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"49px\",\"margin\":0},\"children\":\"This page could not be found.\"}]}]]}]}]],\"notFoundStyles\":[]}]}]}]],null],null],\"couldBeIntercepted\":false,\"initialHead\":[null,\"$La\"],\"globalErrorComponent\":\"$b\",\"missingSlots\":\"$Wc\"}]\n"])</script><script>self.__next_f.push([1,"a:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}],[\"$\",\"meta\",\"1\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"2\",{\"children\":\"LiteLLM Dashboard\"}],[\"$\",\"meta\",\"3\",{\"name\":\"description\",\"content\":\"LiteLLM Proxy Admin UI\"}],[\"$\",\"link\",\"4\",{\"rel\":\"icon\",\"href\":\"/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"16x16\"}],[\"$\",\"link\",\"5\",{\"rel\":\"icon\",\"href\":\"./favicon.ico\"}],[\"$\",\"meta\",\"6\",{\"name\":\"next-size-adjust\"}]]\n5:null\n"])</script></body></html>\ No newline at end of filediff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex c7bf8cdb0ab..d02002aeff8 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -3,7 +3,7 @@ model_list:litellm_params:model: openai/fakeapi_key: fake-key- api_base: https://exampleopenaiendpoint-production.up.railway.app/+ api_base: https://webhook.site/4feb0d46-4b23-468c-bf55-7008b5deb36d- model_name: gpt-5-minilitellm_params:model: azure/gpt-5-mini@@ -20,3 +20,7 @@ litellm_settings:type: redisttl: 600supported_call_types: ["acompletion", "completion"]++ model_group_settings:+ forward_client_headers_to_llm_api:+ - fake-openai-endpointdiff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.pyindex aaeb86e34cc..adec337351c 100644--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@ -384,6 +384,29 @@ class LiteLLMProxyRequestSetup:return returned_headers+ @staticmethod+ def add_headers_to_llm_call_by_model_group(+ data: dict, headers: dict, user_api_key_dict: UserAPIKeyAuth+ ) -> dict:+ """+ Add headers to the LLM call by model group+ """+ data_model = data.get("model")+ if (+ data_model is not None+ and litellm.model_group_settings is not None+ and litellm.model_group_settings.forward_client_headers_to_llm_api+ is not None+ and data_model+ in litellm.model_group_settings.forward_client_headers_to_llm_api+ ):+ _headers = LiteLLMProxyRequestSetup.add_headers_to_llm_call(+ headers, user_api_key_dict+ )+ if _headers != {}:+ data["headers"] = _headers+ return data+@staticmethoddef add_litellm_data_for_backend_llm_call(*,@@ -439,7 +462,7 @@ class LiteLLMProxyRequestSetup:user_api_key_request_route=user_api_key_dict.request_route,)return user_api_key_logged_metadata-+@staticmethoddef add_user_api_key_auth_to_request_metadata(data: dict,@@ -457,9 +480,7 @@ class LiteLLMProxyRequestSetup:data[_metadata_variable_name].update(user_api_key_logged_metadata)data[_metadata_variable_name]["user_api_key"- ] = (- user_api_key_dict.api_key- ) # this is just the hashed token+ ] = user_api_key_dict.api_key # this is just the hashed tokendata[_metadata_variable_name]["user_api_end_user_max_budget"] = getattr(user_api_key_dict, "end_user_max_budget", None@@ -624,6 +645,11 @@ async def add_litellm_data_to_request( # noqa: PLR0915))+ # check for forwardable headers+ data = LiteLLMProxyRequestSetup.add_headers_to_llm_call_by_model_group(+ data=data, headers=_headers, user_api_key_dict=user_api_key_dict+ )+# Parse user info from headersuser = LiteLLMProxyRequestSetup.get_user_from_headers(_headers, general_settings)if user is not None:diff --git a/litellm/router.py b/litellm/router.pyindex 38de80141e9..174b26b92f5 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -624,9 +624,7 @@ class Router:Apply the default settings to the router."""- default_pre_call_checks: OptionalPreCallChecks = [- "forward_client_headers_by_model_group",- ]+ default_pre_call_checks: OptionalPreCallChecks = []self.add_optional_pre_call_checks(default_pre_call_checks)return None@@ -892,8 +890,6 @@ class Router:)elif pre_call_check == "responses_api_deployment_check":_callback = ResponsesApiDeploymentCheck()- elif pre_call_check == "forward_client_headers_by_model_group":- _callback = ForwardClientSideHeadersByModelGroup()if _callback is not None:if self.optional_callbacks is None:self.optional_callbacks = []@@ -4323,7 +4319,9 @@ class Router:"deployment", None) # stable name - works for wildcard routes as well# Get model_group and id from kwargs like the sync version does- model_group = kwargs["litellm_params"]["metadata"].get("model_group", None)+ model_group = kwargs["litellm_params"]["metadata"].get(+ "model_group", None+ )model_info = kwargs["litellm_params"].get("model_info", {}) or {}id = model_info.get("id", None)if model_group is None or id is None:diff --git a/litellm/router_utils/forward_clientside_headers_by_model_group.py b/litellm/router_utils/forward_clientside_headers_by_model_group.pydeleted file mode 100644index 2e1a066a6cc..00000000000--- a/litellm/router_utils/forward_clientside_headers_by_model_group.py+++ /dev/null@@ -1,84 +0,0 @@-from typing import Any, Dict, Optional, TypedDict--from litellm.types.utils import CallTypes--from ..integrations.custom_logger import CustomLogger---class PotentialModelGroups(TypedDict):- deployment_model_name: Optional[str]- model_group_alias: Optional[str]---class ForwardClientSideHeadersByModelGroup(CustomLogger):- def get_potential_model_groups_from_kwargs(- self, kwargs: Dict[str, Any]- ) -> Optional[PotentialModelGroups]:- """- Get the model group from the kwargs.-- Returns the potential model groups from the kwargs.- - deployment_model_name (useful for wildcard model names)- - model_group_alias (if the model is an alias)- """- metadata = kwargs.get("litellm_metadata") or kwargs.get("metadata")- if metadata is None:- return None- deployment_model_name = metadata.get("deployment_model_name", None)- model_group_alias = metadata.get("model_group_alias", None)- return {- "deployment_model_name": deployment_model_name,- "model_group_alias": model_group_alias,- }-- def filter_headers(self, headers: Dict[str, Any]) -> Dict[str, Any]:- """- Filter the headers to only include the headers that are forwarded to the LLM API.-- E.g. passing 'connection': 'keep-alive' will cause the request to hang, and not be acknowledged on the other side.- """- return {- k: v- for k, v in headers.items()- if k.lower() not in ["connection", "content-length"]- }-- async def async_pre_call_deployment_hook(- self, kwargs: Dict[str, Any], call_type: Optional[CallTypes]- ) -> Optional[dict]:- """- if kwargs["proxy_server_request"]["headers"] is not None:- and kwargs["forward_client_headers_to_llm_api"] is not None:-- add the headers to the request- kwargs["headers"].update(kwargs["proxy_server_request"]["headers"])- """- import litellm-- if litellm.model_group_settings is None:- return None-- potential_model_groups = self.get_potential_model_groups_from_kwargs(kwargs)-- if potential_model_groups is None:- return None-- if (- "secret_fields" in kwargs- and kwargs["secret_fields"]["raw_headers"] is not None- and isinstance(kwargs["secret_fields"]["raw_headers"], dict)- ):- for model_group in potential_model_groups.values():- if model_group is None:- continue- if (- litellm.model_group_settings.forward_client_headers_to_llm_api- is not None- and model_group- in litellm.model_group_settings.forward_client_headers_to_llm_api- ):- kwargs.setdefault("headers", {}).update(- self.filter_headers(kwargs["secret_fields"]["raw_headers"])- )-- return kwargs