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]

feat(ui): give the budgets page a standard header and default column set

Yuneng Jiang2769fbe37b0d
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.test.tsx
index 0c485adf4f2..f78ba34770d 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.test.tsx
@@ -52,6 +52,11 @@ const FORBIDDEN_PROBLEM = {
detail: "Only proxy admins can view budgets",
};
+const showColumn = async (user: ReturnType<typeof userEvent.setup>, columnId: string) => {
+ await user.click(screen.getByTestId("view-options-trigger"));
+ await user.click(await screen.findByTestId(`view-option-${columnId}`));
+};
+
const defaultProps = {
canModify: true,
onEditClick: vi.fn(),
@@ -72,14 +77,26 @@ describe("BudgetTable", () => {
expect(screen.getByText("10")).toBeInTheDocument();
});
- it("should render the reset column with the friendly duration label", () => {
+ it("should open on the four columns the page has always shown, with reset and created off", () => {
renderWithProviders(<BudgetTable {...defaultProps} list={makeList()} />);
+ const headers = screen.getAllByRole("columnheader").map((header) => header.textContent);
+ expect(headers).toEqual(expect.arrayContaining(["Budget ID", "Max Budget", "TPM", "RPM"]));
+ expect(headers).not.toContain("Reset");
+ expect(headers).not.toContain("Created");
+ });
+
+ it("should render the reset column with the friendly duration label once it is turned on", async () => {
+ const user = userEvent.setup();
+ renderWithProviders(<BudgetTable {...defaultProps} list={makeList()} />);
+ await showColumn(user, "budget_duration");
expect(screen.getByText("monthly")).toBeInTheDocument();
});
- it("should render 'Not set' when a budget has no reset duration", () => {
+ it("should render 'Not set' when a budget has no reset duration", async () => {
+ const user = userEvent.setup();
const list = makeList({ rows: [makeBudget({ budget_duration: null })] });
renderWithProviders(<BudgetTable {...defaultProps} list={list} />);
+ await showColumn(user, "budget_duration");
expect(screen.getByText("Not set")).toBeInTheDocument();
});
@@ -109,16 +126,21 @@ describe("BudgetTable", () => {
});
it("should offer sorting on every backend-sortable column", async () => {
+ const user = userEvent.setup();
renderWithProviders(<BudgetTable {...defaultProps} list={makeList()} />);
+ await showColumn(user, "created_at");
for (const field of ["budget_id", "max_budget", "tpm_limit", "rpm_limit", "created_at"]) {
expect(screen.getByTestId(`sort-header-${field}`)).toBeInTheDocument();
}
});
- it("should not make the reset column sortable", () => {
+ it("should not make the reset column sortable", async () => {
+ const user = userEvent.setup();
renderWithProviders(<BudgetTable {...defaultProps} list={makeList()} />);
+ await showColumn(user, "budget_duration");
+ const headers = screen.getAllByRole("columnheader").map((header) => header.textContent);
+ expect(headers).toContain("Reset");
expect(screen.queryByTestId("sort-header-budget_duration")).not.toBeInTheDocument();
- expect(screen.getByText("Reset")).toBeInTheDocument();
});
it("should ask the list for a new sort when a sortable header is clicked", async () => {
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.tsx b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.tsx
index 76355c874f8..88e40dfba2f 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTable.tsx
@@ -23,7 +23,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ApiError } from "@/lib/http/client";
-import { getBudgetTableColumns } from "./BudgetTableColumns";
+import { BUDGET_TABLE_HIDDEN_COLUMNS, getBudgetTableColumns } from "./BudgetTableColumns";
interface BudgetTableProps {
list: ResourceListResult<budgetItem>;
@@ -225,6 +225,7 @@ const BudgetTable: React.FC<BudgetTableProps> = ({ list, canModify, onEditClick,
data={list.rows}
columns={columns}
getRowId={(budget, index) => budget.budget_id || String(index)}
+ defaultColumnVisibility={BUDGET_TABLE_HIDDEN_COLUMNS}
sortingMode="server"
sorting={list.sorting}
onSortingChange={list.onSortingChange}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTableColumns.tsx b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTableColumns.tsx
index d1192468359..e5cd9043492 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTableColumns.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/BudgetTableColumns.tsx
@@ -75,6 +75,12 @@ function BudgetRowActions({ budget, onEditClick, onDeleteClick }: BudgetRowActio
);
}
+/** Off by default so the table opens on the four columns it has always shown; the Columns menu turns them on. */
+export const BUDGET_TABLE_HIDDEN_COLUMNS: Record<string, boolean> = {
+ budget_duration: false,
+ created_at: false,
+};
+
interface BudgetTableColumnsDeps {
canModify: boolean;
onEditClick: (budget: budgetItem) => void;
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/budget_panel.tsx b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/budget_panel.tsx
index 78c2c0ca74a..fbcbd501313 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/budget_panel.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/budgets/_components/budget_panel.tsx
@@ -3,8 +3,10 @@
*
*/
+import { Plus, Wallet } from "lucide-react";
import React, { useCallback, useState } from "react";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
+import { PageHeader } from "@/components/shared/PageHeader";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import DeleteResourceModal from "@/components/common_components/DeleteResourceModal";
@@ -76,11 +78,19 @@ const BudgetPanel: React.FC<BudgetSettingsPageProps> = ({ accessToken }) => {
};
return (
- <div className="w-full mx-auto flex-auto overflow-y-auto m-8 p-2">
+ <div className="flex flex-col gap-4 p-6 px-12">
+ <PageHeader
+ icon={<Wallet className="size-5" />}
+ title="Budgets"
+ subtitle="Spend, TPM and RPM limits you can assign to customers."
+ />
{canModify && (
- <Button size="sm" className="mb-2" onClick={() => setIsCreateModelVisible(true)}>
- + Create Budget
- </Button>
+ <div>
+ <Button onClick={() => setIsCreateModelVisible(true)}>
+ <Plus className="size-4" />
+ Create Budget
+ </Button>
+ </div>
)}
<Tabs defaultValue="budgets">
<TabsList variant="line" className="h-auto w-full justify-start rounded-none border-b p-0">
@@ -101,7 +111,6 @@ const BudgetPanel: React.FC<BudgetSettingsPageProps> = ({ accessToken }) => {
existingBudget={selectedBudget}
/>
)}
- <p className="mb-4 text-sm text-muted-foreground">Create a budget to assign to customers.</p>
<BudgetTable
list={budgetList}
canModify={canModify}