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(proxy): use parameterized query for combined_view token lookup

jayden4dc416ee7491
diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py
index 635204f3362..a62f34764d3 100644
--- a/litellm/proxy/utils.py
+++ b/litellm/proxy/utils.py
@@ -2645,7 +2645,7 @@ class PrismaClient:
raise e
async def _query_first_with_cached_plan_fallback(
- self, sql_query: str
+ self, sql_query: str, *args
) -> Optional[dict]:
"""
Execute a query with automatic fallback for PostgreSQL cached plan errors.
@@ -2664,7 +2664,7 @@ class PrismaClient:
Original exception if not a cached plan error
"""
try:
- return await self.db.query_first(query=sql_query)
+ return await self.db.query_first(sql_query, *args)
except Exception as e:
error_str = str(e)
if "cached plan must not change result type" in error_str:
@@ -2679,7 +2679,7 @@ class PrismaClient:
"retrying with fresh plan. This may occur during rolling deployments "
"when schema changes are applied."
)
- return await self.db.query_first(query=sql_query_retry)
+ return await self.db.query_first(sql_query_retry, *args)
else:
raise
@@ -3016,11 +3016,11 @@ class PrismaClient:
LEFT JOIN "LiteLLM_ProjectTable" AS p ON v.project_id = p.project_id
LEFT JOIN "LiteLLM_OrganizationTable" AS o ON v.organization_id = o.organization_id
LEFT JOIN "LiteLLM_BudgetTable" AS b2 ON o.budget_id = b2.budget_id
- WHERE v.token = '{token}'
+ WHERE v.token = $1
"""
response = await self._query_first_with_cached_plan_fallback(
- sql_query
+ sql_query, hashed_token
)
# If not found in main table, check deprecated keys (grace period)