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): replace Any with real types across 29 more backend files
mateo-berrif747bc67048f
diff --git a/litellm/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.pyindex 68dc27ec25e..52dac92ee22 100644--- a/litellm/litellm_core_utils/llm_cost_calc/utils.py+++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py@@ -6,7 +6,7 @@ from collections.abc import Mapping, Sequencefrom dataclasses import dataclassfrom datetime import datetime, timezone, tzinfofrom types import MappingProxyType-from typing import Any, Final, Literal, TypedDict, cast+from typing import Final, Literal, TypedDict, castfrom zoneinfo import ZoneInfo, ZoneInfoNotFoundErrorimport litellm@@ -89,7 +89,7 @@ def _requested_image_size(optional_params: Mapping[str, object] | None) -> str |return value if value is not None and _IMAGE_SIZE_PATTERN.fullmatch(value) else None-def get_web_search_requests(server_tool_use: Any) -> int | None:+def get_web_search_requests(server_tool_use: object) -> int | None:"""Tolerantly read ``web_search_requests`` from a ``server_tool_use`` valuethat may be ``None``, a ``dict``, a ``ServerToolUse`` pydantic instance,@@ -1494,7 +1494,7 @@ def calculate_image_response_cost_from_usage(if prompt_tokens == 0 and completion_tokens == 0 and total_tokens == 0:return None- input_tokens_details: Final = getattr(usage, "input_tokens_details", None)+ input_tokens_details: Final[object] = getattr(usage, "input_tokens_details", None)prompt_tokens_details: PromptTokensDetailsWrapper | None = Noneif input_tokens_details is not None:# input_tokens_details may be a dict (e.g. OpenAI image edit responses)@@ -1507,9 +1507,12 @@ def calculate_image_response_cost_from_usage(cached_tokens=0,)- output_tokens_details = getattr(usage, "completion_tokens_details", None)- if output_tokens_details is None:- output_tokens_details = getattr(usage, "output_tokens_details", None)+ completion_tokens_details_attr: Final[object] = getattr(usage, "completion_tokens_details", None)+ output_tokens_details: Final[object] = (+ getattr(usage, "output_tokens_details", None)+ if completion_tokens_details_attr is None+ else completion_tokens_details_attr+ )if output_tokens_details is None:completion_tokens_details = CompletionTokensDetailsWrapper(diff --git a/litellm/llms/azure/text_to_speech/transformation.py b/litellm/llms/azure/text_to_speech/transformation.pyindex d8ccf26ce60..eed7a3178ca 100644--- a/litellm/llms/azure/text_to_speech/transformation.py+++ b/litellm/llms/azure/text_to_speech/transformation.py@@ -19,6 +19,7 @@ from litellm.secret_managers.main import get_secret_strif TYPE_CHECKING:from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj+ from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandlerfrom litellm.types.llms.openai import HttpxBinaryResponseContentelse:LiteLLMLoggingObj = Any@@ -67,15 +68,15 @@ class AzureAVATextToSpeechConfig(BaseTextToSpeechConfig):litellm_params_dict: dict,logging_obj: "LiteLLMLoggingObj",timeout: float | httpx.Timeout,- extra_headers: dict[str, Any] | None,- base_llm_http_handler: Any,+ extra_headers: dict[str, object] | None,+ base_llm_http_handler: "BaseLLMHTTPHandler",aspeech: bool,api_base: str | None,api_key: str | None,- **kwargs: Any,+ **kwargs: object,) -> Union["HttpxBinaryResponseContent",- Coroutine[Any, Any, "HttpxBinaryResponseContent"],+ Coroutine[object, object, "HttpxBinaryResponseContent"],]:"""Dispatch method to handle Azure AVA TTS requestsdiff --git a/litellm/llms/bedrock/image_edit/stability_transformation.py b/litellm/llms/bedrock/image_edit/stability_transformation.pyindex bc9a64f587a..01e25f4671e 100644--- a/litellm/llms/bedrock/image_edit/stability_transformation.py+++ b/litellm/llms/bedrock/image_edit/stability_transformation.py@@ -125,7 +125,7 @@ class BedrockStabilityImageEditConfig(BaseImageEditConfig):}# Create a copy to not mutate original - convert TypedDict to regular dict- mapped_params: Final[dict[str, Any]] = dict(image_edit_optional_params)+ mapped_params: Final[dict[str, object]] = dict(image_edit_optional_params)for k, v in image_edit_optional_params.items():if k in param_mapping:@@ -172,7 +172,7 @@ class BedrockStabilityImageEditConfig(BaseImageEditConfig):Returns the request body dict that will be JSON-encoded by the handler."""# Build Bedrock Stability request- data: Final[dict[str, Any]] = {+ data: Final[dict[str, object]] = {"output_format": "png", # Default to PNG}diff --git a/litellm/llms/bedrock_mantle/responses/transformation.py b/litellm/llms/bedrock_mantle/responses/transformation.pyindex bbbda4d14b6..3d2eab8fcee 100644--- a/litellm/llms/bedrock_mantle/responses/transformation.py+++ b/litellm/llms/bedrock_mantle/responses/transformation.py@@ -16,8 +16,8 @@ BaseAWSLLM._sign_request after the request body is finalized."""import json-from collections.abc import Mapping-from typing import Any, Final+from collections.abc import Mapping, Sequence+from typing import Finalimport httpxfrom typing_extensions import ReadOnly, TypedDict@@ -142,9 +142,9 @@ class BedrockMantleResponsesAPIConfig(BedrockMantleAuthMixin, OpenAIResponsesAPIreturn False@staticmethod- def _filter_unsupported_tools(tools: list[Any]) -> list[Any]:+ def _filter_unsupported_tools(tools: "Sequence[object]") -> "list[object]":"""Keep only tool types Mantle's Responses API accepts."""- kept: Final[list[Any]] = []+ kept: Final[list[object]] = []dropped_types: Final[list[str]] = []for tool in tools:if not isinstance(tool, dict):@@ -217,11 +217,11 @@ class BedrockMantleResponsesAPIConfig(BedrockMantleAuthMixin, OpenAIResponsesAPI)@staticmethod- def _is_codex_additional_tools_item(item: Any) -> bool:+ def _is_codex_additional_tools_item(item: object) -> bool:return isinstance(item, dict) and item.get("type") == _CODEX_ADDITIONAL_TOOLS_INPUT_ITEM_TYPE@staticmethod- def _tools_of_additional_tools_item(item: "dict[str, Any]") -> "list[Any]":+ def _tools_of_additional_tools_item(item: "Mapping[str, object]") -> "list[object]":tools: Final = item.get("tools")return tools if isinstance(tools, list) else []@@ -229,7 +229,7 @@ class BedrockMantleResponsesAPIConfig(BedrockMantleAuthMixin, OpenAIResponsesAPIdef _hoist_codex_additional_tools(cls,input: "str | ResponseInputParam",- ) -> "tuple[str | ResponseInputParam, list[Any]]":+ ) -> "tuple[str | ResponseInputParam, list[object]]":"""Codex's "responses lite" wire mode ships tool definitions inside`input` as {"type": "additional_tools", "role": "developer","tools": [...]} items. api.openai.com accepts that item type; Mantlediff --git a/litellm/llms/cohere/embed/v1_transformation.py b/litellm/llms/cohere/embed/v1_transformation.pyindex ee40464362d..b35fae5a1ac 100644--- a/litellm/llms/cohere/embed/v1_transformation.py+++ b/litellm/llms/cohere/embed/v1_transformation.py@@ -2,7 +2,8 @@Legacy /v1/embedding transformation logic for Bedrock Cohere."""-from typing import Any, Final+from collections.abc import Sized+from typing import Final, Protocolimport httpx@@ -16,6 +17,12 @@ from litellm.types.utils import EmbeddingResponse, PromptTokensDetailsWrapper, Ufrom litellm.utils import is_base64_encoded+class _SupportsEncode(Protocol):+ """Tokenizer handle: the embedding usage path only encodes text to measure its token length."""++ def encode(self, text: str, /) -> Sized: ...++class CohereEmbeddingConfig:"""Reference: https://docs.cohere.com/v2/reference/embed@@ -61,7 +68,7 @@ class CohereEmbeddingConfig:return transformed_request- def _calculate_usage(self, input: list[str], encoding: Any, meta: dict) -> Usage:+ def _calculate_usage(self, input: list[str], encoding: _SupportsEncode, meta: dict) -> Usage:input_tokens = 0text_tokens: Final[int | None] = meta.get("billed_units", {}).get("input_tokens")@@ -97,7 +104,7 @@ class CohereEmbeddingConfig:data: dict | CohereEmbeddingRequest,model_response: EmbeddingResponse,model: str,- encoding: Any,+ encoding: _SupportsEncode,input: list,) -> EmbeddingResponse:response_json: Final = response.json()@@ -121,7 +128,7 @@ class CohereEmbeddingConfig:response_json: dict,model_response: EmbeddingResponse,model: str,- encoding: Any,+ encoding: _SupportsEncode,input: list,) -> EmbeddingResponse:"""diff --git a/litellm/llms/gdc/chat/transformation.py b/litellm/llms/gdc/chat/transformation.pyindex 03037512551..6eac3ac79cd 100644--- a/litellm/llms/gdc/chat/transformation.py+++ b/litellm/llms/gdc/chat/transformation.py@@ -7,14 +7,32 @@ import osimport reimport threadingfrom collections.abc import Callable-from typing import Any, Final, Protocol+from typing import Final, Protocolfrom urllib.parse import urlsplit+from typing_extensions import ReadOnly, TypedDict, Unpack+import litellmfrom litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfigfrom litellm.types.llms.openai import AllMessageValues+class _OpenAIGPTConfigOptions(TypedDict, total=False):+ """The sampling defaults ``OpenAIGPTConfig.__init__`` accepts and stashes on the class."""++ frequency_penalty: ReadOnly[int | None]+ function_call: ReadOnly[str | dict[str, object] | None]+ functions: ReadOnly[list[object] | None]+ logit_bias: ReadOnly[dict[str, object] | None]+ max_tokens: ReadOnly[int | None]+ n: ReadOnly[int | None]+ presence_penalty: ReadOnly[int | None]+ stop: ReadOnly[str | list[object] | None]+ temperature: ReadOnly[int | None]+ top_p: ReadOnly[int | None]+ response_format: ReadOnly[dict[str, object] | None]++class _GDCHAudienceCredentials(Protocol):"""A GDCH service account credential already bound to an audience, ready to mint a bearer token."""@@ -32,7 +50,7 @@ class GDCGeminiConfig(OpenAILikeChatConfig):_GDCH_CREDENTIAL_TYPE: Final[str] = "gdch_service_account"_PATH_ID_PATTERN: Final[re.Pattern[str]] = re.compile(r"^[a-zA-Z0-9_-]+$")- def __init__(self, **kwargs: Any) -> None:+ def __init__(self, **kwargs: Unpack[_OpenAIGPTConfigOptions]) -> None:super().__init__(**kwargs)self._creds_lock = threading.Lock()self._gdch_creds_cache: dict[tuple[str, str], _GDCHAudienceCredentials] = {}diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.pyindex 279035c455d..89a5b8a570e 100644--- a/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py+++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/llama3/transformation.py@@ -1,6 +1,6 @@import typesfrom collections.abc import AsyncIterator, Iterator-from typing import TYPE_CHECKING, Any, Final+from typing import TYPE_CHECKING, Finalimport httpx@@ -95,7 +95,7 @@ class VertexAILlama3Config(OpenAIGPTConfig):streaming_response: Iterator[str] | AsyncIterator[str] | ModelResponse,sync_stream: bool,json_mode: bool | None = False,- ) -> Any:+ ) -> "VertexAILlama3StreamingHandler":return VertexAILlama3StreamingHandler(streaming_response=streaming_response,sync_stream=sync_stream,diff --git a/litellm/llms/voyage/rerank/transformation.py b/litellm/llms/voyage/rerank/transformation.pyindex fea8452d934..6f8d024f0b1 100644--- a/litellm/llms/voyage/rerank/transformation.py+++ b/litellm/llms/voyage/rerank/transformation.py@@ -4,8 +4,8 @@ Transformation logic for Voyage AI's /v1/rerank endpoint.Docs - https://docs.voyageai.com/docs/reranker"""-from collections.abc import Mapping-from typing import Any, Final+from collections.abc import Mapping, Sequence+from typing import Finalimport httpx@@ -33,7 +33,7 @@ class VoyageRerankConfig(BaseRerankConfig):model: str,drop_params: bool,query: str,- documents: list[str | dict[str, Any]],+ documents: Sequence[str | Mapping[str, object]],custom_llm_provider: str | None = None,top_n: int | None = None,rank_fields: list[str] | None = None,diff --git a/litellm/proxy/client/users.py b/litellm/proxy/client/users.pyindex 3f11fe94043..503c92228a8 100644--- a/litellm/proxy/client/users.py+++ b/litellm/proxy/client/users.py@@ -1,3 +1,4 @@+from collections.abc import Mappingfrom typing import Any, Finalimport requests@@ -50,7 +51,7 @@ class UsersManagementClient:response.raise_for_status()return response.json()- def create_user(self, user_data: dict[str, Any]) -> dict[str, Any]:+ def create_user(self, user_data: Mapping[str, object]) -> dict[str, Any]:"""Create a new user (POST /user/new)"""url: Final = f"{self.base_url}/user/new"response: Final = requests.post(url, headers=self._get_headers(), json=user_data, timeout=self.timeout)diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.pyindex 54a0f18fd63..2bae3e946f7 100644--- a/litellm/proxy/common_utils/http_parsing_utils.py+++ b/litellm/proxy/common_utils/http_parsing_utils.py@@ -52,14 +52,18 @@ def _unqualified(annotation: object) -> object:return _unqualified(qualified[0])+def _union_members(annotation: object) -> tuple[object, ...]:+ """The non-``None`` members of a union annotation, or the annotation itself when it is not a union."""+ if get_origin(annotation) not in (Union, UnionType):+ return (annotation,)+ members: Final[tuple[object, ...]] = get_args(annotation)+ return tuple(arg for arg in members if arg is not type(None))++def _numeric_form_type(annotation: object) -> type[int] | type[float] | None:"""The scalar to parse an ``int``/``float``-typed field as, else ``None``."""unwrapped: Final = _unqualified(annotation)- candidates: Final = (- tuple(arg for arg in get_args(unwrapped) if arg is not type(None))- if get_origin(unwrapped) in (Union, UnionType)- else (unwrapped,)- )+ candidates: Final = _union_members(unwrapped)if len(candidates) != 1:return Noneif candidates[0] is int:diff --git a/litellm/proxy/db/prisma_client.py b/litellm/proxy/db/prisma_client.pyindex 2190ae55fd2..2f2ebfdf2bb 100644--- a/litellm/proxy/db/prisma_client.py+++ b/litellm/proxy/db/prisma_client.py@@ -13,7 +13,7 @@ import urllibimport urllib.parsefrom collections.abc import Callablefrom datetime import datetime, timedelta-from typing import Any, Final, Protocol+from typing import TYPE_CHECKING, Any, Final, Protocolfrom litellm._logging import verbose_proxy_loggerfrom litellm.proxy.db.token_auth import (@@ -27,6 +27,9 @@ from litellm.proxy.db.token_auth import ()from litellm.secret_managers.main import str_to_bool+if TYPE_CHECKING:+ from prisma import Prisma+__all__ = ("IAMEndpoint","PrismaManager",@@ -242,7 +245,7 @@ class PrismaWrapper:def _write_engine(prisma_client: _PrismaClient, engine: _PrismaEngine) -> None:prisma_client._Prisma__engine = engine- def _instrument_prisma_client(self, prisma_client: _PrismaClient) -> _PrismaDrainTracker | None:+ def _instrument_prisma_client(self, prisma_client: "Prisma | _PrismaClient") -> _PrismaDrainTracker | None:from prisma.errors import ClientNotConnectedErrortry:@@ -255,7 +258,7 @@ class PrismaWrapper:self._write_engine(prisma_client, _TrackedPrismaEngine(engine, tracker))return tracker- def _get_engine_pid(self, prisma_client: _PrismaClient | None = None) -> int:+ def _get_engine_pid(self, prisma_client: "Prisma | _PrismaClient | None" = None) -> int:"""Get the PID of the current Prisma engine subprocess, or 0 if unavailable.Must never raise: it runs inside the reconnect path, where the clientdiff --git a/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/block_code_execution.py b/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/block_code_execution.pyindex bf2aa1f76e0..2b697671eda 100644--- a/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/block_code_execution.py+++ b/litellm/proxy/guardrails/guardrail_hooks/block_code_execution/block_code_execution.py@@ -8,9 +8,10 @@ confidence scoring and a tunable threshold (only block when confidence >= threshimport refrom datetime import datetime-from typing import TYPE_CHECKING, Any, Final, Literal, Optional, cast+from typing import TYPE_CHECKING, Final, Literal, Optional, castfrom fastapi import HTTPException+from typing_extensions import TypedDict, Unpackfrom litellm.integrations.custom_guardrail import (CustomGuardrail,@@ -314,6 +315,10 @@ def _confidence_for_block(return 0.0+class _CustomGuardrailOptions(TypedDict, total=False, extra_items=object):+ """Base-class constructor options this guardrail forwards untouched to CustomGuardrail."""++class BlockCodeExecutionGuardrail(CustomGuardrail):"""Guardrail that detects fenced code blocks (markdown ```) and blocks or masks them@@ -332,7 +337,7 @@ class BlockCodeExecutionGuardrail(CustomGuardrail):detect_execution_intent: bool = True,event_hook: Literal["pre_call", "post_call", "during_call"] | list[str] | None = None,default_on: bool = False,- **kwargs: Any,+ **kwargs: Unpack[_CustomGuardrailOptions],) -> None:# Normalize to type expected by CustomGuardrail_event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | None = Nonediff --git a/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.py b/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.pyindex 176c308eda6..2d203c31974 100644--- a/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.py+++ b/litellm/proxy/guardrails/guardrail_hooks/cato_networks/cato_networks.py@@ -264,7 +264,7 @@ class CatoNetworksGuardrail(CustomGuardrail):stack.extend(reversed(node))@classmethod- def _extra_inspection_sources(cls, data: Mapping[str, Any]) -> Sequence[tuple[str, Sequence[Mapping[str, str]]]]:+ def _extra_inspection_sources(cls, data: Mapping[str, object]) -> Sequence[tuple[str, Sequence[Mapping[str, str]]]]:"""Text the proxy forwards to the model outside chat ``messages``:Responses-API ``input`` and ``instructions``, legacy completion``prompt`` and tool/function/``response_format`` schema strings. Returned@@ -336,7 +336,7 @@ class CatoNetworksGuardrail(CustomGuardrail):)raise HTTPException(status_code=400, detail=detection_message)- def _anonymize_request(self, res: Any, data: dict) -> dict:+ def _anonymize_request(self, res: _CatoAnalyzeResponse, data: dict) -> dict:verbose_proxy_logger.info("Cato: anonymize action")redacted_chat: Final = res.get("redacted_chat")if not redacted_chat:@@ -379,7 +379,7 @@ class CatoNetworksGuardrail(CustomGuardrail):return data@classmethod- def _apply_extra_redaction(cls, data: dict, field: str, redacted: list) -> bool:+ def _apply_extra_redaction(cls, data: dict, field: str, redacted: Sequence[Mapping[str, object]]) -> bool:if field == "input":input_only: Final = {"input": data["input"]}if not redacted:@@ -400,7 +400,7 @@ class CatoNetworksGuardrail(CustomGuardrail):return True@classmethod- def _apply_schema_string_redaction(cls, data: dict, redacted: list) -> None:+ def _apply_schema_string_redaction(cls, data: dict, redacted: Sequence[Mapping[str, object]]) -> None:redactions: Final = iter(redacted)for container, key in cls._iter_schema_string_refs(data):replacement = next(redactions, None)@@ -408,7 +408,7 @@ class CatoNetworksGuardrail(CustomGuardrail):container[key] = replacement["content"]@staticmethod- def _apply_prompt_redaction(data: dict, redacted: list) -> None:+ def _apply_prompt_redaction(data: dict, redacted: Sequence[Mapping[str, object]]) -> None:contents: Final = [m.get("content") for m in redacted if isinstance(m, dict)]prompt: Final = data.get("prompt")if isinstance(prompt, str):diff --git a/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py b/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.pyindex 93d859066b0..1ecdb1b0f63 100644--- a/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py+++ b/litellm/proxy/guardrails/guardrail_hooks/compresr/compresr.py@@ -22,7 +22,7 @@ import jsonimport timefrom collections import Counter, OrderedDictfrom dataclasses import dataclass, field-from typing import TYPE_CHECKING, Any, Final, Literal, TypeGuard+from typing import TYPE_CHECKING, Final, Literal, TypeGuardfrom urllib.parse import urlparseimport httpx@@ -64,6 +64,9 @@ if TYPE_CHECKING:from litellm.litellm_core_utils.litellm_logging import (Logging as LiteLLMLoggingObj,)+ from litellm.llms.base_llm.anthropic_messages.transformation import (+ BaseAnthropicMessagesConfig,+ )from litellm.types.proxy.guardrails.guardrail_hooks.base import (GuardrailConfigModel,)@@ -1049,7 +1052,7 @@ class CompresrGuardrail(CustomGuardrail):async def async_should_run_agentic_loop(self,- response: Any,+ response: object,model: str,messages: list[dict],tools: list[dict] | None,@@ -1069,8 +1072,8 @@ class CompresrGuardrail(CustomGuardrail):tools: dict,model: str,messages: list[dict],- response: Any,- anthropic_messages_provider_config: Any,+ response: object,+ anthropic_messages_provider_config: BaseAnthropicMessagesConfig | None,anthropic_messages_optional_request_params: dict,logging_obj: LiteLLMLoggingObj | None,stream: bool,diff --git a/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.pyindex 172b1440ca3..806ab5161e8 100644--- a/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.py+++ b/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.py@@ -2,10 +2,10 @@from collections.abc import Callable, Sequencefrom datetime import datetime-from typing import TYPE_CHECKING, Any, Final, Generic, Literal, Optional, TypeVar+from typing import TYPE_CHECKING, Final, Generic, Literal, Optional, TypeVarfrom fastapi import HTTPException-from typing_extensions import NotRequired, ReadOnly, TypedDict+from typing_extensions import NotRequired, ReadOnly, TypedDict, Unpackimport litellmfrom litellm._logging import verbose_logger@@ -106,6 +106,23 @@ def _build_judge_prompt()+class _CustomGuardrailOptions(TypedDict, total=False):+ """The ``CustomGuardrail`` options this guardrail accepts and forwards untouched."""++ mask_request_content: ReadOnly[bool]+ mask_response_content: ReadOnly[bool]+ violation_message_template: ReadOnly[str | None]+ end_session_after_n_fails: ReadOnly[int | None]+ on_violation: ReadOnly[str | None]+ realtime_violation_message: ReadOnly[str | None]+ on_sensitive_data: ReadOnly[str | None]+ sensitive_data_route_to_model: ReadOnly[str | None]+ sticky_session_routing: ReadOnly[bool]+ run_in_parallel: ReadOnly[bool]+ scan_raw_request: ReadOnly[bool]+ only_scan_new_messages: ReadOnly[bool]++class LLMAsAJudgeGuardrail(CustomGuardrail):"""Post-call guardrail that judges response quality via an LLM."""@@ -119,7 +136,7 @@ class LLMAsAJudgeGuardrail(CustomGuardrail):event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | None = None,default_on: bool = False,router_provider: "Callable[[], Router | None] | None" = None,- **kwargs: Any,+ **kwargs: Unpack[_CustomGuardrailOptions],) -> None:_event_hook: GuardrailEventHooks | list[GuardrailEventHooks] | None = Noneif event_hook is not None:diff --git a/litellm/proxy/guardrails/guardrail_hooks/noma/noma.py b/litellm/proxy/guardrails/guardrail_hooks/noma/noma.pyindex 7ef0a9f73f3..edd78e0bbc6 100644--- a/litellm/proxy/guardrails/guardrail_hooks/noma/noma.py+++ b/litellm/proxy/guardrails/guardrail_hooks/noma/noma.py@@ -9,13 +9,13 @@ import asyncioimport jsonimport osimport warnings-from collections.abc import AsyncGenerator+from collections.abc import AsyncGenerator, AsyncIterablefrom datetime import datetimefrom typing import (TYPE_CHECKING,- Any,Final,Literal,+ TypeVar,)from urllib.parse import urljoin@@ -39,9 +39,7 @@ from litellm.types.guardrails import GuardrailEventHooksfrom litellm.types.utils import (CallTypes,CallTypesLiteral,- EmbeddingResponse,GuardrailStatus,- ImageResponse,ModelResponseStream,TextCompletionResponse,)@@ -53,7 +51,8 @@ SENSITIVE_DATA_DETECTOR_KEYS: Final[list[str]] = ["sensitiveData", "dataDetector# Type aliasesMessageRole = Literal["user", "assistant"]-LLMResponse = Any | ModelResponse | EmbeddingResponse | ImageResponse+LLMResponse = object+_LLMResponseT: Final = TypeVar("_LLMResponseT")_LEGACY_NOMA_DEPRECATION_WARNED = Falseif TYPE_CHECKING:@@ -709,10 +708,10 @@ class NomaGuardrail(CustomGuardrail):async def _check_llm_response(self,request_data: dict,- response: LLMResponse,+ response: _LLMResponseT,user_auth: UserAPIKeyAuth,event_type: GuardrailEventHooks | None = None,- ) -> Any:+ ) -> _LLMResponseT:"""Check LLM response for policy violations"""content: Final = await self._process_llm_response_check(request_data, response, user_auth, event_type)if not content:@@ -798,7 +797,7 @@ class NomaGuardrail(CustomGuardrail):async def async_post_call_streaming_iterator_hook(self,user_api_key_dict: UserAPIKeyAuth,- response: Any,+ response: AsyncIterable[ModelResponseStream],request_data: dict,) -> AsyncGenerator[ModelResponseStream, None]:"""Process streaming response chunks with Noma guardrail."""diff --git a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.pyindex b73d3adb99e..86ad2f9db5f 100644--- a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py+++ b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py@@ -793,7 +793,7 @@ class PanwPrismaAirsHandler(CustomGuardrail):},)- def _prepare_metadata_from_request(self, data: dict[str, Any]) -> dict[str, Any]:+ def _prepare_metadata_from_request(self, data: dict[str, Any]) -> dict[str, object]:"""Extract and prepare metadata from request data for PANW API call.@@ -809,7 +809,7 @@ class PanwPrismaAirsHandler(CustomGuardrail):"""user_metadata: Final = data.get("metadata", {}) or {}requester_meta: Final = user_metadata.get("requester_metadata", {}) or {}- metadata: Final = {+ metadata: Final[dict[str, object]] = {"user": data.get("user") or "litellm_user","model": data.get("model") or "unknown",}diff --git a/litellm/proxy/guardrails/usage_endpoints.py b/litellm/proxy/guardrails/usage_endpoints.pyindex 6259efb6654..3f7c36bbbf2 100644--- a/litellm/proxy/guardrails/usage_endpoints.py+++ b/litellm/proxy/guardrails/usage_endpoints.py@@ -45,6 +45,7 @@ _EMPTY_UNITS: Final[Mapping[str, int]] = MappingProxyType({})_ACTION_SEVERITY: Final[Mapping[str, int]] = MappingProxyType({"passed": 0, "flagged": 1, "blocked": 2})_T = TypeVar("_T")+_MetricsRowT = TypeVar("_MetricsRowT", bound="_DailyMetricsRow")_USAGE_MAX_RANGE_DAYS: Final = 366@@ -360,10 +361,12 @@ def _trend_from_comparison(current_fail: float, previous_fail: float) -> str:return "stable"-def _aggregate_daily_metrics(metrics: "Sequence[_DailyMetricsRow]", id_attr: str) -> Mapping[str, _MetricTotals]:+def _aggregate_daily_metrics(+ metrics: "Sequence[_MetricsRowT]", id_of: "Callable[[_MetricsRowT], str]"+) -> Mapping[str, _MetricTotals]:agg: Final[dict[str, _MetricTotals]] = {}for m in metrics:- gid: str = getattr(m, id_attr)+ gid: str = id_of(m)if gid not in agg:agg[gid] = {"requests": 0, "passed": 0, "blocked": 0, "flagged": 0}agg[gid]["requests"] += int(m.requests_evaluated or 0)@@ -373,10 +376,12 @@ def _aggregate_daily_metrics(metrics: "Sequence[_DailyMetricsRow]", id_attr: strreturn agg-def _prev_fail_rates(metrics_prev: "Sequence[_DailyMetricsRow]", id_attr: str) -> Mapping[str, float]:+def _prev_fail_rates(+ metrics_prev: "Sequence[_MetricsRowT]", id_of: "Callable[[_MetricsRowT], str]"+) -> Mapping[str, float]:prev_agg_raw: Final[dict[str, _PrevPeriodCounts]] = {}for m in metrics_prev:- gid: str = getattr(m, id_attr)+ gid: str = id_of(m)r, b = int(m.requests_evaluated or 0), int(m.blocked_count or 0)if gid not in prev_agg_raw:prev_agg_raw[gid] = {"req": 0, "blocked": 0}@@ -429,7 +434,7 @@ def _field_str(mapping: Mapping[str, object], key: str, default: str) -> str:return str(mapping.get(key, default))-def _get_guardrail_attrs(g: "_DbOrConfigGuardrail") -> tuple[Any, str]:+def _get_guardrail_attrs(g: "_DbOrConfigGuardrail") -> tuple[str | None, str]:"""Get (guardrail_id, display_name) from guardrail - handles Prisma model or dict."""gid: Final = _get_guardrail_field(g, "guardrail_id")name: Final = _get_guardrail_field(g, "guardrail_name")@@ -592,8 +597,8 @@ async def guardrails_usage_overview(Sequence[prisma_models.LiteLLM_DailyGuardrailUsageUnits]] = await _find_daily_guardrail_usage_units(prisma_client, where=units_where)- agg: Final = _aggregate_daily_metrics(metrics, "guardrail_id")- prev_agg: Final = _prev_fail_rates(metrics_prev, "guardrail_id")+ agg: Final = _aggregate_daily_metrics(metrics, lambda m: m.guardrail_id)+ prev_agg: Final = _prev_fail_rates(metrics_prev, lambda m: m.guardrail_id)units_agg: Final = _by(units_rows, lambda r: r.guardrail_id, _sum_counter_units)cost_agg: Final = _by(units_rows, lambda r: r.guardrail_id, _sum_tracked_cost)untracked_agg: Final = _by(units_rows, lambda r: r.guardrail_id, _sum_untracked_units)@@ -811,7 +816,7 @@ def _usage_log_entry_from_row()-def _snippet(text: Any, max_len: int = 200) -> str | None:+def _snippet(text: object, max_len: int = 200) -> str | None:if text is None:return Noneif isinstance(text, str):@@ -964,8 +969,8 @@ async def policies_usage_overview(}},)- agg: Final = _aggregate_daily_metrics(metrics, "policy_id")- prev_agg: Final = _prev_fail_rates(metrics_prev, "policy_id")+ agg: Final = _aggregate_daily_metrics(metrics, lambda m: m.policy_id)+ prev_agg: Final = _prev_fail_rates(metrics_prev, lambda m: m.policy_id)chart: Final = _chart_from_metrics(metrics)total_requests: Final = sum(a["requests"] for a in agg.values())total_blocked: Final = sum(a["blocked"] for a in agg.values())diff --git a/litellm/proxy/hooks/proxy_track_cost_callback.py b/litellm/proxy/hooks/proxy_track_cost_callback.pyindex c4fba8ecf9e..e6ada41f062 100644--- a/litellm/proxy/hooks/proxy_track_cost_callback.py+++ b/litellm/proxy/hooks/proxy_track_cost_callback.py@@ -2,7 +2,7 @@ import asyncioimport tracebackfrom collections.abc import Sequencefrom datetime import datetime-from typing import TYPE_CHECKING, Any, Final, cast+from typing import TYPE_CHECKING, Any, Final, Protocol, castimport litellmfrom litellm._logging import verbose_proxy_logger@@ -578,18 +578,36 @@ def _get_request_tags_for_cost_tracking(return None+class _IncrementSpendCounters(Protocol):+ """The ``increment_spend_counters`` coroutine :func:`_update_database_and_spend_counters` awaits."""++ async def __call__(+ self,+ token: str | None,+ team_id: str | None,+ user_id: str | None,+ response_cost: float | None,+ org_id: str | None = None,+ budget_reservation: dict[str, object] | None = None,+ end_user_id: str | None = None,+ tags: list[str] | None = None,+ request_started_at: datetime | None = None,+ model_access_groups: Sequence[str] | None = None,+ ) -> None: ...++async def _update_database_and_spend_counters(proxy_logging_obj: "ProxyLogging",- increment_spend_counters: Any,+ increment_spend_counters: _IncrementSpendCounters,user_api_key: str | None,user_id: str | None,end_user_id: str | None,team_id: str | None,org_id: str | None,kwargs: dict,- completion_response: litellm.ModelResponse | Any | None,- start_time: Any,- end_time: Any,+ completion_response: object,+ start_time: datetime | None,+ end_time: datetime | None,response_cost: float,budget_reservation: dict | None,request_tags: list[str] | None = None,diff --git a/litellm/proxy/management_endpoints/model_access_group_management_endpoints.py b/litellm/proxy/management_endpoints/model_access_group_management_endpoints.pyindex a48130a4f22..e960bdfe337 100644--- a/litellm/proxy/management_endpoints/model_access_group_management_endpoints.py+++ b/litellm/proxy/management_endpoints/model_access_group_management_endpoints.py@@ -540,7 +540,7 @@ async def get_all_access_groups_from_db(deployments: Final = await ModelRepository(prisma_client).table.find_many()# Build access group map- access_group_map: Final[dict[str, dict[str, Any]]] = {}+ model_names_by_group: Final[dict[str, list[str]]] = {}for deployment in deployments:model_info = deployment.model_info or {}@@ -550,25 +550,20 @@ async def get_all_access_groups_from_db(model_name = deployment.model_namefor access_group in access_groups:- if access_group not in access_group_map:- access_group_map[access_group] = {- "model_names": set(),- "deployment_count": 0,- }+ if access_group not in model_names_by_group:+ model_names_by_group[access_group] = []- access_group_map[access_group]["model_names"].add(model_name)- access_group_map[access_group]["deployment_count"] += 1+ model_names_by_group[access_group].append(model_name)# Convert to AccessGroupInfo objects- result: Final = {}- for access_group, data in access_group_map.items():- result[access_group] = AccessGroupInfo(+ return {+ access_group: AccessGroupInfo(access_group=access_group,- model_names=sorted(list(data["model_names"])),- deployment_count=data["deployment_count"],+ model_names=sorted(frozenset(model_names)),+ deployment_count=len(model_names),)-- return result+ for access_group, model_names in model_names_by_group.items()+ }@router.post(diff --git a/litellm/proxy/management_endpoints/usage_endpoints/ai_usage_chat.py b/litellm/proxy/management_endpoints/usage_endpoints/ai_usage_chat.pyindex da4ddbd0aac..1265da99d89 100644--- a/litellm/proxy/management_endpoints/usage_endpoints/ai_usage_chat.py+++ b/litellm/proxy/management_endpoints/usage_endpoints/ai_usage_chat.py@@ -6,7 +6,7 @@ usage/spend data by querying the aggregated daily activity endpoints.import jsonfrom collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Mapping, Sequencefrom datetime import date-from typing import Any, Final, Literal, NamedTuple, Protocol, cast, overload+from typing import Final, Literal, NamedTuple, Protocol, cast, overloadfrom typing_extensions import ReadOnly, TypedDict@@ -16,6 +16,7 @@ from litellm.constants import DEFAULT_COMPETITOR_DISCOVERY_MODELfrom litellm.types.proxy.management_endpoints.common_daily_activity import (SpendAnalyticsPaginatedResponse,)+from litellm.types.utils import ChatCompletionMessageToolCall# ---------------------------------------------------------------------------# Constants@@ -489,19 +490,19 @@ async def _execute_tool_call(async def _process_tool_call(- tc: Any,+ tc: ChatCompletionMessageToolCall,chat_messages: list[Mapping[str, object]],user_id: str | None,is_admin: bool,) -> AsyncIterator[str]:"""Execute a single tool call, yielding SSE events for status."""- fn_name: Final[str] = tc.function.name+ fn_name: Final = tc.function.namefn_args: Final[Mapping[str, str]] = json.loads(tc.function.arguments)allowed_names: Final = {t["function"]["name"] for t in get_tools_for_role(is_admin)}- handler: Final = TOOL_HANDLERS.get(fn_name)+ handler: Final = TOOL_HANDLERS.get(fn_name) if fn_name is not None else None- if fn_name not in allowed_names or not handler:+ if fn_name is None or fn_name not in allowed_names or not handler:chat_messages.append({"role": "tool",diff --git a/litellm/proxy/openai_files_endpoints/files_endpoints.py b/litellm/proxy/openai_files_endpoints/files_endpoints.pyindex bf07f4748ef..4d3a397e519 100644--- a/litellm/proxy/openai_files_endpoints/files_endpoints.py+++ b/litellm/proxy/openai_files_endpoints/files_endpoints.py@@ -485,8 +485,8 @@ async def create_file(# Parse expires_after if providedexpires_after: FileExpiresAfter | None = Noneform_data_raw: Final = await request.form()- form_data_dict: Final[dict[str, Any]] = dict(form_data_raw)- extracted_litellm_metadata: Final[dict[str, Any] | None] = extract_nested_form_metadata(+ form_data_dict: Final[Mapping[str, object]] = dict(form_data_raw)+ extracted_litellm_metadata: Final[Mapping[str, object] | None] = extract_nested_form_metadata(form_data=form_data_dict, prefix="litellm_metadata[")expires_after_anchor: Final = form_data_raw.get("expires_after[anchor]")diff --git a/litellm/proxy/openai_files_endpoints/storage_backend_service.py b/litellm/proxy/openai_files_endpoints/storage_backend_service.pyindex e766f335071..0407499cbcc 100644--- a/litellm/proxy/openai_files_endpoints/storage_backend_service.py+++ b/litellm/proxy/openai_files_endpoints/storage_backend_service.py@@ -7,7 +7,6 @@ storage backends (e.g., Azure Blob Storage) and managing associated metadata.import base64import time-from collections.abc import Mappingfrom typing import Any, Final, castfrom litellm._logging import verbose_proxy_logger@@ -17,7 +16,7 @@ from litellm.llms.base_llm.files.transformation import BaseFileEndpointsfrom litellm.proxy._types import ProxyException, UserAPIKeyAuthfrom litellm.proxy.utils import ProxyLoggingfrom litellm.types.llms.openai import OpenAIFileObject, OpenAIFilesPurpose-from litellm.types.utils import SpecialEnums+from litellm.types.utils import ExtractedFileData, SpecialEnumsclass StorageBackendFileService:@@ -33,7 +32,7 @@ class StorageBackendFileService:@staticmethodasync def upload_file_to_storage_backend(- file_data: Mapping[str, Any],+ file_data: ExtractedFileData,target_storage: str,target_model_names: list[str],purpose: OpenAIFilesPurpose,@@ -163,7 +162,7 @@ class StorageBackendFileService:@staticmethoddef _create_unified_file_id(- file_type: str,+ file_type: str | None,target_model_names: list[str],file_id: str,) -> str:@@ -193,7 +192,7 @@ class StorageBackendFileService:@staticmethodasync def _store_in_managed_files(file_object: OpenAIFileObject,- file_data: Mapping[str, Any],+ file_data: ExtractedFileData,target_model_names: list[str],target_storage: str,storage_url: str,diff --git a/litellm/proxy/vector_store_endpoints/endpoints.py b/litellm/proxy/vector_store_endpoints/endpoints.pyindex 1feda0b0bb5..f21c294e5a2 100644--- a/litellm/proxy/vector_store_endpoints/endpoints.py+++ b/litellm/proxy/vector_store_endpoints/endpoints.py@@ -244,7 +244,7 @@ async def vector_store_create()# Create vector store across multiple models- response: Final = await managed_vector_stores.acreate_vector_store(+ response: Final[object] = await managed_vector_stores.acreate_vector_store(create_request=data,llm_router=llm_router,target_model_names_list=target_model_names_list,diff --git a/litellm/proxy/vector_store_files_endpoints/endpoints.py b/litellm/proxy/vector_store_files_endpoints/endpoints.pyindex 957ed9fd0b9..3ddea288ab8 100644--- a/litellm/proxy/vector_store_files_endpoints/endpoints.py+++ b/litellm/proxy/vector_store_files_endpoints/endpoints.py@@ -553,7 +553,7 @@ async def vector_store_file_create(processor: Final = ProxyBaseLLMRequestProcessing(data=data)try:- response = await processor.base_process_llm_request(+ response: object = await processor.base_process_llm_request(request=request,fastapi_response=fastapi_response,user_api_key_dict=user_api_key_dict,@@ -756,7 +756,7 @@ async def vector_store_file_retrieve(processor: Final = ProxyBaseLLMRequestProcessing(data=data)try:- response = await processor.base_process_llm_request(+ response: object = await processor.base_process_llm_request(request=request,fastapi_response=fastapi_response,user_api_key_dict=user_api_key_dict,@@ -863,7 +863,7 @@ async def vector_store_file_content(processor: Final = ProxyBaseLLMRequestProcessing(data=data)try:- response = await processor.base_process_llm_request(+ response: object = await processor.base_process_llm_request(request=request,fastapi_response=fastapi_response,user_api_key_dict=user_api_key_dict,@@ -973,7 +973,7 @@ async def vector_store_file_update(processor: Final = ProxyBaseLLMRequestProcessing(data=data)try:- response = await processor.base_process_llm_request(+ response: object = await processor.base_process_llm_request(request=request,fastapi_response=fastapi_response,user_api_key_dict=user_api_key_dict,@@ -1080,7 +1080,7 @@ async def vector_store_file_delete(processor: Final = ProxyBaseLLMRequestProcessing(data=data)try:- response = await processor.base_process_llm_request(+ response: object = await processor.base_process_llm_request(request=request,fastapi_response=fastapi_response,user_api_key_dict=user_api_key_dict,diff --git a/litellm/proxy_auth/credentials.py b/litellm/proxy_auth/credentials.pyindex a4e29241959..f8814954a7a 100644--- a/litellm/proxy_auth/credentials.py+++ b/litellm/proxy_auth/credentials.py@@ -7,7 +7,7 @@ It follows the same TokenCredential protocol used by Azure SDK.import timefrom dataclasses import dataclass-from typing import Any, Final, Protocol, runtime_checkable+from typing import Final, Protocol, runtime_checkable@dataclass@@ -50,6 +50,22 @@ class TokenCredential(Protocol):...+class _AzureAccessToken(Protocol):+ """The two attributes :class:`AzureADCredential` reads off an azure-identity token."""++ @property+ def token(self) -> str: ...++ @property+ def expires_on(self) -> int: ...+++class _AzureTokenCredential(Protocol):+ """The single method :class:`AzureADCredential` calls on the credential it wraps."""++ def get_token(self, *scopes: str) -> _AzureAccessToken: ...++class AzureADCredential:"""Wrapper for Azure Identity credentials.@@ -71,7 +87,7 @@ class AzureADCredential:cred = AzureADCredential(credential=azure_cred)"""- def __init__(self, credential: Any | None = None):+ def __init__(self, credential: _AzureTokenCredential | None = None):"""Initialize with an optional Azure credential.@@ -79,7 +95,7 @@ class AzureADCredential:credential: An azure-identity credential object. If None,DefaultAzureCredential will be used on first token request."""- self._credential: Any = credential+ self._credential: _AzureTokenCredential | None = credentialself._initialized = credential is not Nonedef get_token(self, scope: str) -> AccessToken:@@ -95,19 +111,29 @@ class AzureADCredential:Raises:ImportError: If azure-identity is not installed."""- if not self._initialized:- try:- from azure.identity import DefaultAzureCredential+ result: Final = self._resolve_credential().get_token(scope)+ return AccessToken(token=result.token, expires_on=result.expires_on)- self._credential = DefaultAzureCredential()- self._initialized = True- except ImportError:- raise ImportError(- "azure-identity is required for AzureADCredential. Install it with: pip install azure-identity"- )+ def _resolve_credential(self) -> _AzureTokenCredential:+ """Return the wrapped credential, building the Azure default chain on first use.- result: Final = self._credential.get_token(scope)- return AccessToken(token=result.token, expires_on=result.expires_on)+ Raises:+ ImportError: If azure-identity is not installed.+ """+ existing: Final = self._credential+ if existing is not None:+ return existing+ try:+ from azure.identity import DefaultAzureCredential++ created: Final = DefaultAzureCredential()+ except ImportError:+ raise ImportError(+ "azure-identity is required for AzureADCredential. Install it with: pip install azure-identity"+ )+ self._credential = created+ self._initialized = True+ return createdclass GenericOAuth2Credential:@@ -228,7 +254,7 @@ class ProxyAuthHandler:self._cached_token = self.credential.get_token(self.scope)return self._cached_token- def get_auth_headers(self) -> dict:+ def get_auth_headers(self) -> dict[str, str]:"""Get HTTP headers for authentication.diff --git a/litellm/rag/rag_query.py b/litellm/rag/rag_query.pyindex 255faf94402..9325547c17d 100644--- a/litellm/rag/rag_query.py+++ b/litellm/rag/rag_query.py@@ -124,9 +124,9 @@ class RAGQuery:@staticmethoddef extract_documents_from_search(search_response: Any,- ) -> list[str | dict[str, Any]]:+ ) -> list[str | dict[str, object]]:"""Extract text documents from vector store search response."""- documents: Final[list[str | dict[str, Any]]] = []+ documents: Final[list[str | dict[str, object]]] = []search_data: Final[_SearchDataView] = {"results": search_response.get("data", [])}for result in search_data["results"]:content_list = result.get("content", [])diff --git a/litellm/repositories/verification_token_repository.py b/litellm/repositories/verification_token_repository.pyindex c0e59f9b975..d02c2114136 100644--- a/litellm/repositories/verification_token_repository.py+++ b/litellm/repositories/verification_token_repository.py@@ -5,7 +5,8 @@ VerificationToken repository for database operations on LiteLLM_VerificationTokeimport jsonfrom collections.abc import Mapping, Sequencefrom datetime import datetime-from typing import TYPE_CHECKING, Final+from types import TracebackType+from typing import TYPE_CHECKING, Final, Protocolfrom litellm.models.verification_token import (LiteLLM_VerificationToken,@@ -25,7 +26,36 @@ if TYPE_CHECKING:LiteLLM_VerificationToken as PrismaVerificationToken,)- from litellm.proxy.utils import PrismaClient++class _VerificationTokenTables(Protocol):+ """The two verification token tables this repository reads and writes."""++ @property+ def litellm_verificationtoken(self) -> TableActions["PrismaVerificationToken"]: ...++ @property+ def litellm_deletedverificationtoken(self) -> TableActions["PrismaDeletedVerificationToken"]: ...+++class _VerificationTokenTransactionManager(Protocol):+ async def __aenter__(self) -> _VerificationTokenTables: ...++ async def __aexit__(+ self,+ exc_type: type[BaseException] | None,+ exc_value: BaseException | None,+ traceback: TracebackType | None,+ ) -> bool | None: ...+++class _PrismaVerificationTokenDb(_VerificationTokenTables, Protocol):+ def tx(self) -> _VerificationTokenTransactionManager: ...+++class _PrismaClientView(Protocol):+ @property+ def db(self) -> _PrismaVerificationTokenDb: ...+_JSON_ENCODED_TOKEN_FIELDS: Final = ("aliases",@@ -44,17 +74,17 @@ class VerificationTokenRepository(BaseRepository[LiteLLM_VerificationToken]):"""Repository for verification token (API key) database operations."""@property- def prisma_client(self) -> "PrismaClient":- prisma_client: Final[PrismaClient] = super().prisma_client- return prisma_client+ def _db(self) -> _PrismaVerificationTokenDb:+ client: Final[_PrismaClientView] = self.prisma_client+ return client.db@propertydef table(self) -> TableActions["PrismaVerificationToken"]:- return self.prisma_client.db.litellm_verificationtoken+ return self._db.litellm_verificationtoken@propertydef deleted_table(self) -> TableActions["PrismaDeletedVerificationToken"]:- return self.prisma_client.db.litellm_deletedverificationtoken+ return self._db.litellm_deletedverificationtoken@propertydef model_class(self) -> type[LiteLLM_VerificationToken]:@@ -325,7 +355,7 @@ class VerificationTokenRepository(BaseRepository[LiteLLM_VerificationToken]):archive_data["litellm_changed_by"] = litellm_changed_byarchive_data["deleted_at"] = datetime.utcnow()- async with self.prisma_client.db.tx() as tx:+ async with self._db.tx() as tx:await tx.litellm_deletedverificationtoken.create(data=archive_data)await tx.litellm_verificationtoken.delete(where={"token": token})diff --git a/litellm/router_utils/search_api_router.py b/litellm/router_utils/search_api_router.pyindex 309894957ea..76e833563ba 100644--- a/litellm/router_utils/search_api_router.py+++ b/litellm/router_utils/search_api_router.py@@ -15,7 +15,7 @@ from typing import TYPE_CHECKING, Any, Final, Protocolfrom litellm._logging import verbose_router_loggerif TYPE_CHECKING:- from litellm.types.router import SearchToolTypedDict+ from litellm.types.router import SearchToolLiteLLMParams, SearchToolTypedDictclass _SearchToolsRouter(Protocol):@@ -34,7 +34,7 @@ class SearchAPIRouter:@staticmethoddef _resolve_search_provider_credentials(*,- tool_litellm_params: dict[str, Any],+ tool_litellm_params: "SearchToolLiteLLMParams",) -> tuple[str | None, str | None]:"""Resolve search provider credentials from tool configuration ONLY.