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]

global feature flag state for app

Achintya Rajan715c4999a290
diff --git a/ui/litellm-dashboard/src/app/(console)/components/SidebarProvider.tsx b/ui/litellm-dashboard/src/app/(console)/components/SidebarProvider.tsx
new file mode 100644
index 00000000000..a5e150da86c
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(console)/components/SidebarProvider.tsx
@@ -0,0 +1,34 @@
+import Sidebar2 from "@/app/(console)/components/Sidebar2";
+import Sidebar from "@/components/leftnav";
+import React from "react";
+import useFeatureFlags from "@/hooks/useFeatureFlags";
+import useAuthorized from "@/app/(console)/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;
\ No newline at end of file
diff --git a/ui/litellm-dashboard/src/app/(console)/layout.tsx b/ui/litellm-dashboard/src/app/(console)/layout.tsx
index 6ad84208f56..595eeedc596 100644
--- a/ui/litellm-dashboard/src/app/(console)/layout.tsx
+++ b/ui/litellm-dashboard/src/app/(console)/layout.tsx
@@ -5,6 +5,7 @@ import Navbar from "@/components/navbar";
import { ThemeProvider } from "@/contexts/ThemeContext";
import Sidebar2 from "@/app/(console)/components/Sidebar2";
import useAuthorized from "@/app/(console)/hooks/useAuthorized";
+import useFeatureFlags, { FeatureFlagsProvider } from "@/hooks/useFeatureFlags";
export default function Layout({ children }: { children: React.ReactNode }) {
const { accessToken, userRole } = useAuthorized();
diff --git a/ui/litellm-dashboard/src/app/layout.tsx b/ui/litellm-dashboard/src/app/layout.tsx
index 95c485fe2f0..8a37d0fa1bf 100644
--- a/ui/litellm-dashboard/src/app/layout.tsx
+++ b/ui/litellm-dashboard/src/app/layout.tsx
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
+import { FeatureFlagsProvider } from "@/hooks/useFeatureFlags";
const inter = Inter({ subsets: ["latin"] });
@@ -17,7 +18,9 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
- <body className={inter.className}>{children}</body>
+ <FeatureFlagsProvider>
+ <body className={inter.className}>{children}</body>
+ </FeatureFlagsProvider>
</html>
);
}
diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx
index 2e49b422b49..eff997a3aaf 100644
--- a/ui/litellm-dashboard/src/app/page.tsx
+++ b/ui/litellm-dashboard/src/app/page.tsx
@@ -39,8 +39,9 @@ import VectorStoreManagement from "@/components/vector_store_management";
import UIThemeSettings from "@/components/ui_theme_settings";
import { UiLoadingSpinner } from "@/components/ui/ui-loading-spinner";
import { cx } from "@/lib/cva.config";
-import useFeatureFlags from "@/hooks/useFeatureFlags";
+import useFeatureFlags, { FeatureFlagsProvider } from "@/hooks/useFeatureFlags";
import Sidebar2 from "@/app/(console)/components/Sidebar2";
+import SidebarProvider from "@/app/(console)/components/SidebarProvider";
function getCookie(name: string) {
const cookieValue = document.cookie.split("; ").find((row) => row.startsWith(name + "="));
@@ -118,8 +119,6 @@ export default function CreateKeyPage() {
const [authLoading, setAuthLoading] = useState(true);
const [userID, setUserID] = useState<string | null>(null);
- const { refactoredUIFlag, setRefactoredUIFlag } = useFeatureFlags();
-
const invitation_id = searchParams.get("invitation_id");
// Get page from URL, default to 'api-keys' if not present
@@ -234,6 +233,7 @@ export default function CreateKeyPage() {
<UserDashboard
userID={userID}
userRole={userRole}
+ userEmail={userEmail}
premiumUser={premiumUser}
teams={teams}
keys={keys}
@@ -258,28 +258,17 @@ export default function CreateKeyPage() {
isPublicPage={false}
sidebarCollapsed={sidebarCollapsed}
onToggleSidebar={toggleSidebar}
- refactoredUIFlag={refactoredUIFlag}
- setRefactoredUIFlag={setRefactoredUIFlag}
/>
<div className="flex flex-1 overflow-auto">
<div className="mt-2">
- {refactoredUIFlag ? (
- <Sidebar2 accessToken={accessToken} userRole={userRole} />
- ) : (
- <Sidebar
- accessToken={accessToken}
- setPage={updatePage}
- userRole={userRole}
- defaultSelectedKey={page}
- collapsed={sidebarCollapsed}
- />
- )}
+ <SidebarProvider defaultSelectedKey={page} sidebarCollapsed={sidebarCollapsed} setPage={updatePage} />
</div>
{page == "api-keys" ? (
<UserDashboard
userID={userID}
userRole={userRole}
+ userEmail={userEmail}
premiumUser={premiumUser}
teams={teams}
keys={keys}
diff --git a/ui/litellm-dashboard/src/components/navbar.tsx b/ui/litellm-dashboard/src/components/navbar.tsx
index e4a9c21c443..37cb5a12284 100644
--- a/ui/litellm-dashboard/src/components/navbar.tsx
+++ b/ui/litellm-dashboard/src/components/navbar.tsx
@@ -32,8 +32,6 @@ interface NavbarProps {
isPublicPage: boolean;
sidebarCollapsed?: boolean;
onToggleSidebar?: () => void;
- refactoredUIFlag: boolean;
- setRefactoredUIFlag: React.Dispatch<React.SetStateAction<boolean>>;
}
const Navbar: React.FC<NavbarProps> = ({
@@ -46,13 +44,12 @@ const Navbar: React.FC<NavbarProps> = ({
accessToken,
isPublicPage = false,
sidebarCollapsed = false,
- onToggleSidebar,
- refactoredUIFlag,
- setRefactoredUIFlag,
+ onToggleSidebar
}) => {
const baseUrl = getProxyBaseUrl();
const [logoutUrl, setLogoutUrl] = useState("");
const { logoUrl } = useTheme();
+ const { refactoredUIFlag, setRefactoredUIFlag } = useFeatureFlags();
// Simple logo URL: use custom logo if available, otherwise default
const imageUrl = logoUrl || `${baseUrl}/get_image`;
diff --git a/ui/litellm-dashboard/src/hooks/useFeatureFlags.ts b/ui/litellm-dashboard/src/hooks/useFeatureFlags.ts
deleted file mode 100644
index b82f89e8749..00000000000
--- a/ui/litellm-dashboard/src/hooks/useFeatureFlags.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { useState } from "react";
-
-const useFeatureFlags = () => {
- const [refactoredUIFlag, setRefactoredUIFlag] = useState<boolean>(false);
-
- return { refactoredUIFlag, setRefactoredUIFlag };
-};
-
-export default useFeatureFlags;
diff --git a/ui/litellm-dashboard/src/hooks/useFeatureFlags.tsx b/ui/litellm-dashboard/src/hooks/useFeatureFlags.tsx
new file mode 100644
index 00000000000..d50fdf46a6e
--- /dev/null
+++ b/ui/litellm-dashboard/src/hooks/useFeatureFlags.tsx
@@ -0,0 +1,26 @@
+'use client';
+import React, {createContext, useContext, useState} from 'react';
+
+type Flags = {
+ refactoredUIFlag: boolean;
+ setRefactoredUIFlag: (v: boolean) => void;
+};
+
+const FeatureFlagsCtx = createContext<Flags | null>(null);
+
+export const FeatureFlagsProvider = ({ children }: { children: React.ReactNode }) => {
+ const [refactoredUIFlag, setRefactoredUIFlag] = useState(false);
+ return (
+ <FeatureFlagsCtx.Provider value={{ refactoredUIFlag, setRefactoredUIFlag }}>
+ {children}
+ </FeatureFlagsCtx.Provider>
+);
+}
+
+const useFeatureFlags = () => {
+ const ctx = useContext(FeatureFlagsCtx);
+ if (!ctx) throw new Error('useFeatureFlags must be used within FeatureFlagsProvider');
+ return ctx;
+}
+
+export default useFeatureFlags;