diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py index d3e937734c..bc774816f6 100644 --- a/litellm/proxy/auth/user_api_key_auth.py +++ b/litellm/proxy/auth/user_api_key_auth.py @@ -1129,12 +1129,15 @@ async def user_api_key_auth( if isinstance(e, litellm.BudgetExceededError): raise ProxyException( - message=e.message, type="auth_error", param=None, code=400 + message=e.message, + type=ProxyErrorTypes.budget_exceeded, + param=None, + code=400, ) if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_401_UNAUTHORIZED), ) @@ -1142,7 +1145,7 @@ async def user_api_key_auth( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_401_UNAUTHORIZED, ) diff --git a/litellm/proxy/management_endpoints/internal_user_endpoints.py b/litellm/proxy/management_endpoints/internal_user_endpoints.py index 9cece646d2..6bf2102d51 100644 --- a/litellm/proxy/management_endpoints/internal_user_endpoints.py +++ b/litellm/proxy/management_endpoints/internal_user_endpoints.py @@ -422,7 +422,7 @@ async def user_info( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -430,7 +430,7 @@ async def user_info( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -523,7 +523,7 @@ async def user_update(data: UpdateUserRequest): if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -531,7 +531,7 @@ async def user_update(data: UpdateUserRequest): raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -582,7 +582,7 @@ async def user_request_model(request: Request): if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -590,7 +590,7 @@ async def user_request_model(request: Request): raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -630,7 +630,7 @@ async def user_get_requests(): if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -638,7 +638,7 @@ async def user_get_requests(): raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index b1ad015080..03028821f0 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -261,7 +261,7 @@ async def generate_key_fn( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -269,7 +269,7 @@ async def generate_key_fn( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -374,7 +374,7 @@ async def update_key_fn( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -382,7 +382,7 @@ async def update_key_fn( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -427,7 +427,7 @@ async def delete_key_fn( if len(keys) == 0: raise ProxyException( message=f"No keys provided, passed in: keys={keys}", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="keys", code=status.HTTP_400_BAD_REQUEST, ) @@ -505,7 +505,7 @@ async def delete_key_fn( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -513,7 +513,7 @@ async def delete_key_fn( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -580,7 +580,7 @@ async def info_key_fn_v2( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -588,7 +588,7 @@ async def info_key_fn_v2( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -652,7 +652,7 @@ async def info_key_fn( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -660,7 +660,7 @@ async def info_key_fn( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index b05cd2505a..08994a957e 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -5989,7 +5989,7 @@ async def add_new_model( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -5997,7 +5997,7 @@ async def add_new_model( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -6105,7 +6105,7 @@ async def update_model( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -6113,7 +6113,7 @@ async def update_model( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -6903,7 +6903,7 @@ async def delete_model(model_info: ModelInfoDelete): if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -6911,7 +6911,7 @@ async def delete_model(model_info: ModelInfoDelete): raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -7141,7 +7141,7 @@ async def async_queue_request( if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -7149,7 +7149,7 @@ async def async_queue_request( raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -7180,7 +7180,7 @@ async def google_login(request: Request): if premium_user != True: raise ProxyException( message="You must be a LiteLLM Enterprise user to use SSO. If you have a license please set `LITELLM_LICENSE` in your env. If you want to obtain a license meet with us here: https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat You are seeing this error message because You set one of `MICROSOFT_CLIENT_ID`, `GOOGLE_CLIENT_ID`, or `GENERIC_CLIENT_ID` in your env. Please unset this", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="premium_user", code=status.HTTP_403_FORBIDDEN, ) @@ -7205,7 +7205,7 @@ async def google_login(request: Request): if google_client_secret is None: raise ProxyException( message="GOOGLE_CLIENT_SECRET not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GOOGLE_CLIENT_SECRET", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7228,7 +7228,7 @@ async def google_login(request: Request): if microsoft_client_secret is None: raise ProxyException( message="MICROSOFT_CLIENT_SECRET not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="MICROSOFT_CLIENT_SECRET", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7254,28 +7254,28 @@ async def google_login(request: Request): if generic_client_secret is None: raise ProxyException( message="GENERIC_CLIENT_SECRET not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_CLIENT_SECRET", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) if generic_authorization_endpoint is None: raise ProxyException( message="GENERIC_AUTHORIZATION_ENDPOINT not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_AUTHORIZATION_ENDPOINT", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) if generic_token_endpoint is None: raise ProxyException( message="GENERIC_TOKEN_ENDPOINT not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_TOKEN_ENDPOINT", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) if generic_userinfo_endpoint is None: raise ProxyException( message="GENERIC_USERINFO_ENDPOINT not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_USERINFO_ENDPOINT", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7360,7 +7360,7 @@ async def login(request: Request): if master_key is None: raise ProxyException( message="Master Key not set for Proxy. Please set Master Key to use Admin UI. Set `LITELLM_MASTER_KEY` in .env or set general_settings:master_key in config.yaml. https://docs.litellm.ai/docs/proxy/virtual_keys. If set, use `--detailed_debug` to debug issue.", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="master_key", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7374,7 +7374,7 @@ async def login(request: Request): if ui_password is None: raise ProxyException( message="set Proxy master key to use UI. https://docs.litellm.ai/docs/proxy/virtual_keys. If set, use `--detailed_debug` to debug issue.", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="UI_PASSWORD", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7433,7 +7433,7 @@ async def login(request: Request): else: raise ProxyException( message="No Database connected. Set DATABASE_URL in .env. If set, use `--detailed_debug` to debug issue.", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="DATABASE_URL", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7497,7 +7497,7 @@ async def login(request: Request): else: raise ProxyException( message="No Database connected. Set DATABASE_URL in .env. If set, use `--detailed_debug` to debug issue.", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="DATABASE_URL", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7530,14 +7530,14 @@ async def login(request: Request): else: raise ProxyException( message=f"Invalid credentials used to access UI. Passed in username: {username}, passed in password: {password}.\nNot valid credentials for {username}", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="invalid_credentials", code=status.HTTP_401_UNAUTHORIZED, ) else: raise ProxyException( message=f"Invalid credentials used to access UI. Passed in username: {username}, passed in password: {password}.\nCheck 'UI_USERNAME', 'UI_PASSWORD' in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="invalid_credentials", code=status.HTTP_401_UNAUTHORIZED, ) @@ -7569,7 +7569,7 @@ async def onboarding(invite_link: str): if master_key is None: raise ProxyException( message="Master Key not set for Proxy. Please set Master Key to use Admin UI. Set `LITELLM_MASTER_KEY` in .env or set general_settings:master_key in config.yaml. https://docs.litellm.ai/docs/proxy/virtual_keys. If set, use `--detailed_debug` to debug issue.", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="master_key", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7784,7 +7784,7 @@ async def auth_callback(request: Request): if master_key is None: raise ProxyException( message="Master Key not set for Proxy. Please set Master Key to use Admin UI. Set `LITELLM_MASTER_KEY` in .env or set general_settings:master_key in config.yaml. https://docs.litellm.ai/docs/proxy/virtual_keys. If set, use `--detailed_debug` to debug issue.", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="master_key", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7800,7 +7800,7 @@ async def auth_callback(request: Request): if google_client_secret is None: raise ProxyException( message="GOOGLE_CLIENT_SECRET not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GOOGLE_CLIENT_SECRET", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7818,14 +7818,14 @@ async def auth_callback(request: Request): if microsoft_client_secret is None: raise ProxyException( message="MICROSOFT_CLIENT_SECRET not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="MICROSOFT_CLIENT_SECRET", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) if microsoft_tenant is None: raise ProxyException( message="MICROSOFT_TENANT not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="MICROSOFT_TENANT", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -7854,28 +7854,28 @@ async def auth_callback(request: Request): if generic_client_secret is None: raise ProxyException( message="GENERIC_CLIENT_SECRET not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_CLIENT_SECRET", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) if generic_authorization_endpoint is None: raise ProxyException( message="GENERIC_AUTHORIZATION_ENDPOINT not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_AUTHORIZATION_ENDPOINT", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) if generic_token_endpoint is None: raise ProxyException( message="GENERIC_TOKEN_ENDPOINT not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_TOKEN_ENDPOINT", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) if generic_userinfo_endpoint is None: raise ProxyException( message="GENERIC_USERINFO_ENDPOINT not set. Set it in .env file", - type="auth_error", + type=ProxyErrorTypes.auth_error, param="GENERIC_USERINFO_ENDPOINT", code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) @@ -8446,7 +8446,7 @@ async def update_config(config_info: ConfigYAML): if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -8454,7 +8454,7 @@ async def update_config(config_info: ConfigYAML): raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, ) @@ -8916,7 +8916,7 @@ async def get_config(): if isinstance(e, HTTPException): raise ProxyException( message=getattr(e, "detail", f"Authentication Error({str(e)})"), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST), ) @@ -8924,7 +8924,7 @@ async def get_config(): raise e raise ProxyException( message="Authentication Error, " + str(e), - type="auth_error", + type=ProxyErrorTypes.auth_error, param=getattr(e, "param", "None"), code=status.HTTP_400_BAD_REQUEST, )