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): link project page keys to their virtual key detail (#36002)

ryan-crabbe-berri1dab133d2437
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTable.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTable.test.tsx
index 3685d30b414..506de6ad43e 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTable.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTable.test.tsx
@@ -8,6 +8,12 @@ vi.mock("@/components/common_components/DefaultProxyAdminTag", () => ({
default: ({ userId }: { userId: string }) => <span data-testid="owner-tag">{userId}</span>,
}));
+const push = vi.fn();
+vi.mock("next/navigation", async () => ({
+ ...(await vi.importActual("next/navigation")),
+ useRouter: () => ({ push }),
+}));
+
const defaultProps = {
totalCount: 0,
isLoading: false,
@@ -100,6 +106,40 @@ describe("ProjectKeysTable", () => {
expect(screen.getByText("—")).toBeInTheDocument();
});
+ it("should link the key name to that key's detail on the Virtual Keys page", () => {
+ renderWithProviders(
+ <ProjectKeysTable {...defaultProps} keys={[makeKey({ token: "tok-abc123", key_alias: "My API Key" })]} />,
+ );
+ expect(screen.getByRole("link", { name: "My API Key" })).toHaveAttribute("href", "/ui/api-keys?key=tok-abc123");
+ });
+
+ it("should navigate to the key detail without a full page load when the key name is clicked", async () => {
+ const user = userEvent.setup();
+ push.mockClear();
+ renderWithProviders(
+ <ProjectKeysTable {...defaultProps} keys={[makeKey({ token: "tok-abc123", key_alias: "My API Key" })]} />,
+ );
+ await user.click(screen.getByRole("link", { name: "My API Key" }));
+ expect(push).toHaveBeenCalledWith("/ui/api-keys?key=tok-abc123");
+ });
+
+ it("should still link a key that has no alias", () => {
+ renderWithProviders(
+ <ProjectKeysTable
+ {...defaultProps}
+ keys={[makeKey({ token: "tok-no-alias", key_alias: "", user_id: "owner-1" })]}
+ />,
+ );
+ expect(screen.getByRole("link", { name: "—" })).toHaveAttribute("href", "/ui/api-keys?key=tok-no-alias");
+ });
+
+ it("should give each row a link to its own key", () => {
+ const keys = [makeKey({ token: "tok-1", key_alias: "Key One" }), makeKey({ token: "tok-2", key_alias: "Key Two" })];
+ renderWithProviders(<ProjectKeysTable {...defaultProps} keys={keys} />);
+ expect(screen.getByRole("link", { name: "Key One" })).toHaveAttribute("href", "/ui/api-keys?key=tok-1");
+ expect(screen.getByRole("link", { name: "Key Two" })).toHaveAttribute("href", "/ui/api-keys?key=tok-2");
+ });
+
it("should display the owner using user.user_email when available", () => {
const key = makeKey({ user: { user_id: "u1", user_email: "[email protected]", user_alias: null } });
renderWithProviders(<ProjectKeysTable {...defaultProps} keys={[key]} />);
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTableColumns.tsx b/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTableColumns.tsx
index b04a32844ea..591de71ce10 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTableColumns.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/projects/_components/ProjectKeysTableColumns.tsx
@@ -4,7 +4,8 @@ import { ColumnDef } from "@tanstack/react-table";
import DefaultProxyAdminTag from "@/components/common_components/DefaultProxyAdminTag";
import { KeyResponse } from "@/components/key_team_helpers/key_list";
-import { CellTooltip, DateCell } from "@/components/shared/table_cells";
+import { CellTooltip, DateCell, IdentityCell } from "@/components/shared/table_cells";
+import { keyDetailHref } from "@/utils/entityLinks";
function OwnerCell({ record }: { record: KeyResponse }) {
const email = record.user?.user_email ?? record.user_id ?? null;
@@ -29,9 +30,11 @@ export const getProjectKeysTableColumns = (): ColumnDef<KeyResponse>[] => [
header: "Key Name",
enableSorting: false,
cell: ({ row }) => (
- <span className="block max-w-60 truncate text-sm font-medium" title={row.original.key_alias ?? undefined}>
- {row.original.key_alias || "—"}
- </span>
+ <IdentityCell
+ title={<span title={row.original.key_alias ?? undefined}>{row.original.key_alias || "—"}</span>}
+ href={row.original.token ? keyDetailHref(row.original.token) : undefined}
+ className="max-w-60"
+ />
),
},
{
diff --git a/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.test.tsx b/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.test.tsx
index f3ec203adbb..9a91e163baf 100644
--- a/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.test.tsx
+++ b/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.test.tsx
@@ -4,6 +4,9 @@ import { describe, expect, it, vi } from "vitest";
import { IdentityCell } from "./identity_cell";
+const routerPush = vi.fn();
+vi.mock("next/navigation", () => ({ useRouter: () => ({ push: routerPush }) }));
+
describe("IdentityCell", () => {
it("renders the title", () => {
render(<IdentityCell title="prod-gateway" />);
@@ -38,4 +41,25 @@ describe("IdentityCell", () => {
await user.click(button);
expect(onClick).toHaveBeenCalledTimes(1);
});
+
+ it("renders an anchor with the chevron affordance and routes through the client router when href is set", async () => {
+ const user = userEvent.setup();
+ render(<IdentityCell title="routing-qa-key-alpha" href="/api-keys?key=abc123" />);
+ const link = screen.getByRole("link", { name: /routing-qa-key-alpha/ });
+ expect(link).toHaveAttribute("href", "/api-keys?key=abc123");
+ expect(link.querySelector(".lucide-chevron-right")).not.toBeNull();
+ expect(link.className).toContain("hover:bg-muted");
+ await user.click(link);
+ expect(routerPush).toHaveBeenCalledWith("/api-keys?key=abc123");
+ });
+
+ it("leaves modifier clicks to the browser so open-in-new-tab keeps working", async () => {
+ routerPush.mockClear();
+ const user = userEvent.setup();
+ render(<IdentityCell title="routing-qa-key-alpha" href="/api-keys?key=abc123" />);
+ await user.keyboard("{Meta>}");
+ await user.click(screen.getByRole("link", { name: /routing-qa-key-alpha/ }));
+ await user.keyboard("{/Meta}");
+ expect(routerPush).not.toHaveBeenCalled();
+ });
});
diff --git a/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.tsx b/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.tsx
index 97263436454..62ae04bbf88 100644
--- a/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.tsx
+++ b/ui/litellm-dashboard/src/components/shared/table_cells/identity_cell.tsx
@@ -1,6 +1,7 @@
"use client";
import { ChevronRight } from "lucide-react";
+import { useRouter } from "next/navigation";
import * as React from "react";
import { cn } from "@/lib/cva.config";
@@ -10,11 +11,19 @@ interface IdentityCellProps {
subtitle?: React.ReactNode;
badge?: React.ReactNode;
onClick?: () => void;
+ href?: string;
className?: string;
titleClassName?: string;
}
-export function IdentityCell({ title, subtitle, badge, onClick, className, titleClassName }: IdentityCellProps) {
+const INTERACTIVE_CELL_CLASSES =
+ "group -mx-2 flex w-[calc(100%+1rem)] cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-left transition-colors hover:bg-muted";
+
+const HoverChevron = () => (
+ <ChevronRight className="ml-auto size-4 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
+);
+
+export function IdentityCell({ title, subtitle, badge, onClick, href, className, titleClassName }: IdentityCellProps) {
const hasSubtitleRow = (subtitle != null && subtitle !== "") || badge != null;
const body = (
@@ -31,21 +40,37 @@ export function IdentityCell({ title, subtitle, badge, onClick, className, title
</div>
);
+ if (href != null) {
+ return <IdentityCellLink href={href} className={className} body={body} />;
+ }
+
if (onClick != null) {
return (
- <button
- type="button"
- onClick={onClick}
- className={cn(
- "group -mx-2 flex w-[calc(100%+1rem)] cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-left transition-colors hover:bg-muted",
- className,
- )}
- >
+ <button type="button" onClick={onClick} className={cn(INTERACTIVE_CELL_CLASSES, className)}>
{body}
- <ChevronRight className="ml-auto size-4 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
+ <HoverChevron />
</button>
);
}
return <div className={cn("min-w-0", className)}>{body}</div>;
}
+
+function IdentityCellLink({ href, className, body }: { href: string; className?: string; body: React.ReactNode }) {
+ const router = useRouter();
+
+ const handleClick = (e: React.MouseEvent) => {
+ const hasModifierKey = e.metaKey || e.ctrlKey || e.shiftKey;
+ const isNativeNewTabClick = hasModifierKey || e.button === 1;
+ if (isNativeNewTabClick) return;
+ e.preventDefault();
+ router.push(href);
+ };
+
+ return (
+ <a href={href} onClick={handleClick} className={cn(INTERACTIVE_CELL_CLASSES, className)}>
+ {body}
+ <HoverChevron />
+ </a>
+ );
+}
diff --git a/ui/litellm-dashboard/src/utils/entityLinks.ts b/ui/litellm-dashboard/src/utils/entityLinks.ts
index 2659a307866..85052448866 100644
--- a/ui/litellm-dashboard/src/utils/entityLinks.ts
+++ b/ui/litellm-dashboard/src/utils/entityLinks.ts
@@ -3,3 +3,7 @@ import { migratedHref } from "@/utils/migratedPages";
export function teamDetailHref(teamId: string): string {
return `${migratedHref("teams")}?team=${encodeURIComponent(teamId)}`;
}
+
+export function keyDetailHref(keyToken: string): string {
+ return `${migratedHref("api-keys")}?key=${encodeURIComponent(keyToken)}`;
+}