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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(ui): add null guard for models in API keys table (#20655)
Varun Chawlac8d954709574
diff --git a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsx b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsxindex ef5bb2a0371..749396c82f3 100644--- a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsx+++ b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsx@@ -542,3 +542,86 @@ it("should display 'Default Proxy Admin' for created_by when value is 'default_uexpect(defaultProxyAdminElements.length).toBeGreaterThan(0);});});+++it("should render table without crashing when models is null", async () => {+ const keyWithNullModels = {+ ...mockKey,+ models: null as unknown as string[],+ };++ mockUseFilterLogic.mockReturnValue({+ filters: {+ "Team ID": "",+ "Organization ID": "",+ "Key Alias": "",+ "User ID": "",+ "Sort By": "created_at",+ "Sort Order": "desc",+ },+ filteredKeys: [keyWithNullModels],+ allKeyAliases: ["test-key-alias"],+ allTeams: [mockTeam],+ allOrganizations: [mockOrganization],+ handleFilterChange: vi.fn(),+ handleFilterReset: vi.fn(),+ });++ const mockProps = {+ teams: [mockTeam],+ organizations: [mockOrganization],+ onSortChange: vi.fn(),+ currentSort: {+ sortBy: "created_at",+ sortOrder: "desc" as const,+ },+ };++ // This should not throw an error+ renderWithProviders(<VirtualKeysTable {...mockProps} />);++ await waitFor(() => {+ expect(screen.getByText("Test Key Alias")).toBeInTheDocument();+ });+});++it("should render table without crashing when models is undefined", async () => {+ const keyWithUndefinedModels = {+ ...mockKey,+ models: undefined as unknown as string[],+ };++ mockUseFilterLogic.mockReturnValue({+ filters: {+ "Team ID": "",+ "Organization ID": "",+ "Key Alias": "",+ "User ID": "",+ "Sort By": "created_at",+ "Sort Order": "desc",+ },+ filteredKeys: [keyWithUndefinedModels],+ allKeyAliases: ["test-key-alias"],+ allTeams: [mockTeam],+ allOrganizations: [mockOrganization],+ handleFilterChange: vi.fn(),+ handleFilterReset: vi.fn(),+ });++ const mockProps = {+ teams: [mockTeam],+ organizations: [mockOrganization],+ onSortChange: vi.fn(),+ currentSort: {+ sortBy: "created_at",+ sortOrder: "desc" as const,+ },+ };++ // This should not throw an error+ renderWithProviders(<VirtualKeysTable {...mockProps} />);++ await waitFor(() => {+ expect(screen.getByText("Test Key Alias")).toBeInTheDocument();+ });+});diff --git a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsx b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsxindex 465b9b8fbe0..f7c47943e7e 100644--- a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsx+++ b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsx@@ -727,7 +727,7 @@ export function VirtualKeysTable({ teams, organizations, onSortChange, currentSowhiteSpace: "pre-wrap",overflow: "hidden",}}- className={`py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ${cell.column.id === "models" && (cell.getValue() as string[]).length > 3 ? "px-0" : ""}`}+ className={`py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ${cell.column.id === "models" && Array.isArray(cell.getValue()) && (cell.getValue() as string[]).length > 3 ? "px-0" : ""}`}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>