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(types): drop restating docstrings, import search tool types at runtime, close the spend-table match

mateo-berrib8c793b96254
diff --git a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py
index 3ea9b7d9bfd..41974c26158 100644
--- a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py
+++ b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py
@@ -43,8 +43,6 @@ TERMINAL_MANAGED_OBJECT_STATUSES: Final[Tuple[str, ...]] = (
class _ManagedObjectRow(Protocol):
- """The managed-object row fields this poller reads off whatever the DB hands back."""
-
@property
def id(self) -> str: ...
@@ -59,19 +57,16 @@ class _ManagedObjectRow(Protocol):
def _managed_object_table(prisma_client: "PrismaClient") -> "TableActions[_ManagedObjectRow]":
- """The managed-object table's prisma actions, typed to the row fields this module reads."""
table: Final[TableActions[_ManagedObjectRow]] = prisma_client.db.litellm_managedobjecttable
return table
def _user_table(prisma_client: "PrismaClient") -> "TableActions[prisma_models.LiteLLM_UserTable]":
- """The user table's prisma actions."""
table: Final[TableActions[prisma_models.LiteLLM_UserTable]] = prisma_client.db.litellm_usertable
return table
def _token_table(prisma_client: "PrismaClient") -> "TableActions[prisma_models.LiteLLM_VerificationToken]":
- """The virtual-key table's prisma actions."""
table: Final[TableActions[prisma_models.LiteLLM_VerificationToken]] = (
prisma_client.db.litellm_verificationtoken
)
@@ -79,7 +74,6 @@ def _token_table(prisma_client: "PrismaClient") -> "TableActions[prisma_models.L
def _team_table(prisma_client: "PrismaClient") -> "TableActions[prisma_models.LiteLLM_TeamTable]":
- """The team table's prisma actions."""
table: Final[TableActions[prisma_models.LiteLLM_TeamTable]] = prisma_client.db.litellm_teamtable
return table
diff --git a/enterprise/litellm_enterprise/proxy/common_utils/check_responses_cost.py b/enterprise/litellm_enterprise/proxy/common_utils/check_responses_cost.py
index 1bc41f2aa5b..cdeea0d3d4b 100644
--- a/enterprise/litellm_enterprise/proxy/common_utils/check_responses_cost.py
+++ b/enterprise/litellm_enterprise/proxy/common_utils/check_responses_cost.py
@@ -29,8 +29,6 @@ TERMINAL_RESPONSE_STATUSES = frozenset({"completed", "failed", "cancelled", "inc
class _ManagedObjectRow(Protocol):
- """The managed-object row fields this poller reads off whatever the DB hands back."""
-
@property
def id(self) -> str: ...
@@ -45,7 +43,6 @@ class _ManagedObjectRow(Protocol):
def _managed_object_table(prisma_client: "PrismaClient") -> "TableActions[_ManagedObjectRow]":
- """The managed-object table's prisma actions, typed to the row fields this poller reads."""
table: Final[TableActions[_ManagedObjectRow]] = prisma_client.db.litellm_managedobjecttable
return table
diff --git a/litellm/proxy/db/db_spend_update_writer.py b/litellm/proxy/db/db_spend_update_writer.py
index 0516f5460a7..865a8c39f03 100644
--- a/litellm/proxy/db/db_spend_update_writer.py
+++ b/litellm/proxy/db/db_spend_update_writer.py
@@ -19,7 +19,7 @@ from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, TypeAlias, Type
from urllib.parse import quote, unquote
from pydantic import TypeAdapter
-from typing_extensions import LiteralString, ReadOnly, TypedDict
+from typing_extensions import LiteralString, ReadOnly, TypedDict, assert_never
import litellm
from litellm._logging import verbose_proxy_logger
@@ -142,7 +142,6 @@ _EntitySpendTable: TypeAlias = Literal[
def _entity_spend_table(batcher: _SpendBatch, table_accessor: _EntitySpendTable) -> BatchTable:
- """The batch table an entity type's spend increments are written to."""
match table_accessor:
case "litellm_tagtable":
return batcher.litellm_tagtable
@@ -152,6 +151,8 @@ def _entity_spend_table(batcher: _SpendBatch, table_accessor: _EntitySpendTable)
return batcher.litellm_modelaccessgroupbudgettable
case "litellm_projecttable":
return batcher.litellm_projecttable
+ case _ as unreachable:
+ assert_never(unreachable)
class _SpendBatchManager(Protocol):
diff --git a/litellm/router_utils/search_api_router.py b/litellm/router_utils/search_api_router.py
index 76e833563ba..1cfb311d796 100644
--- a/litellm/router_utils/search_api_router.py
+++ b/litellm/router_utils/search_api_router.py
@@ -10,18 +10,16 @@ import traceback
from collections.abc import Callable
from functools import partial
from types import MappingProxyType
-from typing import TYPE_CHECKING, Any, Final, Protocol
+from typing import Any, Final, Protocol
from litellm._logging import verbose_router_logger
-
-if TYPE_CHECKING:
- from litellm.types.router import SearchToolLiteLLMParams, SearchToolTypedDict
+from litellm.types.router import SearchToolLiteLLMParams, SearchToolTypedDict
class _SearchToolsRouter(Protocol):
"""The one router attribute the search-tool helpers read and replace."""
- search_tools: "list[SearchToolTypedDict]"
+ search_tools: list[SearchToolTypedDict]
class SearchAPIRouter:
@@ -34,7 +32,7 @@ class SearchAPIRouter:
@staticmethod
def _resolve_search_provider_credentials(
*,
- tool_litellm_params: "SearchToolLiteLLMParams",
+ tool_litellm_params: SearchToolLiteLLMParams,
) -> tuple[str | None, str | None]:
"""
Resolve search provider credentials from tool configuration ONLY.
@@ -65,8 +63,6 @@ class SearchAPIRouter:
search_tools: List of search tool configurations from the database
"""
try:
- from litellm.types.router import SearchToolTypedDict
-
verbose_router_logger.debug("Adding %s search tools to router", len(search_tools))
# Convert search tools to the format expected by the router