Skip to content

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]

fix(ui): align spend and budget columns (#35176)

daniel-meismer-zocdocb4a4277a271c
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/guardrails-monitor/page.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/guardrails-monitor/page.integration.test.tsx
index d4c68841299..fb521c0b8a3 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/guardrails-monitor/page.integration.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/guardrails-monitor/page.integration.test.tsx
@@ -46,8 +46,7 @@ describe("Guardrails Monitor page access by role", () => {
renderAs(userRole);
expect(await screen.findByText("Guardrails Monitor is only available to admin users.")).toBeInTheDocument();
- await waitFor(() => expect(fetchMock).not.toHaveBeenCalled());
- expect(requestedUrls().filter((url) => url.includes("/guardrails/usage"))).toEqual([]);
+ await waitFor(() => expect(requestedUrls().filter((url) => url.includes("/guardrails/usage"))).toEqual([]));
},
);
});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/memory/page.integration.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/memory/page.integration.test.tsx
index 8d15bb59187..40773381587 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/memory/page.integration.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/memory/page.integration.test.tsx
@@ -46,8 +46,7 @@ describe("Memory page access by role", () => {
renderAs(userRole);
expect(await screen.findByText("Memory is only available to admin users.")).toBeInTheDocument();
- await waitFor(() => expect(fetchMock).not.toHaveBeenCalled());
- expect(requestedUrls().filter((url) => url.includes("/v1/memory"))).toEqual([]);
+ await waitFor(() => expect(requestedUrls().filter((url) => url.includes("/v1/memory"))).toEqual([]));
},
);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTable.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTable.test.tsx
index 4689ef7cf96..6262fd60f70 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTable.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTable.test.tsx
@@ -123,6 +123,12 @@ describe("UsersTable", () => {
});
});
+ it("renders spend with two decimal places", () => {
+ render(<Harness data={[makeUser({ spend: 98.854 })]} />);
+
+ expect(screen.getByText("$98.85")).toBeInTheDocument();
+ });
+
// Sorting is server-side and the backend only accepts these five keys, so a sort
// control on any other column would send an invalid sort_by. Assert the exact set:
// a missing control and an extra one both have to fail.
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTableColumns.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTableColumns.tsx
index 6c569f205e5..d2888c675b0 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTableColumns.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/UsersTableColumns.tsx
@@ -163,7 +163,7 @@ export const getUsersTableColumns = ({
header: ({ column }) => <DataTableSortHeader column={column} title="Spend (USD)" variant="header-cycle" />,
size: 130,
enableSorting: true,
- cell: ({ row }) => <MoneyCell value={row.original.spend} decimals={4} />,
+ cell: ({ row }) => <MoneyCell value={row.original.spend} decimals={2} />,
},
{
id: "max_budget",
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.test.tsx
index 0a5c9523614..c704da301ad 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.test.tsx
@@ -122,6 +122,19 @@ describe("UserInfoView", () => {
expect(aliases.length).toBeGreaterThan(0);
});
+ it("should render overview spend and budget with two decimal places", async () => {
+ mockUserGetInfoV2.mockResolvedValue({
+ ...MOCK_USER_DATA,
+ spend: 98.854,
+ max_budget: 3_000_000,
+ });
+
+ render(<UserInfoView {...defaultProps} />);
+
+ expect(await screen.findByText("$98.85")).toBeInTheDocument();
+ expect(screen.getByText(/of \$3,000,000\.00/)).toBeInTheDocument();
+ });
+
it("should render teams in a table with team names", async () => {
render(<UserInfoView {...defaultProps} />);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx
index 5572c4dc4a9..7c7b6b51ef4 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/users/_components/view_users/user_info_view.tsx
@@ -521,10 +521,10 @@ export default function UserInfoView({
<Card>
<Text>Spend</Text>
<div className="mt-2">
- <Title>${formatNumberWithCommas(userData.spend || 0, 4)}</Title>
+ <Title>${formatNumberWithCommas(userData.spend || 0, 2)}</Title>
<Text>
of{" "}
- {userData.max_budget !== null ? `$${formatNumberWithCommas(userData.max_budget, 4)}` : "Unlimited"}
+ {userData.max_budget !== null ? `$${formatNumberWithCommas(userData.max_budget, 2)}` : "Unlimited"}
</Text>
</div>
</Card>
diff --git a/ui/litellm-dashboard/src/components/TeamsPage/TeamsTable.test.tsx b/ui/litellm-dashboard/src/components/TeamsPage/TeamsTable.test.tsx
index 09bd3e9f245..71c6aa66cf3 100644
--- a/ui/litellm-dashboard/src/components/TeamsPage/TeamsTable.test.tsx
+++ b/ui/litellm-dashboard/src/components/TeamsPage/TeamsTable.test.tsx
@@ -107,8 +107,8 @@ it("renders a team row with alias, organization, and spend/budget", async () =>
await waitFor(() => {
expect(screen.getByText("Acme Team")).toBeInTheDocument();
expect(screen.getByText("Test Organization")).toBeInTheDocument();
- expect(screen.getByText("$42.5000")).toBeInTheDocument();
- expect(screen.getByText("of $100")).toBeInTheDocument();
+ expect(screen.getByText("$42.50")).toBeInTheDocument();
+ expect(screen.getByText("of $100.00")).toBeInTheDocument();
});
});
diff --git a/ui/litellm-dashboard/src/components/TeamsPage/teamTableColumns.tsx b/ui/litellm-dashboard/src/components/TeamsPage/teamTableColumns.tsx
index ecf7387ee83..e57378310f0 100644
--- a/ui/litellm-dashboard/src/components/TeamsPage/teamTableColumns.tsx
+++ b/ui/litellm-dashboard/src/components/TeamsPage/teamTableColumns.tsx
@@ -209,7 +209,14 @@ export const getTeamTableColumns = ({
header: "Spend / Budget",
size: 200,
enableSorting: false,
- cell: ({ row }) => <SpendBudgetCell spend={row.original.spend} maxBudget={row.original.max_budget} />,
+ cell: ({ row }) => (
+ <SpendBudgetCell
+ spend={row.original.spend}
+ maxBudget={row.original.max_budget}
+ spendDecimals={2}
+ budgetDecimals={2}
+ />
+ ),
},
{
id: "created_at",
diff --git a/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.test.tsx b/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.test.tsx
index 473785e31c4..e6f9f092f3a 100644
--- a/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.test.tsx
+++ b/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.test.tsx
@@ -4,21 +4,25 @@ import { describe, expect, it } from "vitest";
import { MoneyCell } from "./money_cell";
describe("MoneyCell", () => {
- it("renders '-' for null and undefined", () => {
+ it("renders '-' for missing and non-finite values", () => {
const { rerender } = render(<MoneyCell value={null} />);
expect(screen.getByText("-")).toBeInTheDocument();
rerender(<MoneyCell value={undefined} />);
expect(screen.getByText("-")).toBeInTheDocument();
+ rerender(<MoneyCell value={Number.NaN} />);
+ expect(screen.getByText("-")).toBeInTheDocument();
+ rerender(<MoneyCell value={Number.POSITIVE_INFINITY} />);
+ expect(screen.getByText("-")).toHaveClass("w-full", "text-right", "tabular-nums");
});
it("renders the custom emptyText for null budgets", () => {
render(<MoneyCell value={null} emptyText="Unlimited" />);
- expect(screen.getByText("Unlimited")).toBeInTheDocument();
+ expect(screen.getByText("Unlimited")).toHaveClass("w-full", "text-right", "tabular-nums");
});
it("renders '-' for zero by default", () => {
render(<MoneyCell value={0} />);
- expect(screen.getByText("-")).toBeInTheDocument();
+ expect(screen.getByText("-")).toHaveClass("w-full", "text-right", "tabular-nums");
});
it("renders a formatted zero when showZero is set, never the emptyText", () => {
@@ -28,8 +32,16 @@ describe("MoneyCell", () => {
});
it("formats amounts with commas, a dollar sign and the given decimals", () => {
- render(<MoneyCell value={1234.5678} decimals={2} />);
+ const { container } = render(<MoneyCell value={1234.5678} decimals={2} />);
expect(screen.getByText("$1,234.57")).toBeInTheDocument();
+ expect(container.querySelector('[data-slot="money-cell"]')).toHaveClass(
+ "block",
+ "w-full",
+ "text-right",
+ "tabular-nums",
+ );
+ expect(container.querySelector('[data-slot="money-cell"]')).not.toHaveAttribute("aria-hidden");
+ expect(screen.getAllByText("$1,234.57")).toHaveLength(1);
});
it("defaults to 4 decimals", () => {
@@ -38,7 +50,8 @@ describe("MoneyCell", () => {
});
it("renders the sub-threshold form for amounts that round to zero", () => {
- render(<MoneyCell value={0.0000001} decimals={6} />);
+ const { container } = render(<MoneyCell value={0.0000001} decimals={6} />);
expect(screen.getByText("< $0.000001")).toBeInTheDocument();
+ expect(container.querySelector('[data-slot="money-cell"]')).toHaveTextContent("< $0.000001");
});
});
diff --git a/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.tsx b/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.tsx
index 9d3c747b20e..0676b801cc1 100644
--- a/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.tsx
+++ b/ui/litellm-dashboard/src/components/shared/table_cells/money_cell.tsx
@@ -9,15 +9,23 @@ interface MoneyCellProps {
showZero?: boolean;
}
+const placeholderClassName = "block w-full whitespace-nowrap text-right tabular-nums text-muted-foreground";
+const moneyClassName = "block w-full whitespace-nowrap text-right tabular-nums";
+
export function MoneyCell({ value, decimals = 4, emptyText = "-", showZero = false }: MoneyCellProps) {
- if (value === null || value === undefined || Number.isNaN(value)) {
- return <span className="text-muted-foreground">{emptyText}</span>;
+ if (value === null || value === undefined || !Number.isFinite(value)) {
+ return <span className={placeholderClassName}>{emptyText}</span>;
}
- if (value === 0) {
- if (!showZero) {
- return <span className="text-muted-foreground">-</span>;
- }
- return <span className="whitespace-nowrap">{`$${formatNumberWithCommas(0, decimals, false, true)}`}</span>;
+ if (value === 0 && !showZero) {
+ return <span className={placeholderClassName}>-</span>;
}
- return <span className="whitespace-nowrap">{getSpendString(value, decimals)}</span>;
+
+ const formattedValue =
+ value === 0 ? `$${formatNumberWithCommas(0, decimals, false, true)}` : getSpendString(value, decimals);
+
+ return (
+ <span data-slot="money-cell" className={moneyClassName}>
+ {formattedValue}
+ </span>
+ );
}
diff --git a/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.test.tsx b/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.test.tsx
index 707441aef1d..d4af8428d69 100644
--- a/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.test.tsx
+++ b/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.test.tsx
@@ -30,6 +30,14 @@ describe("SpendBudgetCell", () => {
expect(screen.getByText("of $100")).toBeInTheDocument();
});
+ it("supports matching spend and budget precision for summary views", () => {
+ render(<SpendBudgetCell spend={98.854} maxBudget={3000} spendDecimals={2} budgetDecimals={2} />);
+
+ expect(screen.getByText("$98.85")).toBeInTheDocument();
+ expect(screen.getByText("of $3,000.00")).toBeInTheDocument();
+ expect(screen.getByRole("meter")).toHaveAttribute("aria-valuetext", "$98.85 of $3,000.00");
+ });
+
it("keeps the default tone below 80% usage", () => {
const { container } = render(<SpendBudgetCell spend={50} maxBudget={100} />);
expect(indicator(container)?.className).toContain("bg-primary");
diff --git a/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.tsx b/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.tsx
index 10956f23b1c..60b42615967 100644
--- a/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.tsx
+++ b/ui/litellm-dashboard/src/components/shared/table_cells/spend_budget_cell.tsx
@@ -7,6 +7,8 @@ interface SpendBudgetCellProps {
spend: number | null | undefined;
maxBudget: number | null | undefined;
teamMaxBudget?: number | null;
+ spendDecimals?: number;
+ budgetDecimals?: number;
}
const meterTone = (pct: number): "default" | "warning" | "over" => {
@@ -15,16 +17,24 @@ const meterTone = (pct: number): "default" | "warning" | "over" => {
return "default";
};
-export function SpendBudgetCell({ spend, maxBudget, teamMaxBudget }: SpendBudgetCellProps) {
+export function SpendBudgetCell({
+ spend,
+ maxBudget,
+ teamMaxBudget,
+ spendDecimals = 4,
+ budgetDecimals = 0,
+}: SpendBudgetCellProps) {
const spendValue = typeof spend === "number" && !Number.isNaN(spend) ? spend : 0;
const budget = maxBudget ?? teamMaxBudget ?? null;
const isTeamBudget = maxBudget == null && teamMaxBudget != null;
const hasBudget = typeof budget === "number" && budget > 0;
const pct = hasBudget ? (spendValue / budget) * 100 : 0;
- const spendText = spendValue > 0 ? getSpendString(spendValue, 4) : "$0.00";
+ const spendText = spendValue > 0 ? getSpendString(spendValue, spendDecimals) : "$0.00";
const budgetLabel =
- budget === null ? "· Unlimited" : `of $${formatNumberWithCommas(budget)}${isTeamBudget ? " (Team)" : ""}`;
+ budget === null
+ ? "· Unlimited"
+ : `of $${formatNumberWithCommas(budget, budgetDecimals)}${isTeamBudget ? " (Team)" : ""}`;
return (
<div className="flex min-w-[130px] flex-col gap-1">
@@ -33,7 +43,11 @@ export function SpendBudgetCell({ spend, maxBudget, teamMaxBudget }: SpendBudget
<span className="text-muted-foreground">{budgetLabel}</span>
</div>
{hasBudget && (
- <Meter value={spendValue} max={budget} aria-valuetext={`${spendText} of $${formatNumberWithCommas(budget)}`}>
+ <Meter
+ value={spendValue}
+ max={budget}
+ aria-valuetext={`${spendText} of $${formatNumberWithCommas(budget, budgetDecimals)}`}
+ >
<MeterTrack>
<MeterIndicator tone={meterTone(pct)} />
</MeterTrack>
diff --git a/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx b/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
index f0774537fd9..d6df58ec0f8 100644
--- a/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamInfo.test.tsx
@@ -311,6 +311,8 @@ describe("TeamInfoView", () => {
await waitFor(() => {
expect(screen.getByText("Budget Status")).toBeInTheDocument();
});
+ expect(screen.getByText("$250.50")).toBeInTheDocument();
+ expect(screen.getByText(/of \$1,000\.00/)).toBeInTheDocument();
});
it("should display guardrails in overview when present", async () => {
@@ -363,6 +365,7 @@ describe("TeamInfoView", () => {
await waitFor(() => {
expect(screen.getByText("Budget Status")).toBeInTheDocument();
});
+ expect(screen.getByText("Team Member Budget: $500.00")).toBeInTheDocument();
});
it("should display virtual keys information", async () => {
diff --git a/ui/litellm-dashboard/src/components/team/TeamInfo.tsx b/ui/litellm-dashboard/src/components/team/TeamInfo.tsx
index d4cf8ca2d27..eae11d481e3 100644
--- a/ui/litellm-dashboard/src/components/team/TeamInfo.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamInfo.tsx
@@ -762,15 +762,15 @@ const TeamInfoView: React.FC<TeamInfoProps> = ({
<Card>
<Text>Budget Status</Text>
<div className="mt-2">
- <Title>${formatNumberWithCommas(info.spend, 4)}</Title>
+ <Title>${formatNumberWithCommas(info.spend, 2)}</Title>
<Text>
- of {info.max_budget === null ? "Unlimited" : `$${formatNumberWithCommas(info.max_budget, 4)}`}
+ of {info.max_budget === null ? "Unlimited" : `$${formatNumberWithCommas(info.max_budget, 2)}`}
</Text>
{info.budget_duration && <Text className="text-gray-500">Reset: {info.budget_duration}</Text>}
<br />
{info.team_member_budget_table && (
<Text className="text-gray-500">
- Team Member Budget: ${formatNumberWithCommas(info.team_member_budget_table.max_budget, 4)}
+ Team Member Budget: ${formatNumberWithCommas(info.team_member_budget_table.max_budget, 2)}
</Text>
)}
</div>
diff --git a/ui/litellm-dashboard/src/components/team/TeamMemberTab.test.tsx b/ui/litellm-dashboard/src/components/team/TeamMemberTab.test.tsx
index a07c57eaa30..04234cf5a5e 100644
--- a/ui/litellm-dashboard/src/components/team/TeamMemberTab.test.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamMemberTab.test.tsx
@@ -71,6 +71,7 @@ const createMockTeamData = (overrides: Partial<TeamData> = {}): TeamData => ({
team_id: "team-123",
budget_id: "budget1",
spend: 100.5,
+ total_spend: 1538.2608,
litellm_budget_table: {
budget_id: "budget1",
soft_budget: null,
@@ -246,7 +247,8 @@ describe("TeamMembersComponent", () => {
/>,
);
- expect(screen.getByText("$100.5000")).toBeInTheDocument();
+ expect(screen.getByText("$100.50")).toBeInTheDocument();
+ expect(screen.getByText("$1,538.26")).toBeInTheDocument();
expect(screen.getByText(/100 RPM/)).toBeInTheDocument();
expect(screen.getByText(/10000 TPM/)).toBeInTheDocument();
});
@@ -278,7 +280,7 @@ describe("TeamMembersComponent", () => {
/>,
);
- expect(screen.getByText("$1,000.0000")).toBeInTheDocument();
+ expect(screen.getByText("$1,000.00")).toBeInTheDocument();
expect(screen.getByText("Unlimited")).toBeInTheDocument();
});
diff --git a/ui/litellm-dashboard/src/components/team/TeamMemberTab.tsx b/ui/litellm-dashboard/src/components/team/TeamMemberTab.tsx
index b884490efc0..4e04063197c 100644
--- a/ui/litellm-dashboard/src/components/team/TeamMemberTab.tsx
+++ b/ui/litellm-dashboard/src/components/team/TeamMemberTab.tsx
@@ -142,7 +142,7 @@ export default function TeamMemberTab({
),
key: "spend",
render: (_: unknown, record: Member) => (
- <MoneyCell value={getUserCurrentCycleSpend(record.user_id)} decimals={4} />
+ <MoneyCell value={getUserCurrentCycleSpend(record.user_id)} decimals={2} />
),
},
{
@@ -155,13 +155,13 @@ export default function TeamMemberTab({
</Space>
),
key: "total_spend",
- render: (_: unknown, record: Member) => <MoneyCell value={getUserTotalSpend(record.user_id)} decimals={4} />,
+ render: (_: unknown, record: Member) => <MoneyCell value={getUserTotalSpend(record.user_id)} decimals={2} />,
},
{
title: "Team Member Budget (USD)",
key: "budget",
render: (_: unknown, record: Member) => (
- <MoneyCell value={getUserBudget(record.user_id)} decimals={4} emptyText="Unlimited" showZero />
+ <MoneyCell value={getUserBudget(record.user_id)} decimals={2} emptyText="Unlimited" showZero />
),
},
{