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 use view for getting tag usage

Ishaan Jaff67751d0eccba
diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py
index 0d6edd7702e..4031999d815 100644
--- a/litellm/proxy/utils.py
+++ b/litellm/proxy/utils.py
@@ -974,7 +974,7 @@ class PrismaClient:
)
"""
)
- if ret[0]["sum"] == 7:
+ if ret[0]["sum"] == 8:
print("All necessary views exist!") # noqa
return
except Exception:
@@ -1124,6 +1124,24 @@ class PrismaClient:
print("MonthlyGlobalSpendPerUserPerKey Created!") # noqa
+ try:
+ await self.db.query_raw("""SELECT 1 FROM "DailyTagSpend" LIMIT 1""")
+ print("DailyTagSpend Exists!") # noqa
+ except Exception as e:
+ sql_query = """
+ CREATE OR REPLACE VIEW DailyTagSpend AS
+ SELECT
+ jsonb_array_elements_text(request_tags) AS individual_request_tag,
+ DATE(s."startTime") AS spend_date,
+ COUNT(*) AS log_count,
+ SUM(spend) AS total_spend
+ FROM "LiteLLM_SpendLogs" s
+ GROUP BY individual_request_tag, DATE(s."startTime");
+ """
+ await self.db.execute_raw(query=sql_query)
+
+ print("DailyTagSpend Created!") # noqa
+
try:
await self.db.query_raw(
"""SELECT 1 FROM "Last30dTopEndUsersSpend" LIMIT 1"""