diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index c3bffc516ca..f188801e093 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -1664,4 +1664,5 @@ class SpendCalculateRequest(LiteLLMBase): class ProxyErrorTypes(str, enum.Enum): budget_exceeded = "budget_exceeded" + expired_key = "expired_key" auth_error = "auth_error" diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py index 4b931a27268..d02ebe4ceb9 100644 --- a/litellm/proxy/auth/user_api_key_auth.py +++ b/litellm/proxy/auth/user_api_key_auth.py @@ -753,9 +753,11 @@ async def user_api_key_auth( ) if expiry_time < current_time: # Token exists but is expired. - raise HTTPException( - status_code=status.HTTP_403_FORBIDDEN, - detail=f"Authentication Error - Expired Key. Key Expiry time {expiry_time} and current time {current_time}", + raise ProxyException( + message=f"Authentication Error - Expired Key. Key Expiry time {expiry_time} and current time {current_time}", + type=ProxyErrorTypes.expired_key, + code=400, + param=api_key, ) # Check 4. Token Spend is under budget diff --git a/litellm/tests/test_key_generate_prisma.py b/litellm/tests/test_key_generate_prisma.py index 48e3689ddfb..0d1f488e1eb 100644 --- a/litellm/tests/test_key_generate_prisma.py +++ b/litellm/tests/test_key_generate_prisma.py @@ -941,6 +941,8 @@ def test_generate_and_call_with_expired_key(prisma_client): print("Got Exception", e) print(e.message) assert "Authentication Error" in e.message + assert e.type == ProxyErrorTypes.expired_key + pass