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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
return error client side from spend endpoints
Ishaan Jaff3eb0325063f3
diff --git a/litellm/proxy/spend_tracking/spend_management_endpoints.py b/litellm/proxy/spend_tracking/spend_management_endpoints.pyindex 7c8921c5d04..d6af6a93b10 100644--- a/litellm/proxy/spend_tracking/spend_management_endpoints.py+++ b/litellm/proxy/spend_tracking/spend_management_endpoints.py@@ -1752,32 +1752,53 @@ async def global_spend_logs(More efficient implementation of /spend/logs, by creating a view over the spend logs table."""+ import traceback+from litellm.proxy.proxy_server import 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" ORDER BY "date";"""+ try:+ 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" ORDER BY "date";"""- 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" = $1- ORDER BY "date";- """+ return response+ else:+ sql_query = """+ SELECT * FROM "MonthlyGlobalSpendPerKey"+ WHERE "api_key" = $1+ ORDER BY "date";+ """- response = await prisma_client.db.query_raw(sql_query, api_key)+ response = await prisma_client.db.query_raw(sql_query, api_key)- return response- return+ return response++ except Exception as e:+ error_trace = traceback.format_exc()+ error_str = str(e) + "\n" + error_trace+ if isinstance(e, HTTPException):+ raise ProxyException(+ message=getattr(e, "detail", f"/global/spend/logs Error({error_str})"),+ type="internal_error",+ param=getattr(e, "param", "None"),+ code=getattr(e, "status_code", status.HTTP_500_INTERNAL_SERVER_ERROR),+ )+ elif isinstance(e, ProxyException):+ raise e+ raise ProxyException(+ message="/global/spend/logs Error" + error_str,+ type="internal_error",+ param=getattr(e, "param", "None"),+ code=status.HTTP_500_INTERNAL_SERVER_ERROR,+ )@router.get(