Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(types): move is_jwt into litellm.types.proxy.auth.user_api_key_auth (#45747)

nate-berri7831d8a9915e
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index f60f0ddce8d..23f92280513 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -67,6 +67,7 @@ from litellm.types.proxy.agent_identity import ManagedAgentContext
from litellm.types.proxy.auth.special_headers import (
SpecialHeaders as SpecialHeaders, # noqa: PLC0414 # public re-export
)
+from litellm.types.proxy.auth.user_api_key_auth import is_jwt
from litellm.types.proxy.carried_budget_state import (
OrgBudgetSnapshot,
TeamBudgetSnapshot,
@@ -3482,9 +3483,7 @@ class UserAPIKeyAuth(LiteLLM_VerificationTokenView): # the expected response ob
normalized = normalized[7:]
if normalized.startswith("sk-"):
return hash_token(normalized)
- from litellm.proxy.auth.handle_jwt import JWTHandler
-
- if JWTHandler.is_jwt(token=normalized):
+ if is_jwt(token=normalized):
return f"hashed-jwt-{hash_token(token=normalized)}"
return normalized
diff --git a/litellm/proxy/auth/handle_jwt.py b/litellm/proxy/auth/handle_jwt.py
index a57eacdd133..3283a080c14 100644
--- a/litellm/proxy/auth/handle_jwt.py
+++ b/litellm/proxy/auth/handle_jwt.py
@@ -75,6 +75,7 @@ from litellm.repositories.user_repository import UserRepository
from litellm.types.agents import AgentResponse
from litellm.types.proxy.agent_identity import AgentIdentityFailure
from litellm.types.proxy.auth.auth_checks import UserNotFoundError
+from litellm.types.proxy.auth.user_api_key_auth import is_jwt as is_jwt_token
from .auth_checks import (
TeamNotFoundError,
@@ -276,10 +277,7 @@ class JWTHandler:
@staticmethod
def is_jwt(token: str | None) -> bool:
- if token is None:
- return False
- parts: Final = token.split(".")
- return len(parts) == 3
+ return is_jwt_token(token=token)
@staticmethod
def get_unverified_claims(token: str) -> dict | None:
diff --git a/litellm/types/proxy/auth/user_api_key_auth.py b/litellm/types/proxy/auth/user_api_key_auth.py
new file mode 100644
index 00000000000..3d879fdcc43
--- /dev/null
+++ b/litellm/types/proxy/auth/user_api_key_auth.py
@@ -0,0 +1,8 @@
+from typing import Final
+
+
+def is_jwt(token: str | None) -> bool:
+ if token is None:
+ return False
+ parts: Final = token.split(".")
+ return len(parts) == 3