fix(proxy_server.py): introduces a beta endpoint for admin to view global spend

This commit is contained in:
Krrish Dholakia 2024-02-28 12:47:51 -08:00
parent a042092faa
commit 6a94ef6c16
4 changed files with 183 additions and 19 deletions

View file

@ -3788,7 +3788,7 @@ async def view_spend_tags(
@router.get(
"/spend/logs",
tags=["budget & spend Tracking"],
tags=["Budget & Spend Tracking"],
dependencies=[Depends(user_api_key_auth)],
responses={
200: {"model": List[LiteLLM_SpendLogs]},
@ -4048,6 +4048,28 @@ async def view_spend_logs(
)
@router.get(
"/global/spend/logs",
tags=["Budget & Spend Tracking"],
dependencies=[Depends(user_api_key_auth)],
)
async def global_spend_logs():
"""
[BETA] This is a beta endpoint.
Use this to get global spend (spend per day for last 30d). Admin-only endpoint
More efficient implementation of /spend/logs, by creating a view over the spend logs table.
"""
global prisma_client
sql_query = """SELECT * FROM "globalspendperdate";"""
response = await prisma_client.db.query_raw(query=sql_query)
return response
@router.get(
"/daily_metrics",
summary="Get daily spend metrics",