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]

fix linting

harish-berri3bff192c2f55
diff --git a/litellm/proxy/common_utils/user_api_key_cache.py b/litellm/proxy/common_utils/user_api_key_cache.py
index 7c42aa545d0..c6b830371ba 100644
--- a/litellm/proxy/common_utils/user_api_key_cache.py
+++ b/litellm/proxy/common_utils/user_api_key_cache.py
@@ -39,20 +39,22 @@ class UserApiKeyCache(DualCache):
@overload
def get_cache(
self,
- key,
- parent_otel_span=None,
+ key: Any,
+ parent_otel_span: Any = None,
local_only: bool = False,
- ) -> Any: ...
+ *,
+ model_type: Type[T],
+ **kwargs: Any,
+ ) -> Optional[T]: ...
@overload
def get_cache(
self,
- key,
- parent_otel_span=None,
+ key: Any,
+ parent_otel_span: Any = None,
local_only: bool = False,
- *,
- model_type: Type[T],
- ) -> Optional[T]: ...
+ **kwargs: Any,
+ ) -> Any: ...
def set_cache(self, key, value, local_only: bool = False, **kwargs): # type: ignore[override]
model_type = cast(Optional[Type[BaseModel]], kwargs.pop("model_type", None))
@@ -86,20 +88,22 @@ class UserApiKeyCache(DualCache):
@overload
async def async_get_cache(
self,
- key,
- parent_otel_span=None,
+ key: Any,
+ parent_otel_span: Any = None,
local_only: bool = False,
- ) -> Any: ...
+ *,
+ model_type: Type[T],
+ **kwargs: Any,
+ ) -> Optional[T]: ...
@overload
async def async_get_cache(
self,
- key,
- parent_otel_span=None,
+ key: Any,
+ parent_otel_span: Any = None,
local_only: bool = False,
- *,
- model_type: Type[T],
- ) -> Optional[T]: ...
+ **kwargs: Any,
+ ) -> Any: ...
def get_cache( # type: ignore[override]
self,
diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py
index 8129fb0de5e..ae38b389b46 100644
--- a/litellm/proxy/management_endpoints/key_management_endpoints.py
+++ b/litellm/proxy/management_endpoints/key_management_endpoints.py
@@ -27,7 +27,7 @@ from fastapi import APIRouter, Depends, Header, HTTPException, Query, Request, s
import litellm
from litellm._logging import verbose_proxy_logger
from litellm._uuid import uuid
-from litellm.caching import DualCache
+from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache
from litellm.constants import (
LENGTH_OF_LITELLM_GENERATED_KEY,
LITELLM_PROXY_ADMIN_NAME,
@@ -1058,7 +1058,7 @@ async def _check_project_key_limits(
project_id: str,
data: Union[GenerateKeyRequest, UpdateKeyRequest],
prisma_client: PrismaClient,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
) -> None:
"""
Validate that key's models and budget respect its project's limits.
@@ -1833,7 +1833,7 @@ async def _process_single_key_update(
user_api_key_dict: UserAPIKeyAuth,
litellm_changed_by: Optional[str],
prisma_client: Optional[PrismaClient],
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
proxy_logging_obj: Any,
llm_router: Optional[Router],
user_custom_key_update: Optional[Callable] = None,
@@ -3297,7 +3297,7 @@ async def _team_key_deletion_check(
user_api_key_dict: UserAPIKeyAuth,
key_info: LiteLLM_VerificationToken,
prisma_client: PrismaClient,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
):
is_team_key = _is_team_key(data=key_info)
@@ -3340,7 +3340,7 @@ async def _team_key_deletion_check(
async def can_modify_verification_token(
key_info: LiteLLM_VerificationToken,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
user_api_key_dict: UserAPIKeyAuth,
prisma_client: PrismaClient,
) -> bool:
@@ -3414,7 +3414,7 @@ async def can_modify_verification_token(
async def delete_verification_tokens(
tokens: List,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
user_api_key_dict: UserAPIKeyAuth,
litellm_changed_by: Optional[str] = None,
) -> Tuple[Optional[Dict], List[LiteLLM_VerificationToken]]:
@@ -3604,7 +3604,7 @@ async def _persist_deleted_verification_tokens(
async def delete_key_aliases(
key_aliases: List[str],
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
prisma_client: PrismaClient,
user_api_key_dict: UserAPIKeyAuth,
litellm_changed_by: Optional[str] = None,
@@ -3850,7 +3850,7 @@ async def _execute_virtual_key_regeneration(
data: Optional[RegenerateKeyRequest],
user_api_key_dict: UserAPIKeyAuth,
litellm_changed_by: Optional[str],
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
proxy_logging_obj: ProxyLogging,
) -> GenerateKeyResponse:
"""Generate new token, update DB, invalidate cache, and return response."""
@@ -4140,7 +4140,7 @@ async def _check_proxy_or_team_admin_for_key(
key_in_db: LiteLLM_VerificationToken,
user_api_key_dict: UserAPIKeyAuth,
prisma_client: PrismaClient,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
) -> None:
if user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN.value:
return
@@ -5161,7 +5161,7 @@ async def _check_key_admin_access(
user_api_key_dict: UserAPIKeyAuth,
hashed_token: str,
prisma_client: Any,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
route: str,
) -> None:
"""
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index 342e1c4ab37..06fdef295d8 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -1613,7 +1613,7 @@ prisma_client: Optional[PrismaClient] = None
shared_aiohttp_session: Optional["ClientSession"] = (
None # Global shared session for connection reuse
)
-user_api_key_cache = UserApiKeyCache(
+user_api_key_cache: UserApiKeyCache = UserApiKeyCache(
default_in_memory_ttl=UserAPIKeyCacheTTLEnum.in_memory_cache_ttl.value
)
spend_counter_cache = DualCache(
@@ -6318,7 +6318,7 @@ class ProxyStartupEvent:
cls,
general_settings: dict,
prisma_client: Optional[PrismaClient],
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
):
"""Initialize JWT auth on startup"""
if general_settings.get("litellm_jwtauth", None) is not None:
@@ -6367,7 +6367,7 @@ class ProxyStartupEvent:
async def _warm_global_spend_cache(
cls,
litellm_proxy_admin_name: str,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
prisma_client: PrismaClient,
) -> None:
"""Warm global spend cache once at startup to reduce impact of first wave of requests."""
@@ -7007,7 +7007,7 @@ class ProxyStartupEvent:
cls,
database_url: Optional[str],
proxy_logging_obj: ProxyLogging,
- user_api_key_cache: DualCache,
+ user_api_key_cache: UserApiKeyCache,
) -> Optional[PrismaClient]:
"""
- Sets up prisma client