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): migrate api-keys landing to App Router path route (#30699)

ryan-crabbe-berri32bdd004bd21
diff --git a/ui/litellm-dashboard/e2e_tests/fixtures/migratedPages.ts b/ui/litellm-dashboard/e2e_tests/fixtures/migratedPages.ts
index cd9178db108..58939ca2b9a 100644
--- a/ui/litellm-dashboard/e2e_tests/fixtures/migratedPages.ts
+++ b/ui/litellm-dashboard/e2e_tests/fixtures/migratedPages.ts
@@ -11,6 +11,7 @@
* Keep this in lockstep with MIGRATED_PAGES in src/utils/migratedPages.ts.
*/
export const MIGRATED_E2E_PAGES: Record<string, string> = {
+ "api-keys": "api-keys",
models: "models-and-endpoints",
api_ref: "api-reference",
"llm-playground": "playground",
diff --git a/ui/litellm-dashboard/e2e_tests/tests/migration/migratedPages.spec.ts b/ui/litellm-dashboard/e2e_tests/tests/migration/migratedPages.spec.ts
index c512ab2ddfb..0a3be326e42 100644
--- a/ui/litellm-dashboard/e2e_tests/tests/migration/migratedPages.spec.ts
+++ b/ui/litellm-dashboard/e2e_tests/tests/migration/migratedPages.spec.ts
@@ -17,11 +17,11 @@ const ROOT = process.env.SERVER_ROOT_PATH ?? "";
const esc = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const pathRe = (segment: string) => new RegExp(`${esc(ROOT)}/ui/${esc(segment)}/?($|\\?)`);
-const legacyAnchor = (page: Page) => page.getByRole("link", { name: "Virtual Keys", exact: true });
+const virtualKeysLink = (page: Page) => page.getByRole("link", { name: "Virtual Keys", exact: true });
/** The dashboard shell is present (sidebar rendered); page didn't 404 / crash. */
async function expectRendered(page: Page) {
- await expect(legacyAnchor(page)).toBeVisible({ timeout: 20_000 });
+ await expect(virtualKeysLink(page)).toBeVisible({ timeout: 20_000 });
}
/**
@@ -45,7 +45,7 @@ test.use({ storageState: ADMIN_STORAGE_PATH });
test.describe("App Router migrated pages", () => {
for (const segment of MIGRATED_E2E_SEGMENTS) {
- test(`${segment}: sidebar nav, reload, and round-trip with a legacy page`, async ({ page }) => {
+ test(`${segment}: sidebar nav, reload, and round-trip via the api-keys landing`, async ({ page }) => {
const pageErrors: string[] = [];
page.on("pageerror", (e) => pageErrors.push(String(e)));
@@ -63,9 +63,9 @@ test.describe("App Router migrated pages", () => {
await dismissFeedbackPopup(page);
await expect(page).toHaveURL(pathRe(segment));
await expectRendered(page);
- // 4. Click off to a legacy (not-yet-migrated) page.
- await legacyAnchor(page).click();
- await expect(page).toHaveURL(new RegExp(`${esc(ROOT)}/ui/\\?page=api-keys`));
+ // 4. Click the Virtual Keys sidebar link to the api-keys landing (now a path route), then back.
+ await virtualKeysLink(page).click();
+ await expect(page).toHaveURL(pathRe("api-keys"));
await dismissFeedbackPopup(page);
await expectRendered(page);
// 5. Click back to the migrated page.
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/api-keys/ApiKeysDashboard.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-keys/ApiKeysDashboard.tsx
new file mode 100644
index 00000000000..9c8bdd5c56f
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-keys/ApiKeysDashboard.tsx
@@ -0,0 +1,100 @@
+"use client";
+
+import { teamListCall as v2TeamListCall } from "@/app/(dashboard)/hooks/teams/useTeams";
+import { KeyResponse, Team } from "@/components/key_team_helpers/key_list";
+import { Organization } from "@/components/networking";
+import { CreateKeyPrefillData } from "@/components/organisms/create_key_button";
+import { fetchOrganizations } from "@/components/organizations";
+import UserDashboard from "@/components/user_dashboard";
+import { useAuth } from "@/contexts/AuthContext";
+import { useSearchParams } from "next/navigation";
+import { useEffect, useMemo, useState } from "react";
+
+export default function ApiKeysDashboard() {
+ const { userID, userRole, userEmail, accessToken, premiumUser, setUserRole, setUserEmail } = useAuth();
+ const searchParams = useSearchParams()!;
+
+ const [teams, setTeams] = useState<Team[] | null>(null);
+ const [keys, setKeys] = useState<KeyResponse[] | null>([]);
+ const [organizations, setOrganizations] = useState<Organization[]>([]);
+ const [createClicked, setCreateClicked] = useState<boolean>(false);
+
+ const autoOpenCreate = searchParams.get("create") === "true";
+ const prefillData: CreateKeyPrefillData | undefined = useMemo(() => {
+ if (!autoOpenCreate) return undefined;
+
+ const ownedBy = searchParams.get("owned_by");
+ const teamId = searchParams.get("team_id");
+ const keyAlias = searchParams.get("key_alias");
+ const modelsParam = searchParams.get("models");
+ const keyType = searchParams.get("key_type");
+
+ if (!ownedBy && !teamId && !keyAlias && !modelsParam && !keyType) {
+ return undefined;
+ }
+
+ const validOwnedByValues = ["you", "service_account", "another_user"];
+ const validatedOwnedBy =
+ ownedBy && validOwnedByValues.includes(ownedBy) ? (ownedBy as CreateKeyPrefillData["owned_by"]) : undefined;
+
+ const validKeyTypes = ["default", "llm_api", "management"];
+ const validatedKeyType =
+ keyType && validKeyTypes.includes(keyType) ? (keyType as CreateKeyPrefillData["key_type"]) : undefined;
+
+ const sanitizedKeyAlias = keyAlias ? keyAlias.trim().slice(0, 256) : undefined;
+
+ const sanitizedModels = modelsParam
+ ? modelsParam
+ .split(",")
+ .slice(0, 100)
+ .map((m) => m.trim().slice(0, 256))
+ .filter((m) => m.length > 0)
+ : undefined;
+
+ return {
+ owned_by: validatedOwnedBy,
+ team_id: teamId?.trim() || undefined,
+ key_alias: sanitizedKeyAlias,
+ models: sanitizedModels && sanitizedModels.length > 0 ? sanitizedModels : undefined,
+ key_type: validatedKeyType,
+ };
+ }, [searchParams, autoOpenCreate]);
+
+ const addKey = (data: KeyResponse) => {
+ setKeys((prevData) => (prevData ? [...prevData, data] : [data]));
+ setCreateClicked((prev) => !prev);
+ };
+
+ useEffect(() => {
+ if (accessToken && userID && userRole) {
+ v2TeamListCall(accessToken, 1, 100, {
+ userID: userRole !== "Admin" && userRole !== "Admin Viewer" ? userID : null,
+ })
+ .then((response) => setTeams(response.teams ?? []))
+ .catch(console.error);
+ }
+ if (accessToken) {
+ fetchOrganizations(accessToken, setOrganizations);
+ }
+ }, [accessToken, userID, userRole]);
+
+ return (
+ <UserDashboard
+ userID={userID}
+ userRole={userRole}
+ premiumUser={premiumUser}
+ teams={teams}
+ keys={keys}
+ setUserRole={setUserRole}
+ userEmail={userEmail}
+ setUserEmail={setUserEmail}
+ setTeams={setTeams}
+ setKeys={setKeys}
+ organizations={organizations}
+ addKey={addKey}
+ createClicked={createClicked}
+ autoOpenCreate={autoOpenCreate}
+ prefillData={prefillData}
+ />
+ );
+}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/api-keys/page.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-keys/page.tsx
new file mode 100644
index 00000000000..081ca87dc62
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-keys/page.tsx
@@ -0,0 +1,22 @@
+"use client";
+
+import ApiKeysDashboard from "@/app/(dashboard)/api-keys/ApiKeysDashboard";
+import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
+import LoadingScreen from "@/components/common_components/LoadingScreen";
+import { Suspense } from "react";
+
+function ApiKeysPageContent() {
+ const { isLoading, isAuthorized } = useAuthorized();
+ if (isLoading || !isAuthorized) {
+ return <LoadingScreen />;
+ }
+ return <ApiKeysDashboard />;
+}
+
+export default function ApiKeysPage() {
+ return (
+ <Suspense fallback={<LoadingScreen />}>
+ <ApiKeysPageContent />
+ </Suspense>
+ );
+}
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/page.tsx b/ui/litellm-dashboard/src/app/(dashboard)/page.tsx
index 8320f1d6a1b..c5d28fab8a0 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/page.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/page.tsx
@@ -1,10 +1,10 @@
"use client";
+import ApiKeysDashboard from "@/app/(dashboard)/api-keys/ApiKeysDashboard";
import { teamListCall as v2TeamListCall } from "@/app/(dashboard)/hooks/teams/useTeams";
import LoadingScreen from "@/components/common_components/LoadingScreen";
import { Team } from "@/components/key_team_helpers/key_list";
import { Organization, proxyBaseUrl } from "@/components/networking";
-import { CreateKeyPrefillData } from "@/components/organisms/create_key_button";
import { fetchOrganizations } from "@/components/organizations";
import UserDashboard from "@/components/user_dashboard";
import { useAuth } from "@/contexts/AuthContext";
@@ -17,7 +17,7 @@ import {
} from "@/utils/returnUrlUtils";
import { MIGRATED_PAGES, migratedHref } from "@/utils/migratedPages";
import { useRouter, useSearchParams } from "next/navigation";
-import { Suspense, useEffect, useMemo, useRef, useState } from "react";
+import { Suspense, useEffect, useRef, useState } from "react";
function CreateKeyPageContent() {
const { authLoading, token, userID, userRole, userEmail, accessToken, premiumUser, setUserRole, setUserEmail } =
@@ -33,57 +33,8 @@ function CreateKeyPageContent() {
const invitation_id = searchParams.get("invitation_id");
- // Parse URL query parameters for pre-filling the create key form
- // Includes validation to prevent injection and DoS attacks
- const autoOpenCreate = searchParams.get("create") === "true";
- const prefillData: CreateKeyPrefillData | undefined = useMemo(() => {
- if (!autoOpenCreate) return undefined;
-
- const ownedBy = searchParams.get("owned_by");
- const teamId = searchParams.get("team_id");
- const keyAlias = searchParams.get("key_alias");
- const modelsParam = searchParams.get("models");
- const keyType = searchParams.get("key_type");
-
- // Only return prefill data if at least one field is provided
- if (!ownedBy && !teamId && !keyAlias && !modelsParam && !keyType) {
- return undefined;
- }
-
- // Validate owned_by against allowed values
- const validOwnedByValues = ["you", "service_account", "another_user"];
- const validatedOwnedBy =
- ownedBy && validOwnedByValues.includes(ownedBy) ? (ownedBy as CreateKeyPrefillData["owned_by"]) : undefined;
-
- // Validate key_type against allowed values
- const validKeyTypes = ["default", "llm_api", "management"];
- const validatedKeyType =
- keyType && validKeyTypes.includes(keyType) ? (keyType as CreateKeyPrefillData["key_type"]) : undefined;
-
- // Sanitize key_alias (limit length, trim whitespace)
- const sanitizedKeyAlias = keyAlias
- ? keyAlias.trim().slice(0, 256) // Reasonable max length
- : undefined;
-
- // Sanitize models (limit array size and individual model name length)
- const sanitizedModels = modelsParam
- ? modelsParam
- .split(",")
- .slice(0, 100) // Limit number of models to prevent DoS
- .map((m) => m.trim().slice(0, 256)) // Limit individual model name length
- .filter((m) => m.length > 0) // Remove empty strings
- : undefined;
-
- return {
- owned_by: validatedOwnedBy,
- team_id: teamId?.trim() || undefined,
- key_alias: sanitizedKeyAlias,
- models: sanitizedModels && sanitizedModels.length > 0 ? sanitizedModels : undefined,
- key_type: validatedKeyType,
- };
- }, [searchParams, autoOpenCreate]);
-
- const page = searchParams.get("page") || "api-keys";
+ const explicitPage = searchParams.get("page");
+ const page = explicitPage || "api-keys";
// Track if we've already attempted a return URL redirect to prevent race conditions
const hasAttemptedReturnRedirectRef = useRef(false);
@@ -106,8 +57,10 @@ function CreateKeyPageContent() {
}
}, [redirectToLogin]);
- // Redirect legacy query-param pages to their new path-based routes
- const isLegacyRedirect = page in MIGRATED_PAGES;
+ // Redirect legacy query-param pages to their new path-based routes. Only when the page is
+ // explicitly requested via ?page=, so the bare landing renders inline and the post-login
+ // return-URL handling below stays intact.
+ const isLegacyRedirect = explicitPage !== null && explicitPage in MIGRATED_PAGES;
useEffect(() => {
if (!authLoading && isLegacyRedirect) {
router.replace(migratedHref(MIGRATED_PAGES[page]));
@@ -187,23 +140,7 @@ function CreateKeyPageContent() {
createClicked={createClicked}
/>
) : (
- <UserDashboard
- userID={userID}
- userRole={userRole}
- premiumUser={premiumUser}
- teams={teams}
- keys={keys}
- setUserRole={setUserRole}
- userEmail={userEmail}
- setUserEmail={setUserEmail}
- setTeams={setTeams}
- setKeys={setKeys}
- organizations={organizations}
- addKey={addKey}
- createClicked={createClicked}
- autoOpenCreate={autoOpenCreate}
- prefillData={prefillData}
- />
+ <ApiKeysDashboard />
)}
</>
);
diff --git a/ui/litellm-dashboard/src/utils/migratedPages.test.ts b/ui/litellm-dashboard/src/utils/migratedPages.test.ts
index a931a9a8b59..5812c1eec40 100644
--- a/ui/litellm-dashboard/src/utils/migratedPages.test.ts
+++ b/ui/litellm-dashboard/src/utils/migratedPages.test.ts
@@ -41,6 +41,14 @@ describe("migratedHref / legacyPageHref", () => {
expect(MIGRATED_PAGES["api-reference"]).toBe("api-reference");
});
+ it("maps the api-keys landing id to its route and builds its redirect href", async () => {
+ vi.doMock("@/components/networking", () => ({ serverRootPath: "/" }));
+ const { MIGRATED_PAGES, migratedHref } = await import("./migratedPages");
+
+ expect(MIGRATED_PAGES["api-keys"]).toBe("api-keys");
+ expect(migratedHref(MIGRATED_PAGES["api-keys"])).toBe("/ui/api-keys");
+ });
+
it("maps the llm-playground sidebar id to the playground route", async () => {
vi.doMock("@/components/networking", () => ({ serverRootPath: "/" }));
const { MIGRATED_PAGES } = await import("./migratedPages");
diff --git a/ui/litellm-dashboard/src/utils/migratedPages.ts b/ui/litellm-dashboard/src/utils/migratedPages.ts
index 3e1b4701589..a3eb4a958df 100644
--- a/ui/litellm-dashboard/src/utils/migratedPages.ts
+++ b/ui/litellm-dashboard/src/utils/migratedPages.ts
@@ -9,6 +9,7 @@ import { serverRootPath } from "@/components/networking";
* legacy `?page=` URL; remove it to roll back.
*/
export const MIGRATED_PAGES: Record<string, string> = {
+ "api-keys": "api-keys",
models: "models-and-endpoints",
api_ref: "api-reference",
// Legacy alias: older bookmarks used the hyphenated ?page=api-reference form.