forked from phoenix/litellm-mirror
feat(proxy/utils.py): enable end_user + team id tracking in spend logs
allows separating proxy owner vs. end user in the spen d logs
This commit is contained in:
parent
d9e272942b
commit
c60fa9c84d
5 changed files with 18 additions and 6 deletions
|
@ -1152,9 +1152,9 @@ async def update_database(
|
||||||
payload["spend"] = response_cost
|
payload["spend"] = response_cost
|
||||||
if prisma_client is not None:
|
if prisma_client is not None:
|
||||||
await prisma_client.insert_data(data=payload, table_name="spend")
|
await prisma_client.insert_data(data=payload, table_name="spend")
|
||||||
|
|
||||||
elif custom_db_client is not None:
|
elif custom_db_client is not None:
|
||||||
await custom_db_client.insert_data(payload, table_name="spend")
|
await custom_db_client.insert_data(payload, table_name="spend")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
verbose_proxy_logger.info(f"Update Spend Logs DB failed to execute")
|
verbose_proxy_logger.info(f"Update Spend Logs DB failed to execute")
|
||||||
|
|
||||||
|
|
|
@ -97,8 +97,9 @@ model LiteLLM_SpendLogs {
|
||||||
cache_hit String @default("")
|
cache_hit String @default("")
|
||||||
cache_key String @default("")
|
cache_key String @default("")
|
||||||
request_tags Json @default("[]")
|
request_tags Json @default("[]")
|
||||||
|
team_id String?
|
||||||
|
end_user String?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Beta - allow team members to request access to a model
|
// Beta - allow team members to request access to a model
|
||||||
model LiteLLM_UserNotifications {
|
model LiteLLM_UserNotifications {
|
||||||
request_id String @unique
|
request_id String @unique
|
||||||
|
|
|
@ -1528,7 +1528,12 @@ def get_logging_payload(kwargs, response_obj, start_time, end_time):
|
||||||
"startTime": start_time,
|
"startTime": start_time,
|
||||||
"endTime": end_time,
|
"endTime": end_time,
|
||||||
"model": kwargs.get("model", ""),
|
"model": kwargs.get("model", ""),
|
||||||
"user": kwargs.get("user", ""),
|
"user": kwargs.get("litellm_params", {})
|
||||||
|
.get("metadata", {})
|
||||||
|
.get("user_api_key_user_id", ""),
|
||||||
|
"team_id": kwargs.get("litellm_params", {})
|
||||||
|
.get("metadata", {})
|
||||||
|
.get("user_api_key_team_id", ""),
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
"cache_key": cache_key,
|
"cache_key": cache_key,
|
||||||
"spend": kwargs.get("response_cost", 0),
|
"spend": kwargs.get("response_cost", 0),
|
||||||
|
@ -1536,6 +1541,7 @@ def get_logging_payload(kwargs, response_obj, start_time, end_time):
|
||||||
"prompt_tokens": usage.get("prompt_tokens", 0),
|
"prompt_tokens": usage.get("prompt_tokens", 0),
|
||||||
"completion_tokens": usage.get("completion_tokens", 0),
|
"completion_tokens": usage.get("completion_tokens", 0),
|
||||||
"request_tags": metadata.get("tags", []),
|
"request_tags": metadata.get("tags", []),
|
||||||
|
"end_user": kwargs.get("user", ""),
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose_proxy_logger.debug(f"SpendTable: created payload - payload: {payload}\n\n")
|
verbose_proxy_logger.debug(f"SpendTable: created payload - payload: {payload}\n\n")
|
||||||
|
|
|
@ -97,6 +97,8 @@ model LiteLLM_SpendLogs {
|
||||||
cache_hit String @default("")
|
cache_hit String @default("")
|
||||||
cache_key String @default("")
|
cache_key String @default("")
|
||||||
request_tags Json @default("[]")
|
request_tags Json @default("[]")
|
||||||
|
team_id String?
|
||||||
|
end_user String?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Beta - allow team members to request access to a model
|
// Beta - allow team members to request access to a model
|
||||||
|
|
|
@ -138,10 +138,13 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
|
||||||
console.log(`admins: ${admins?.length}`);
|
console.log(`admins: ${admins?.length}`);
|
||||||
return (
|
return (
|
||||||
<div className="w-full m-2">
|
<div className="w-full m-2">
|
||||||
<Title level={4}>Proxy Admins</Title>
|
<Title level={4}>Restricted Access</Title>
|
||||||
<Paragraph>
|
<Paragraph>
|
||||||
Add other people to just view global spend. They cannot create teams or
|
Add other people to just view spend. They cannot create keys, teams or
|
||||||
grant users access to new models.
|
grant users access to new models.{" "}
|
||||||
|
<a href="https://docs.litellm.ai/docs/proxy/ui#restrict-ui-access">
|
||||||
|
Requires SSO Setup
|
||||||
|
</a>
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<Grid numItems={1} className="gap-2 p-0 w-full">
|
<Grid numItems={1} className="gap-2 p-0 w-full">
|
||||||
<Col numColSpan={1}>
|
<Col numColSpan={1}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue