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(ui_sso.py): support experimental jwt keys for UI auth w/ SSO (#10326)
Krish Dholakia339351c579fe
diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.pyindex 4f53c037022..7414488bc8a 100644--- a/litellm/proxy/management_endpoints/ui_sso.py+++ b/litellm/proxy/management_endpoints/ui_sso.py@@ -40,7 +40,7 @@ from litellm.proxy._types import (TeamMemberAddRequest,UserAPIKeyAuth,)-from litellm.proxy.auth.auth_checks import get_user_object+from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken, get_user_objectfrom litellm.proxy.auth.auth_utils import _has_user_setup_ssofrom litellm.proxy.auth.handle_jwt import JWTHandlerfrom litellm.proxy.auth.user_api_key_auth import user_api_key_auth@@ -60,7 +60,7 @@ from litellm.proxy.management_endpoints.sso_helper_utils import (from litellm.proxy.management_endpoints.team_endpoints import new_team, team_member_addfrom litellm.proxy.management_endpoints.types import CustomOpenIDfrom litellm.proxy.utils import PrismaClient, ProxyLogging-from litellm.secret_managers.main import str_to_bool+from litellm.secret_managers.main import get_secret_bool, str_to_boolfrom litellm.types.proxy.management_endpoints.ui_sso import *if TYPE_CHECKING:@@ -621,6 +621,30 @@ async def auth_callback(request: Request): # noqa: PLR0915import jwt+ if get_secret_bool("EXPERIMENTAL_UI_LOGIN"):+ _user_info: Optional[LiteLLM_UserTable] = None+ if (+ user_defined_values is not None+ and user_defined_values["user_id"] is not None+ ):+ _user_info = LiteLLM_UserTable(+ user_id=user_defined_values["user_id"],+ user_role=user_defined_values["user_role"] or user_role,+ models=[],+ max_budget=litellm.max_ui_session_budget,+ )+ if _user_info is None:+ raise HTTPException(+ status_code=401,+ detail={+ "error": "User Information is required for experimental UI login"+ },+ )++ key = ExperimentalUIJWTToken.get_experimental_ui_login_jwt_auth_token(+ _user_info+ )+jwt_token = jwt.encode( # type: ignore{"user_id": user_id,diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 569887f0acc..5252cb9a973 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -809,9 +809,9 @@ model_max_budget_limiter = _PROXY_VirtualKeyModelMaxBudgetLimiter(dual_cache=user_api_key_cache)litellm.logging_callback_manager.add_litellm_callback(model_max_budget_limiter)-redis_usage_cache: Optional[RedisCache] = (- None # redis cache used for tracking spend, tpm/rpm limits-)+redis_usage_cache: Optional[+ RedisCache+] = None # redis cache used for tracking spend, tpm/rpm limitsuser_custom_auth = Noneuser_custom_key_generate = Noneuser_custom_sso = None@@ -1137,9 +1137,9 @@ async def update_cache( # noqa: PLR0915_id = "team_id:{}".format(team_id)try:# Fetch the existing cost for the given user- existing_spend_obj: Optional[LiteLLM_TeamTable] = (- await user_api_key_cache.async_get_cache(key=_id)- )+ existing_spend_obj: Optional[+ LiteLLM_TeamTable+ ] = await user_api_key_cache.async_get_cache(key=_id)if existing_spend_obj is None:# do nothing if team not in api key cachereturn@@ -2811,9 +2811,9 @@ async def initialize( # noqa: PLR0915user_api_base = api_basedynamic_config[user_model]["api_base"] = api_baseif api_version:- os.environ["AZURE_API_VERSION"] = (- api_version # set this for azure - litellm can read this from the env- )+ os.environ[+ "AZURE_API_VERSION"+ ] = api_version # set this for azure - litellm can read this from the envif max_tokens: # model-specific paramdynamic_config[user_model]["max_tokens"] = max_tokensif temperature: # model-specific param@@ -7791,9 +7791,9 @@ async def get_config_list(hasattr(sub_field_info, "description")and sub_field_info.description is not None):- nested_fields[idx].field_description = (- sub_field_info.description- )+ nested_fields[+ idx+ ].field_description = sub_field_info.descriptionidx += 1_stored_in_db = None