Merge pull request #1590 from BerriAI/litellm_spend_logs_by_key

feat(proxy_server.py): enable returning spend logs by api key
This commit is contained in:
Krish Dholakia 2024-01-24 14:45:25 -08:00 committed by GitHub
commit ed77f2d682
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 10 deletions

View file

@ -361,7 +361,7 @@ class PrismaClient:
self,
token: Optional[str] = None,
user_id: Optional[str] = None,
request_id: Optional[str] = None,
key_val: Optional[dict] = None,
table_name: Optional[Literal["user", "key", "config", "spend"]] = None,
query_type: Literal["find_unique", "find_all"] = "find_unique",
expires: Optional[datetime] = None,
@ -441,12 +441,19 @@ class PrismaClient:
verbose_proxy_logger.debug(
f"PrismaClient: get_data: table_name == 'spend'"
)
if request_id is not None:
response = await self.db.litellm_spendlogs.find_unique( # type: ignore
where={
"request_id": request_id,
}
)
if key_val is not None:
if query_type == "find_unique":
response = await self.db.litellm_spendlogs.find_unique( # type: ignore
where={ # type: ignore
key_val["key"]: key_val["value"], # type: ignore
}
)
elif query_type == "find_all":
response = await self.db.litellm_spendlogs.find_many( # type: ignore
where={
key_val["key"]: key_val["value"], # type: ignore
}
)
return response
else:
response = await self.db.litellm_spendlogs.find_many( # type: ignore