diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py index 5531f2af7ef..53069a1c2ae 100644 --- a/litellm/proxy/auth/user_api_key_auth.py +++ b/litellm/proxy/auth/user_api_key_auth.py @@ -622,7 +622,10 @@ async def _resolve_jwt_to_virtual_key( status_code=403, detail=f"JWT Key Mapping: No registered mapping for {virtual_key_claim_field}='{claim_value}'. Access denied.", ) - if behavior == UnregisteredJWTClientBehavior.AUTO_REGISTER and prisma_client is not None: + if ( + behavior == UnregisteredJWTClientBehavior.AUTO_REGISTER + and prisma_client is not None + ): # Stale sentinel written under a prior fallback_team_mapping config — # evict it and auto-register now that the policy has changed. await user_api_key_cache.async_delete_cache(cache_key) @@ -846,11 +849,8 @@ async def _user_api_key_auth_builder( # noqa: PLR0915 # Routing uses unverified JWT claims only to choose auth path. # Final authentication is enforced by the selected validator. - route_jwt_to_oauth2 = ( - is_jwt - and _should_route_jwt_to_oauth2_override( - token=api_key, jwt_handler=jwt_handler - ) + route_jwt_to_oauth2 = is_jwt and _should_route_jwt_to_oauth2_override( + token=api_key, jwt_handler=jwt_handler ) # OAuth2 applies for: @@ -866,6 +866,7 @@ async def _user_api_key_auth_builder( # noqa: PLR0915 ) if (should_apply_global_oauth2 and not is_jwt) or should_apply_override_oauth2: from litellm.proxy.proxy_server import premium_user + if premium_user is not True: raise ValueError( "Oauth2 token validation is only available for premium users" @@ -893,10 +894,7 @@ async def _user_api_key_auth_builder( # noqa: PLR0915 if jwt_handler.litellm_jwtauth.virtual_key_claim_field is not None: # Decode JWT to get claims without running full auth_builder jwt_claims: Optional[dict] - if ( - jwt_handler.litellm_jwtauth.oidc_userinfo_enabled - and not is_jwt - ): + if jwt_handler.litellm_jwtauth.oidc_userinfo_enabled and not is_jwt: jwt_claims = await jwt_handler.get_oidc_userinfo(token=api_key) else: jwt_claims = await jwt_handler.auth_jwt(token=api_key) @@ -1131,9 +1129,9 @@ async def _user_api_key_auth_builder( # noqa: PLR0915 route=route, ) if _end_user_object is not None: - end_user_params[ - "allowed_model_region" - ] = _end_user_object.allowed_model_region + end_user_params["allowed_model_region"] = ( + _end_user_object.allowed_model_region + ) if _end_user_object.litellm_budget_table is not None: _apply_budget_limits_to_end_user_params( end_user_params=end_user_params, @@ -1687,9 +1685,9 @@ async def _user_api_key_auth_builder( # noqa: PLR0915 if _end_user_object is not None: valid_token_dict.update(end_user_params) - valid_token_dict[ - "end_user_object_permission" - ] = _end_user_object.object_permission + valid_token_dict["end_user_object_permission"] = ( + _end_user_object.object_permission + ) # check if token is from litellm-ui, litellm ui makes keys to allow users to login with sso. These keys can only be used for LiteLLM UI functions # sso/login, ui/login, /key functions and /user functions @@ -1952,12 +1950,9 @@ async def _enforce_key_and_fallback_model_access( if config != {}: model_list = config.get("model_list", []) new_model_list = model_list - verbose_proxy_logger.debug( - f"\n new llm router model list {new_model_list}" - ) + verbose_proxy_logger.debug(f"\n new llm router model list {new_model_list}") elif ( - isinstance(valid_token.models, list) - and "all-team-models" in valid_token.models + isinstance(valid_token.models, list) and "all-team-models" in valid_token.models ): pass else: