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
fix: restore if TYPE_CHECKING block for proper FastAPI import handling
Julio Quinteros Pro1fffeb953c60
diff --git a/litellm/proxy/policy_engine/policy_resolve_endpoints.py b/litellm/proxy/policy_engine/policy_resolve_endpoints.pyindex 27ee896c719..8f613694506 100644--- a/litellm/proxy/policy_engine/policy_resolve_endpoints.py+++ b/litellm/proxy/policy_engine/policy_resolve_endpoints.py@@ -12,18 +12,26 @@ from typing import TYPE_CHECKINGtry:from fastapi import APIRouter, Depends, HTTPException, Queryexcept ImportError:- # Provide stubs for environments without FastAPI+ # Provide stubs for type checking only+ if TYPE_CHECKING:+ from fastapi import APIRouter, Depends, HTTPException, Queryelse:# Create mock classes that won't be usedclass APIRouter: # type: ignore[no-redef]def post(self, *args, **kwargs):def decorator(func):return func+return decorator- def Depends(func): return func # type: ignore[misc]+ def Depends(func):+ return func # type: ignore[misc]+HTTPException = Exception # type: ignore[misc,assignment]- def Query(*args, **kwargs): return None # type: ignore[misc]++ def Query(*args, **kwargs):+ return None # type: ignore[misc]+from litellm._logging import verbose_proxy_loggerfrom litellm.constants import MAX_POLICY_ESTIMATE_IMPACT_ROWS@@ -93,7 +101,9 @@ def _get_tags_from_metadata(metadata: object, json_metadata: object = None) -> lasync def _fetch_all_teams(prisma_client: object) -> list:"""Fetch teams from DB once. Reuse the result across tag and alias lookups."""return await prisma_client.db.litellm_teamtable.find_many( # type: ignore- where={}, order={"created_at": "desc"}, take=MAX_POLICY_ESTIMATE_IMPACT_ROWS,+ where={},+ order={"created_at": "desc"},+ take=MAX_POLICY_ESTIMATE_IMPACT_ROWS,)@@ -175,7 +185,8 @@ async def _find_affected_by_team_patterns(if matched_team_ids:keys = await prisma_client.db.litellm_verificationtoken.find_many( # type: ignorewhere={"team_id": {"in": matched_team_ids}},- order={"created_at": "desc"}, take=MAX_POLICY_ESTIMATE_IMPACT_ROWS,+ order={"created_at": "desc"},+ take=MAX_POLICY_ESTIMATE_IMPACT_ROWS,)for key in keys:key_alias = key.key_alias or ""@@ -197,7 +208,8 @@ async def _find_affected_keys_by_alias(keys = await prisma_client.db.litellm_verificationtoken.find_many( # type: ignorewhere=_build_alias_where("key_alias", key_patterns),- order={"created_at": "desc"}, take=MAX_POLICY_ESTIMATE_IMPACT_ROWS,+ order={"created_at": "desc"},+ take=MAX_POLICY_ESTIMATE_IMPACT_ROWS,)for key in keys:key_alias = key.key_alias or ""@@ -380,19 +392,24 @@ async def estimate_attachment_impact(# Tag-based impactif tag_patterns:keys = await prisma_client.db.litellm_verificationtoken.find_many( # type: ignore- where={}, order={"created_at": "desc"},+ where={},+ order={"created_at": "desc"},take=MAX_POLICY_ESTIMATE_IMPACT_ROWS,)affected_keys, unnamed_keys = _filter_keys_by_tags(keys, tag_patterns)affected_teams, unnamed_teams = _filter_teams_by_tags(- all_teams, tag_patterns,+ all_teams,+ tag_patterns,)# Team-based impact (alias matching + keys belonging to those teams)if team_patterns:new_teams, new_keys, new_unnamed = await _find_affected_by_team_patterns(- prisma_client, all_teams, team_patterns,- affected_teams, affected_keys,+ prisma_client,+ all_teams,+ team_patterns,+ affected_teams,+ affected_keys,)affected_teams.extend(new_teams)affected_keys.extend(new_keys)@@ -402,7 +419,9 @@ async def estimate_attachment_impact(key_patterns = request.keys or []if key_patterns:new_keys = await _find_affected_keys_by_alias(- prisma_client, key_patterns, affected_keys,+ prisma_client,+ key_patterns,+ affected_keys,)affected_keys.extend(new_keys)