Add Health and Spend for Admins
This commit is contained in:
@@ -47,4 +47,58 @@ export async function getTeamSpendLogsV2(
|
||||
page_size: String(pageSize),
|
||||
});
|
||||
return litellmFetch(`/spend/logs/v2?${params}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all teams registered in LiteLLM.
|
||||
* Returns team_id, spend, max_budget, etc.
|
||||
*/
|
||||
export async function listTeams(): Promise<any[]> {
|
||||
const data = await litellmFetch("/team/list");
|
||||
// LiteLLM returns either an array or { data: [...] }
|
||||
return Array.isArray(data) ? data : data?.data ?? data?.teams ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get LiteLLM health status.
|
||||
*/
|
||||
export async function getLitellmHealth(): Promise<{
|
||||
healthy: boolean;
|
||||
details?: any;
|
||||
}> {
|
||||
try {
|
||||
const data = await litellmFetch("/health");
|
||||
return { healthy: true, details: data };
|
||||
} catch (e: any) {
|
||||
return { healthy: false, details: e.message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global spend across all teams for the current month.
|
||||
*/
|
||||
export async function getGlobalSpend(): Promise<number> {
|
||||
try {
|
||||
const data = await litellmFetch("/global/spend");
|
||||
// LiteLLM returns { spend: number } or similar
|
||||
if (typeof data === "number") return data;
|
||||
return data?.spend ?? data?.total_spend ?? 0;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch per-team spend as a map: teamId → spend (CHF).
|
||||
* Uses /team/list which includes current spend per team.
|
||||
*/
|
||||
export async function getPerTeamSpend(): Promise<Map<string, number>> {
|
||||
const teams = await listTeams();
|
||||
const map = new Map<string, number>();
|
||||
for (const team of teams) {
|
||||
const id = team.team_id ?? team.id;
|
||||
const spend = team.spend ?? 0;
|
||||
if (id) map.set(id, spend);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user