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]

Sidebar2 uses FF now

Achintya Rajan051c9a7c6192
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/components/Sidebar2.tsx b/ui/litellm-dashboard/src/app/(dashboard)/components/Sidebar2.tsx
index 37901b5e639..843a176f6e1 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/components/Sidebar2.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/components/Sidebar2.tsx
@@ -1,8 +1,5 @@
-"use client";
-
-import React from "react";
-import { usePathname, useSearchParams, useRouter } from "next/navigation";
-import { Layout, Menu, ConfigProvider } from "antd";
+import { Layout, Menu } from "antd";
+import { useRouter, usePathname } from "next/navigation"; // UPDATED: also usePathname to detect current route
import {
KeyOutlined,
PlayCircleOutlined,
@@ -23,16 +20,18 @@ import {
TagsOutlined,
BgColorsOutlined,
} from "@ant-design/icons";
+import { ConfigProvider } from "antd";
+import useFeatureFlags from "@/hooks/useFeatureFlags";
import { all_admin_roles, internalUserRoles, isAdminRole, rolesWithWriteAccess } from "@/utils/roles";
import UsageIndicator from "@/components/usage_indicator";
-
+import React from "react";
const { Sider } = Layout;
interface SidebarProps {
accessToken: string | null;
+ setPage: (page: string) => void;
userRole: string;
- /** Used to highlight a menu item when pathname doesn't match (e.g., on non-routed pages) */
- defaultSelectedKey?: string;
+ defaultSelectedKey: string;
collapsed?: boolean;
}
@@ -45,87 +44,77 @@ interface MenuItem {
icon?: React.ReactNode;
}
-/** ---------- Base URL helpers ---------- */
-/** Normalizes NEXT_PUBLIC_BASE_URL into either "" or "/something" (no trailing slash). */
-const getBasePath = () => {
- const raw = process.env.NEXT_PUBLIC_BASE_URL ?? "";
- const trimmed = raw.replace(/^\/+|\/+$/g, ""); // strip leading/trailing slashes
- return trimmed ? `/${trimmed}` : "";
-};
-
-/** Joins base path with a relative path like "virtual-keys" or "/virtual-keys" -> "/base/virtual-keys" */
-const withBase = (relativePath: string) => {
- const base = getBasePath(); // "" or "/ui" (no trailing slash)
- const rel = relativePath.replace(/^\/+/, ""); // drop any leading slash
- return `${base}/${rel}`.replace(/\/{2,}/g, "/"); // collapse accidental doubles
-};
-
-const Sidebar2: React.FC<SidebarProps> = ({ accessToken, userRole, defaultSelectedKey, collapsed = false }) => {
+const Sidebar2: React.FC<SidebarProps> = ({
+ accessToken,
+ setPage,
+ userRole,
+ defaultSelectedKey,
+ collapsed = false,
+}) => {
const router = useRouter();
const pathname = usePathname();
- const searchParams = useSearchParams();
+ const { refactoredUIFlag } = useFeatureFlags();
- /** ---------- Menu model ---------- */
const menuItems: MenuItem[] = [
- { key: "1", page: "api-keys", label: "Virtual Keys", icon: <KeyOutlined style={{ fontSize: 18 }} /> },
+ { key: "1", page: "api-keys", label: "Virtual Keys", icon: <KeyOutlined style={{ fontSize: "18px" }} /> },
{
key: "3",
page: "llm-playground",
label: "Test Key",
- icon: <PlayCircleOutlined style={{ fontSize: 18 }} />,
+ icon: <PlayCircleOutlined style={{ fontSize: "18px" }} />,
roles: rolesWithWriteAccess,
},
{
key: "2",
page: "models",
label: "Models + Endpoints",
- icon: <BlockOutlined style={{ fontSize: 18 }} />,
+ icon: <BlockOutlined style={{ fontSize: "18px" }} />,
roles: rolesWithWriteAccess,
},
{
key: "12",
page: "new_usage",
label: "Usage",
- icon: <BarChartOutlined style={{ fontSize: 18 }} />,
+ icon: <BarChartOutlined style={{ fontSize: "18px" }} />,
roles: [...all_admin_roles, ...internalUserRoles],
},
- { key: "6", page: "teams", label: "Teams", icon: <TeamOutlined style={{ fontSize: 18 }} /> },
+ { key: "6", page: "teams", label: "Teams", icon: <TeamOutlined style={{ fontSize: "18px" }} /> },
{
key: "17",
page: "organizations",
label: "Organizations",
- icon: <BankOutlined style={{ fontSize: 18 }} />,
+ icon: <BankOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "5",
page: "users",
label: "Internal Users",
- icon: <UserOutlined style={{ fontSize: 18 }} />,
+ icon: <UserOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
- { key: "14", page: "api_ref", label: "API Reference", icon: <ApiOutlined style={{ fontSize: 18 }} /> },
- { key: "16", page: "model-hub-table", label: "Model Hub", icon: <AppstoreOutlined style={{ fontSize: 18 }} /> },
- { key: "15", page: "logs", label: "Logs", icon: <LineChartOutlined style={{ fontSize: 18 }} /> },
+ { key: "14", page: "api_ref", label: "API Reference", icon: <ApiOutlined style={{ fontSize: "18px" }} /> },
+ { key: "16", page: "model-hub-table", label: "Model Hub", icon: <AppstoreOutlined style={{ fontSize: "18px" }} /> },
+ { key: "15", page: "logs", label: "Logs", icon: <LineChartOutlined style={{ fontSize: "18px" }} /> },
{
key: "11",
page: "guardrails",
label: "Guardrails",
- icon: <SafetyOutlined style={{ fontSize: 18 }} />,
+ icon: <SafetyOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "26",
page: "tools",
label: "Tools",
- icon: <ToolOutlined style={{ fontSize: 18 }} />,
+ icon: <ToolOutlined style={{ fontSize: "18px" }} />,
children: [
- { key: "18", page: "mcp-servers", label: "MCP Servers", icon: <ToolOutlined style={{ fontSize: 18 }} /> },
+ { key: "18", page: "mcp-servers", label: "MCP Servers", icon: <ToolOutlined style={{ fontSize: "18px" }} /> },
{
key: "21",
page: "vector-stores",
label: "Vector Stores",
- icon: <DatabaseOutlined style={{ fontSize: 18 }} />,
+ icon: <DatabaseOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
],
@@ -134,163 +123,146 @@ const Sidebar2: React.FC<SidebarProps> = ({ accessToken, userRole, defaultSelect
key: "experimental",
page: "experimental",
label: "Experimental",
- icon: <ExperimentOutlined style={{ fontSize: 18 }} />,
+ icon: <ExperimentOutlined style={{ fontSize: "18px" }} />,
children: [
{
key: "9",
page: "caching",
label: "Caching",
- icon: <DatabaseOutlined style={{ fontSize: 18 }} />,
+ icon: <DatabaseOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "25",
page: "prompts",
label: "Prompts",
- icon: <FileTextOutlined style={{ fontSize: 18 }} />,
+ icon: <FileTextOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "10",
page: "budgets",
label: "Budgets",
- icon: <BankOutlined style={{ fontSize: 18 }} />,
+ icon: <BankOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "20",
page: "transform-request",
label: "API Playground",
- icon: <ApiOutlined style={{ fontSize: 18 }} />,
+ icon: <ApiOutlined style={{ fontSize: "18px" }} />,
roles: [...all_admin_roles, ...internalUserRoles],
},
{
key: "19",
page: "tag-management",
label: "Tag Management",
- icon: <TagsOutlined style={{ fontSize: 18 }} />,
+ icon: <TagsOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
- { key: "4", page: "usage", label: "Old Usage", icon: <BarChartOutlined style={{ fontSize: 18 }} /> },
+ { key: "4", page: "usage", label: "Old Usage", icon: <BarChartOutlined style={{ fontSize: "18px" }} /> },
],
},
{
key: "settings",
page: "settings",
label: "Settings",
- icon: <SettingOutlined style={{ fontSize: 18 }} />,
+ icon: <SettingOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
children: [
{
key: "11",
page: "general-settings",
label: "Router Settings",
- icon: <SettingOutlined style={{ fontSize: 18 }} />,
+ icon: <SettingOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "8",
page: "settings",
label: "Logging & Alerts",
- icon: <SettingOutlined style={{ fontSize: 18 }} />,
+ icon: <SettingOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "13",
page: "admin-panel",
label: "Admin Settings",
- icon: <SettingOutlined style={{ fontSize: 18 }} />,
+ icon: <SettingOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
{
key: "14",
page: "ui-theme",
label: "UI Theme",
- icon: <BgColorsOutlined style={{ fontSize: 18 }} />,
+ icon: <BgColorsOutlined style={{ fontSize: "18px" }} />,
roles: all_admin_roles,
},
],
},
];
- // Role filtering (preserves original visibility behavior)
- const filteredMenuItems: MenuItem[] = menuItems
- .filter((item) => !item.roles || item.roles.includes(userRole))
- .map((item) => ({
- ...item,
- children: item.children?.filter((child) => !child.roles || child.roles.includes(userRole)),
- }));
-
- /** ---------- Selection state ---------- */
- const pageParam = searchParams.get("page") || undefined;
-
const findMenuItemKey = (page: string): string => {
- const top = filteredMenuItems.find((i) => i.page === page);
- if (top) return top.key;
- for (const i of filteredMenuItems) {
- const child = i.children?.find((c) => c.page === page);
- if (child) return child.key;
+ const topLevelItem = menuItems.find((item) => item.page === page);
+ if (topLevelItem) return topLevelItem.key;
+ for (const item of menuItems) {
+ if (item.children) {
+ const childItem = item.children.find((child) => child.page === page);
+ if (childItem) return childItem.key;
+ }
}
return "1";
};
- // Match Virtual Keys path with base prefix (e.g., "/virtual-keys" or "/ui/virtual-keys")
- const virtualKeysPath = withBase("virtual-keys");
+ const selectedMenuKey = findMenuItemKey(defaultSelectedKey);
- const selectedMenuKey =
- pathname === virtualKeysPath
- ? "1"
- : pageParam
- ? findMenuItemKey(pageParam)
- : defaultSelectedKey
- ? findMenuItemKey(defaultSelectedKey)
- : "1";
+ const filteredMenuItems = menuItems.filter((item) => {
+ const hasParentAccess = !item.roles || item.roles.includes(userRole);
+ if (!hasParentAccess) return false;
+ if (item.children) {
+ item.children = item.children.filter((child) => !child.roles || child.roles.includes(userRole));
+ }
+ return true;
+ });
- /** ---------- Navigation helpers (SPA only) ---------- */
- // Build a root URL ("/" or "/base/") with an updated ?page=...
- const goTo = (p: string) => {
- const base = getBasePath() || "/";
- const root = base.endsWith("/") ? base : `${base}/`;
- const sp = new URLSearchParams(typeof window !== "undefined" ? window.location.search : "");
- sp.set("page", p);
- // Use Next router for client navigation on the SAME route (no hard fetch)
- router.replace(`${root}?${sp.toString()}`, { scroll: false });
+ // Helper: go to /?page=...; when on /virtual-keys with refactored UI, replace instead of appending
+ const pushToRootWithPage = (page: string, useReplace = false) => {
+ const params = new URLSearchParams();
+ params.set("page", page);
+ const url = `/?${params.toString()}`;
+ if (useReplace) {
+ router.replace(url);
+ } else {
+ router.push(url);
+ }
};
- // Keep the /virtual-keys path the same, but avoid route fetches/hard reloads.
- const goToVirtualKeys = () => {
- const base = getBasePath() || "/";
- const root = base.endsWith("/") ? base : `${base}/`;
- const sp = new URLSearchParams(typeof window !== "undefined" ? window.location.search : "");
- sp.set("page", "api-keys");
-
- // 1) Client transition to the root with ?page=api-keys so the view updates.
- router.replace(`${root}?${sp.toString()}`, { scroll: false });
+ // Centralized navigation that satisfies the requirement
+ const navigateToPage = (page: string) => {
+ // Special-case: Virtual Keys target
+ if (page === "api-keys") {
+ if (refactoredUIFlag) {
+ // Go to the dedicated /virtual-keys page
+ router.push("/virtual-keys");
+ return; // do not call setPage here (parity with previous behavior)
+ }
+ // Legacy behavior
+ pushToRootWithPage(page);
+ setPage(page);
+ return;
+ }
- // 2) Cosmetic URL swap to ".../virtual-keys" without navigation (keeps path the same).
- const vk = withBase("virtual-keys");
- if (typeof window !== "undefined") {
- window.history.replaceState(null, "", vk);
+ // All other pages
+ if (refactoredUIFlag) {
+ // If currently on /virtual-keys, REPLACE it with /?page=...
+ const onVirtualKeys = pathname?.startsWith("/virtual-keys");
+ pushToRootWithPage(page, onVirtualKeys);
+ } else {
+ pushToRootWithPage(page);
}
+ setPage(page);
};
- /** ---------- AntD items with onClick handlers ---------- */
- const antdItems = filteredMenuItems.map((item) => {
- const isVirtualKeys = item.key === "1";
- return {
- key: item.key,
- icon: item.icon,
- label: item.label, // plain text; click handled via onClick
- onClick: !item.children ? (isVirtualKeys ? goToVirtualKeys : () => goTo(item.page)) : undefined,
- children: item.children?.map((child) => ({
- key: child.key,
- icon: child.icon,
- label: child.label,
- onClick: () => goTo(child.page),
- })),
- };
- });
-
return (
<Layout style={{ minHeight: "100vh" }}>
<Sider
@@ -300,29 +272,36 @@ const Sidebar2: React.FC<SidebarProps> = ({ accessToken, userRole, defaultSelect
collapsedWidth={80}
collapsible
trigger={null}
- style={{
- transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
- position: "relative",
- }}
+ style={{ transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)", position: "relative" }}
>
- <ConfigProvider
- theme={{
- components: {
- Menu: { iconSize: 18, fontSize: 14 },
- },
- }}
- >
+ <ConfigProvider theme={{ components: { Menu: { iconSize: 18, fontSize: 14 } } }}>
<Menu
mode="inline"
selectedKeys={[selectedMenuKey]}
- defaultOpenKeys={collapsed ? [] : ["llm-tools"]} /* kept to match original look */
+ defaultOpenKeys={collapsed ? [] : ["llm-tools"]}
inlineCollapsed={collapsed}
className="custom-sidebar-menu"
- style={{ borderRight: 0, backgroundColor: "transparent", fontSize: 14 }}
- items={antdItems as any}
+ style={{ borderRight: 0, backgroundColor: "transparent", fontSize: "14px" }}
+ items={filteredMenuItems.map((item) => ({
+ key: item.key,
+ icon: item.icon,
+ label: item.label,
+ children: item.children?.map((child) => ({
+ key: child.key,
+ icon: child.icon,
+ label: child.label,
+ onClick: () => {
+ navigateToPage(child.page);
+ },
+ })),
+ onClick: !item.children
+ ? () => {
+ navigateToPage(item.page);
+ }
+ : undefined,
+ }))}
/>
</ConfigProvider>
-
{isAdminRole(userRole) && !collapsed && <UsageIndicator accessToken={accessToken} width={220} />}
</Sider>
</Layout>
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/components/SidebarProvider.tsx b/ui/litellm-dashboard/src/app/(dashboard)/components/SidebarProvider.tsx
deleted file mode 100644
index 822a30e6403..00000000000
--- a/ui/litellm-dashboard/src/app/(dashboard)/components/SidebarProvider.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-"use client";
-
-import Sidebar2 from "@/app/(dashboard)/components/Sidebar2";
-import Sidebar from "@/components/leftnav";
-import React from "react";
-import useFeatureFlags from "@/hooks/useFeatureFlags";
-import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
-
-interface SidebarProviderProps {
- defaultSelectedKey: string;
- sidebarCollapsed: boolean;
- setPage: (page: string) => void;
-}
-
-const SidebarProvider = ({ defaultSelectedKey, sidebarCollapsed, setPage }: SidebarProviderProps) => {
- const { accessToken, userRole } = useAuthorized();
- const { refactoredUIFlag, setRefactoredUIFlag } = useFeatureFlags();
-
- return refactoredUIFlag ? (
- <Sidebar2 accessToken={accessToken} userRole={userRole} />
- ) : (
- <Sidebar
- accessToken={accessToken}
- setPage={setPage}
- userRole={userRole}
- defaultSelectedKey={defaultSelectedKey}
- collapsed={sidebarCollapsed}
- />
- );
-};
-
-export default SidebarProvider;
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/layout.tsx b/ui/litellm-dashboard/src/app/(dashboard)/layout.tsx
index ad8a82703f7..7e60443d24f 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/layout.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/layout.tsx
@@ -1,14 +1,31 @@
"use client";
-import React from "react";
+import React, { useEffect, useState } from "react";
import Navbar from "@/components/navbar";
import { ThemeProvider } from "@/contexts/ThemeContext";
import Sidebar2 from "@/app/(dashboard)/components/Sidebar2";
import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
+import { useRouter, useSearchParams } from "next/navigation";
export default function Layout({ children }: { children: React.ReactNode }) {
+ const router = useRouter();
+ const searchParams = useSearchParams();
const { accessToken, userRole } = useAuthorized();
const [sidebarCollapsed, setSidebarCollapsed] = React.useState(false);
+ const [page, setPage] = useState(() => {
+ return searchParams.get("page") || "api-keys";
+ });
+
+ const updatePage = (newPage: string) => {
+ const newSearchParams = new URLSearchParams(searchParams);
+ newSearchParams.set("page", newPage);
+ router.push(`/?${newSearchParams.toString()}`); // absolute, not relative
+ setPage(newPage);
+ };
+
+ useEffect(() => {
+ setPage(searchParams.get("page") || "api-keys");
+ }, [searchParams]);
const toggleSidebar = () => setSidebarCollapsed((v) => !v);
@@ -31,12 +48,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
/>
<div className="flex flex-1 overflow-auto">
<div className="mt-2">
- <Sidebar2
- collapsed={sidebarCollapsed}
- accessToken={accessToken}
- userRole={userRole}
- defaultSelectedKey={""}
- />
+ <Sidebar2 defaultSelectedKey={page} setPage={updatePage} accessToken={accessToken} userRole={userRole} />
</div>
<main className="flex-1">{children}</main>
</div>
diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx
index 104ef41810a..d386df4b77e 100644
--- a/ui/litellm-dashboard/src/app/page.tsx
+++ b/ui/litellm-dashboard/src/app/page.tsx
@@ -1,7 +1,7 @@
"use client";
import React, { Suspense, useEffect, useState } from "react";
-import { useSearchParams } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
import { jwtDecode } from "jwt-decode";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Team } from "@/components/key_team_helpers/key_list";
@@ -23,7 +23,6 @@ import ModelHubTable from "@/components/model_hub_table";
import NewUsagePage from "@/components/new_usage";
import APIRef from "@/components/api_ref";
import ChatUI from "@/components/chat_ui/ChatUI";
-import Sidebar from "@/components/leftnav";
import Usage from "@/components/usage";
import CacheDashboard from "@/components/cache_dashboard";
import { getUiConfig, proxyBaseUrl, setGlobalLitellmHeaderName } from "@/components/networking";
@@ -40,7 +39,6 @@ import UIThemeSettings from "@/components/ui_theme_settings";
import { UiLoadingSpinner } from "@/components/ui/ui-loading-spinner";
import { cx } from "@/lib/cva.config";
import Sidebar2 from "@/app/(dashboard)/components/Sidebar2";
-import SidebarProvider from "@/app/(dashboard)/components/SidebarProvider";
function getCookie(name: string) {
const cookieValue = document.cookie.split("; ").find((row) => row.startsWith(name + "="));
@@ -97,6 +95,7 @@ function LoadingScreen() {
}
export default function CreateKeyPage() {
+ const router = useRouter();
const [userRole, setUserRole] = useState("");
const [premiumUser, setPremiumUser] = useState(false);
const [disabledPersonalKeyCreation, setDisabledPersonalKeyCreation] = useState(false);
@@ -131,13 +130,9 @@ export default function CreateKeyPage() {
// Custom setPage function that updates URL
const updatePage = (newPage: string) => {
- // Update URL without full page reload
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set("page", newPage);
-
- // Use Next.js router to update URL
- window.history.pushState(null, "", `?${newSearchParams.toString()}`);
-
+ router.push(`/?${newSearchParams.toString()}`); // absolute, not relative
setPage(newPage);
};
@@ -264,7 +259,12 @@ export default function CreateKeyPage() {
/>
<div className="flex flex-1 overflow-auto">
<div className="mt-2">
- <SidebarProvider defaultSelectedKey={page} sidebarCollapsed={sidebarCollapsed} setPage={updatePage} />
+ <Sidebar2
+ defaultSelectedKey={page}
+ setPage={updatePage}
+ accessToken={accessToken}
+ userRole={userRole}
+ />
</div>
{page == "api-keys" ? (