From 36916852ad9d0ab04e31a9a09e8820c2314341d7 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 24 May 2024 15:37:36 -0700 Subject: [PATCH] fix - user_id_information --- litellm/proxy/proxy_server.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 565bf47fc14..9e1230c3895 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1062,11 +1062,18 @@ async def user_api_key_auth( # Check 4. Token Spend is under budget if valid_token.spend is not None and valid_token.max_budget is not None: - # collect information for alerting - if isinstance(user_id_information, list): - user_id_information = user_id_information[0] - user_email = user_id_information.get("user_email", None) + #################################### + # collect information for alerting # + #################################### + + user_email = None + # Check if the token has any user id information + if user_id_information is not None: + if isinstance(user_id_information, list): + user_id_information = user_id_information[0] + user_email = user_id_information.get("user_email", None) + call_info = CallInfo( token=valid_token.token, spend=valid_token.spend, @@ -1083,6 +1090,10 @@ async def user_api_key_auth( ) ) + #################################### + # collect information for alerting # + #################################### + if valid_token.spend >= valid_token.max_budget: raise Exception( f"ExceededTokenBudget: Current spend for token: {valid_token.spend}; Max Budget for Token: {valid_token.max_budget}"