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]

perf(spend_tracking): index LiteLLM_SpendLogs by (api_key, startTime)

Etienne Chabert1bdc1b9b1747
diff --git a/litellm-proxy-extras/litellm_proxy_extras/migrations/20260823000000_add_spend_logs_api_key_starttime_index/migration.sql b/litellm-proxy-extras/litellm_proxy_extras/migrations/20260823000000_add_spend_logs_api_key_starttime_index/migration.sql
new file mode 100644
index 00000000000..9a061aaed43
--- /dev/null
+++ b/litellm-proxy-extras/litellm_proxy_extras/migrations/20260823000000_add_spend_logs_api_key_starttime_index/migration.sql
@@ -0,0 +1,2 @@
+-- CreateIndex
+CREATE INDEX IF NOT EXISTS "LiteLLM_SpendLogs_api_key_startTime_idx" ON "LiteLLM_SpendLogs"("api_key", "startTime");
diff --git a/litellm-proxy-extras/litellm_proxy_extras/schema.prisma b/litellm-proxy-extras/litellm_proxy_extras/schema.prisma
index 5582cf930d7..78e1631e114 100644
--- a/litellm-proxy-extras/litellm_proxy_extras/schema.prisma
+++ b/litellm-proxy-extras/litellm_proxy_extras/schema.prisma
@@ -647,6 +647,7 @@ model LiteLLM_SpendLogs {
@@index([startTime, request_id])
@@index([end_user])
@@index([session_id])
+ @@index([api_key, startTime])
}
// View spend, model, api_key per request
diff --git a/litellm/proxy/schema.prisma b/litellm/proxy/schema.prisma
index 5582cf930d7..78e1631e114 100644
--- a/litellm/proxy/schema.prisma
+++ b/litellm/proxy/schema.prisma
@@ -647,6 +647,7 @@ model LiteLLM_SpendLogs {
@@index([startTime, request_id])
@@index([end_user])
@@index([session_id])
+ @@index([api_key, startTime])
}
// View spend, model, api_key per request
diff --git a/schema.prisma b/schema.prisma
index 5582cf930d7..78e1631e114 100644
--- a/schema.prisma
+++ b/schema.prisma
@@ -647,6 +647,7 @@ model LiteLLM_SpendLogs {
@@index([startTime, request_id])
@@index([end_user])
@@index([session_id])
+ @@index([api_key, startTime])
}
// View spend, model, api_key per request