From 34ff0a7e57827fcf16d9e931b916fcbaac8eb2d4 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 12 Jul 2024 18:39:00 -0700 Subject: [PATCH 1/3] raise expired_key error --- litellm/proxy/_types.py | 1 + 1 file changed, 1 insertion(+) 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" From 57ced1d25ee3c7ae6b07580f7b96eebdf01832d9 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 12 Jul 2024 18:41:39 -0700 Subject: [PATCH 2/3] raise roxyErrorTypes.expired_key on expired key --- litellm/proxy/auth/user_api_key_auth.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 From 7918f41aca7a2e4192308e9cbe405752cecc39ba Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 12 Jul 2024 18:45:01 -0700 Subject: [PATCH 3/3] test expired key raises correct exception --- litellm/tests/test_key_generate_prisma.py | 2 ++ 1 file changed, 2 insertions(+) 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