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
Ensure disable_llm_api_endpoints works + Add wildcard model support for 'team-byok' model (#13278)
Krish Dholakiaeb49f987de72
diff --git a/enterprise/litellm_enterprise/proxy/auth/route_checks.py b/enterprise/litellm_enterprise/proxy/auth/route_checks.pyindex 1d4bfc664d5..6cce781faf3 100644--- a/enterprise/litellm_enterprise/proxy/auth/route_checks.py+++ b/enterprise/litellm_enterprise/proxy/auth/route_checks.py@@ -20,7 +20,6 @@ class EnterpriseRouteChecks:status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,detail=f"🚨🚨🚨 DISABLING LLM API ENDPOINTS is an Enterprise feature\n🚨 {CommonProxyErrors.not_premium_user.value}",)- return Falsereturn get_secret_bool("DISABLE_LLM_API_ENDPOINTS") is Truediff --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 f30076137a2..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/fe37e928fd602d9e.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\",\"416\",\"static/chunks/416-ad6bd55a20a586bd.js\",\"154\",\"static/chunks/154-78c3416dcb61977f.js\",\"461\",\"static/chunks/app/onboarding/page-883c32e6b072b842.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\":\"rkJYRcYqQ8OBbL83KQCc4\",\"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/fe37e928fd602d9e.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 ad4dabf9d04..b587913a08a 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -2,27 +2,4 @@ model_list:- model_name: openai-testlitellm_params:model: gpt-3.5-turbo- api_key: os.environ/OPENAI_API_KEY--guardrails:- - guardrail_name: azure-text-moderation- litellm_params:- guardrail: azure/text_moderations- mode: "post_call"- api_key: os.environ/AZURE_GUARDRAIL_API_KEY- api_base: os.environ/AZURE_GUARDRAIL_API_BASE--prompts:- - prompt_id: test_my_json_prompt- litellm_params:- prompt_integration: dotprompt- prompt_id: test_hello_world_prompt- prompt_file: /Users/krrishdholakia/Documents/litellm/litellm/proxy/test_prompts/test_hello_world_prompt.prompt- - prompt_id: test_hello_world_prompt_2- litellm_params:- prompt_integration: dotprompt- prompt_id: test_hello_world_prompt_2- prompt_file: /Users/krrishdholakia/Documents/litellm/litellm/proxy/test_prompts/test_hello_world_prompt.prompt--litellm_settings:- callbacks: ["datadog_llm_observability"]\ No newline at end of file+ api_key: os.environ/OPENAI_API_KEY\ No newline at end of filediff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.pyindex 32ba2080a36..89c012c20ae 100644--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@ -288,9 +288,6 @@ def _is_api_route_allowed(if valid_token is None:raise Exception("Invalid proxy server token passed. valid_token=None.")- # Check if management routes are disabled and raise exception if they are- RouteChecks.should_call_route(route=route, valid_token=valid_token)-if not _is_user_proxy_admin(user_obj=user_obj): # if non-adminRouteChecks.non_proxy_admin_allowed_routes_check(user_obj=user_obj,diff --git a/litellm/proxy/auth/route_checks.py b/litellm/proxy/auth/route_checks.pyindex cd158fd70a7..e4d4f321159 100644--- a/litellm/proxy/auth/route_checks.py+++ b/litellm/proxy/auth/route_checks.py@@ -25,6 +25,8 @@ class RouteChecks:from litellm_enterprise.proxy.auth.route_checks import EnterpriseRouteChecksEnterpriseRouteChecks.should_call_route(route=route)+ except HTTPException as e:+ raise eexcept Exception:pass@@ -386,7 +388,7 @@ class RouteChecks:if "thread" in request.url.path or "assistant" in request.url.path:return Truereturn False-+@staticmethoddef is_generate_content_route(route: str) -> bool:"""diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.pyindex 31395fe7da0..00711afee70 100644--- a/litellm/proxy/auth/user_api_key_auth.py+++ b/litellm/proxy/auth/user_api_key_auth.py@@ -49,6 +49,7 @@ from litellm.proxy.auth.auth_utils import (from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandlerfrom litellm.proxy.auth.oauth2_check import check_oauth2_tokenfrom litellm.proxy.auth.oauth2_proxy_hook import handle_oauth2_proxy_request+from litellm.proxy.auth.route_checks import RouteChecksfrom litellm.proxy.common_utils.http_parsing_utils import (_read_request_body,_safe_get_request_headers,@@ -259,6 +260,7 @@ def get_api_key(from litellm.proxy.common_utils.http_parsing_utils import (_safe_get_request_query_params,)+api_key = api_keypassed_in_key: Optional[str] = Noneif isinstance(custom_litellm_key_header, str):@@ -279,7 +281,11 @@ def get_api_key(elif isinstance(azure_apim_header, str):passed_in_key = azure_apim_headerapi_key = azure_apim_header- elif RouteChecks.is_generate_content_route(route=route) and request is not None and _safe_get_request_query_params(request).get("key"):+ elif (+ RouteChecks.is_generate_content_route(route=route)+ and request is not None+ and _safe_get_request_query_params(request).get("key")+ ):google_auth_key: str = _safe_get_request_query_params(request).get("key") or ""passed_in_key = google_auth_keyapi_key = google_auth_key@@ -1141,6 +1147,8 @@ async def user_api_key_auth(request_data = await _read_request_body(request=request)route: str = get_request_route(request=request)+ ## CHECK IF ROUTE IS ALLOWED+user_api_key_auth_obj = await _user_api_key_auth_builder(request=request,api_key=api_key,@@ -1152,6 +1160,9 @@ async def user_api_key_auth(custom_litellm_key_header=custom_litellm_key_header,)+ ## ENSURE DISABLE ROUTE WORKS ACROSS ALL USER AUTH FLOWS ##+ RouteChecks.should_call_route(route=route, valid_token=user_api_key_auth_obj)+end_user_id = get_end_user_id_from_request_body(request_data, _safe_get_request_headers(request))diff --git a/litellm/router.py b/litellm/router.pyindex ca724006fdf..b89815877b5 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -406,6 +406,9 @@ class Router:self.default_max_parallel_requests = default_max_parallel_requestsself.provider_default_deployment_ids: List[str] = []self.pattern_router = PatternMatchRouter()+ self.team_pattern_routers: Dict[str, PatternMatchRouter] = (+ {}+ ) # {"TEAM_ID": PatternMatchRouter}self.auto_routers: Dict[str, "AutoRouter"] = {}if model_list is not None:@@ -1207,7 +1210,7 @@ class Router:verbose_router_logger.error(f"Fallback also failed: {fallback_error}")- raise fallback_error+ raise fallback_errorreturn FallbackStreamWrapper(stream_with_fallbacks())@@ -5109,6 +5112,19 @@ class Router:if deployment.model_info.id:self.provider_default_deployment_ids.append(deployment.model_info.id)+ _team_id = deployment.model_info.get("team_id")+ _team_public_model_name = deployment.model_info.get("team_public_model_name")+ if (+ _team_id is not None+ and _team_public_model_name is not None+ and "*" in _team_public_model_name+ ):+ if _team_id not in self.team_pattern_routers:+ self.team_pattern_routers[_team_id] = PatternMatchRouter()+ self.team_pattern_routers[_team_id].add_pattern(+ _team_public_model_name, deployment.to_json(exclude_none=True)+ )+# Azure GPT-Vision Enhancements, users can pass os.environ/data_sources = deployment.litellm_params.get("dataSources", []) or []@@ -5920,19 +5936,17 @@ class Router:Map a team model name to a team-specific model name.Returns:- - team_model_name: str - the team-specific model name+ - deployment id: str - the deployment id of the team-specific model- None: if no team-specific model name is found"""- for model in self.model_list:- model_team_id = model["model_info"].get("team_id")- model_team_public_model_name = model["model_info"].get(- "team_public_model_name"- )- if (- model_team_id == team_id- and model_team_public_model_name == team_model_name- ):- return model["model_name"]+ models = self.get_model_list(model_name=team_model_name, team_id=team_id)+ if not models:+ return None+ for model in models:+ if model.get("model_info", {}).get("team_id") == team_id:+ return model.get("model_name")++ ## wildcard modelsreturn Nonedef should_include_deployment(@@ -6073,6 +6087,7 @@ class Router:if team_id specified, returns matching team-specific models"""+if hasattr(self, "model_list"):returned_models: List[DeploymentTypedDict] = []@@ -6087,7 +6102,17 @@ class Router:)if len(returned_models) == 0: # check if wildcard route- potential_wildcard_models = self.pattern_router.route(model_name)+ potential_wildcard_models = self.pattern_router.route(model_name) or []++ ## check for team-specific wildcard models+ if team_id is not None and team_id in self.team_pattern_routers:+ potential_team_only_wildcard_models = (+ self.team_pattern_routers[team_id].route(model_name) or []+ )+ potential_wildcard_models.extend(+ potential_team_only_wildcard_models+ )+if model_name is not None and potential_wildcard_models is not None:for m in potential_wildcard_models:deployment_typed_dict = DeploymentTypedDict(**m) # type: ignore@@ -6519,6 +6544,7 @@ class Router:messages: Optional[List[Dict[str, str]]] = None,input: Optional[Union[str, List]] = None,specific_deployment: Optional[bool] = False,+ request_kwargs: Optional[Dict] = None,) -> Tuple[str, Union[List, Dict]]:"""Common checks for 'get_available_deployment' across sync + async call.@@ -6530,6 +6556,14 @@ class Router:- List, if multiple models chosen- Dict, if specific model chosen"""++ request_team_id: Optional[str] = None+ if request_kwargs is not None:+ metadata = request_kwargs.get("metadata") or {}+ litellm_metadata = request_kwargs.get("litellm_metadata") or {}+ request_team_id = metadata.get(+ "user_api_key_team_id"+ ) or litellm_metadata.get("user_api_key_team_id")# check if aliases set on litellm model alias mapif specific_deployment is True:return model, self._get_deployment_by_litellm_model(model=model)@@ -6552,9 +6586,22 @@ class Router:pattern_deployments = self.pattern_router.get_deployments_by_pattern(model=model,)+if pattern_deployments:return model, pattern_deployments+ if (+ request_team_id is not None+ and request_team_id in self.team_pattern_routers+ ):+ pattern_deployments = self.team_pattern_routers[+ request_team_id+ ].get_deployments_by_pattern(+ model=model,+ )+ if pattern_deployments:+ return model, pattern_deployments+# check if default deployment is setif self.default_deployment is not None:updated_deployment = copy.deepcopy(@@ -6622,6 +6669,7 @@ class Router:messages=messages,input=input,specific_deployment=specific_deployment,+ request_kwargs=request_kwargs,) # type: ignore# IF TEAM ID SPECIFIED ON MODEL, AND REQUEST CONTAINS USER_API_KEY_TEAM_ID, FILTER OUT MODELS THAT ARE NOT IN THE TEAMdiff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.pyindex e8b6567a97d..0a6ea31a1ba 100644--- a/tests/test_litellm/test_router.py+++ b/tests/test_litellm/test_router.py@@ -1357,3 +1357,47 @@ async def test_async_function_with_fallbacks_common_utils():args=(),kwargs={}, # No model key)+++def test_should_include_deployment():+ """Test that Router.should_include_deployment returns the correct response"""+ router = litellm.Router(+ model_list=[+ {+ "model_name": "model_name_a28a12f9-3e44-4861-bd4f-325f2d309ce8_cd5dc6fb-b046-4e05-ae1d-32ba4d936266",+ "litellm_params": {"model": "openai/*"},+ "model_info": {+ "team_id": "a28a12f9-3e44-4861-bd4f-325f2d309ce8",+ "team_public_model_name": "openai/*",+ },+ }+ ],+ )++ model = {+ "model_name": "model_name_a28a12f9-3e44-4861-bd4f-325f2d309ce8_cd5dc6fb-b046-4e05-ae1d-32ba4d936266",+ "litellm_params": {+ "api_key": "sk-proj-1234567890",+ "custom_llm_provider": "openai",+ "use_in_pass_through": False,+ "use_litellm_proxy": False,+ "merge_reasoning_content_in_choices": False,+ "model": "openai/*",+ },+ "model_info": {+ "id": "95f58039-d54a-4d1c-b700-5e32e99a1120",+ "db_model": True,+ "updated_by": "64a2f787-0863-4d76-9516-2dc49c1598e8",+ "created_by": "64a2f787-0863-4d76-9516-2dc49c1598e8",+ "team_id": "a28a12f9-3e44-4861-bd4f-325f2d309ce8",+ "team_public_model_name": "openai/*",+ "mode": "completion",+ "access_groups": ["restricted-models-openai"],+ },+ }+ model_name = "openai/o4-mini-deep-research"+ team_id = "a28a12f9-3e44-4861-bd4f-325f2d309ce8"+ assert router.get_model_list(+ model_name=model_name,+ team_id=team_id,+ )