Add initial Portal version
This commit is contained in:
33
src/lib/litellm.ts
Normal file
33
src/lib/litellm.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
const LITELLM_URL =
|
||||
process.env.LITELLM_INTERNAL_URL ?? "http://litellm.inference.svc:4000";
|
||||
const LITELLM_MASTER_KEY = process.env.LITELLM_MASTER_KEY!;
|
||||
|
||||
async function litellmFetch(path: string, init?: RequestInit) {
|
||||
const res = await fetch(`${LITELLM_URL}${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
Authorization: `Bearer ${LITELLM_MASTER_KEY}`,
|
||||
"Content-Type": "application/json",
|
||||
...init?.headers,
|
||||
},
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`LiteLLM ${path}: ${res.status} ${await res.text()}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function getTeamInfo(teamId: string) {
|
||||
return litellmFetch(`/team/info?team_id=${encodeURIComponent(teamId)}`);
|
||||
}
|
||||
|
||||
export async function getTeamSpendLogs(
|
||||
teamId: string,
|
||||
startDate?: string,
|
||||
endDate?: string
|
||||
) {
|
||||
const params = new URLSearchParams({ team_id: teamId });
|
||||
if (startDate) params.set("start_date", startDate);
|
||||
if (endDate) params.set("end_date", endDate);
|
||||
return litellmFetch(`/global/spend/logs?${params}`);
|
||||
}
|
||||
Reference in New Issue
Block a user