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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
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.pyindex f60f0ddce8d..23f92280513 100644--- a/litellm/proxy/_types.py+++ b/litellm/proxy/_types.py@@ -67,6 +67,7 @@ from litellm.types.proxy.agent_identity import ManagedAgentContextfrom 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_jwtfrom litellm.types.proxy.carried_budget_state import (OrgBudgetSnapshot,TeamBudgetSnapshot,@@ -3482,9 +3483,7 @@ class UserAPIKeyAuth(LiteLLM_VerificationTokenView): # the expected response obnormalized = 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 normalizeddiff --git a/litellm/proxy/auth/handle_jwt.py b/litellm/proxy/auth/handle_jwt.pyindex 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 UserRepositoryfrom litellm.types.agents import AgentResponsefrom litellm.types.proxy.agent_identity import AgentIdentityFailurefrom litellm.types.proxy.auth.auth_checks import UserNotFoundError+from litellm.types.proxy.auth.user_api_key_auth import is_jwt as is_jwt_tokenfrom .auth_checks import (TeamNotFoundError,@@ -276,10 +277,7 @@ class JWTHandler:@staticmethoddef 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)@staticmethoddef 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.pynew file mode 100644index 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