Merge branch 'main' into litellm_end_user_spend_tracking

This commit is contained in:
Krish Dholakia 2024-02-29 19:31:19 -08:00 committed by GitHub
commit 5f9cd5a4f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 305 additions and 135 deletions

View file

@ -4069,7 +4069,12 @@ async def view_spend_logs(
tags=["Budget & Spend Tracking"],
dependencies=[Depends(user_api_key_auth)],
)
async def global_spend_logs():
async def global_spend_logs(
api_key: str = fastapi.Query(
default=None,
description="API Key to get global spend (spend per day for last 30d). Admin-only endpoint",
)
):
"""
[BETA] This is a beta endpoint. It will change.
@ -4078,12 +4083,34 @@ async def global_spend_logs():
More efficient implementation of /spend/logs, by creating a view over the spend logs table.
"""
global prisma_client
if prisma_client is None:
raise ProxyException(
message="Prisma Client is not initialized",
type="internal_error",
param="None",
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
if api_key is None:
sql_query = """SELECT * FROM "MonthlyGlobalSpend";"""
sql_query = """SELECT * FROM "MonthlyGlobalSpend";"""
response = await prisma_client.db.query_raw(query=sql_query)
response = await prisma_client.db.query_raw(query=sql_query)
return response
else:
sql_query = (
"""
SELECT * FROM "MonthlyGlobalSpendPerKey"
WHERE "api_key" = '"""
+ api_key
+ """'
ORDER BY "date";
"""
)
return response
response = await prisma_client.db.query_raw(query=sql_query)
return response
return
@router.get(