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]

Add auto redirect to SSO to new login page

yuneng-jiangd215576477d6
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index 4d971e8ce42..40436e1716b 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -555,10 +555,11 @@ else:
global_max_parallel_request_retry_timeout_env
)
-ui_link = f"{server_root_path}/ui/"
+ui_link = f"{server_root_path}/ui/login"
+fallback_login_link = f"{server_root_path}/fallback/login"
model_hub_link = f"{server_root_path}/ui/model_hub_table"
ui_message = (
- f"👉 [```LiteLLM Admin Panel on /ui```]({ui_link}). Create, Edit Keys with SSO"
+ f"👉 [```LiteLLM Admin Panel on /ui```]({ui_link}). Create, Edit Keys with SSO. Having issues? Try [```Fallback Login```]({fallback_login_link})"
)
ui_message += "\n\n💸 [```LiteLLM Model Cost Map```](https://models.litellm.ai/)."
diff --git a/tests/proxy_admin_ui_tests/e2e_ui_tests/login_to_ui.spec.ts b/tests/proxy_admin_ui_tests/e2e_ui_tests/login_to_ui.spec.ts
index f691389de53..fc4d4653246 100644
--- a/tests/proxy_admin_ui_tests/e2e_ui_tests/login_to_ui.spec.ts
+++ b/tests/proxy_admin_ui_tests/e2e_ui_tests/login_to_ui.spec.ts
@@ -10,7 +10,7 @@ import { test, expect } from "@playwright/test";
test("admin login test", async ({ page }) => {
// Go to the specified URL
- await page.goto("http://localhost:4000/ui");
+ await page.goto("http://localhost:4000/ui/login");
// Enter "admin" in the username input field
await page.fill('input[name="username"]', "admin");
@@ -19,7 +19,7 @@ test("admin login test", async ({ page }) => {
await page.fill('input[name="password"]', "gm");
// Optionally, you can add an assertion to verify the login button is enabled
- const loginButton = page.locator('input[type="submit"]');
+ const loginButton = page.locator('button[type="submit"]');
await expect(loginButton).toBeEnabled();
// Optionally, you can click the login button to submit the form
diff --git a/ui/litellm-dashboard/src/app/login/LoginPage.test.tsx b/ui/litellm-dashboard/src/app/login/LoginPage.test.tsx
new file mode 100644
index 00000000000..cce063eceb7
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/login/LoginPage.test.tsx
@@ -0,0 +1,172 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import { render, screen, waitFor } from "@testing-library/react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import LoginPage from "./LoginPage";
+
+const mockPush = vi.fn();
+const mockReplace = vi.fn();
+
+vi.mock("next/navigation", () => ({
+ useRouter: vi.fn(() => ({
+ push: mockPush,
+ replace: mockReplace,
+ })),
+}));
+
+vi.mock("@/app/(dashboard)/hooks/uiConfig/useUIConfig", () => ({
+ useUIConfig: vi.fn(),
+}));
+
+vi.mock("@/utils/cookieUtils", () => ({
+ getCookie: vi.fn(),
+}));
+
+vi.mock("@/utils/jwtUtils", () => ({
+ isJwtExpired: vi.fn(),
+}));
+
+vi.mock("@/components/networking", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("@/components/networking")>();
+ return {
+ ...actual,
+ getProxyBaseUrl: vi.fn().mockReturnValue("http://localhost:4000"),
+ };
+});
+
+vi.mock("@/app/(dashboard)/hooks/login/useLogin", () => ({
+ useLogin: vi.fn(() => ({
+ mutate: vi.fn(),
+ isPending: false,
+ error: null,
+ })),
+}));
+
+import { useUIConfig } from "@/app/(dashboard)/hooks/uiConfig/useUIConfig";
+import { getCookie } from "@/utils/cookieUtils";
+import { isJwtExpired } from "@/utils/jwtUtils";
+
+const createQueryClient = () =>
+ new QueryClient({
+ defaultOptions: {
+ queries: {
+ retry: false,
+ gcTime: 0,
+ },
+ },
+ });
+
+describe("LoginPage", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mockPush.mockClear();
+ mockReplace.mockClear();
+ });
+
+ it("should render", async () => {
+ (useUIConfig as ReturnType<typeof vi.fn>).mockReturnValue({
+ data: { auto_redirect_to_sso: false, server_root_path: "/", proxy_base_url: null },
+ isLoading: false,
+ });
+ (getCookie as ReturnType<typeof vi.fn>).mockReturnValue(null);
+
+ const queryClient = createQueryClient();
+ render(
+ <QueryClientProvider client={queryClient}>
+ <LoginPage />
+ </QueryClientProvider>,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByRole("heading", { name: "Login" })).toBeInTheDocument();
+ });
+ });
+
+ it("should call router.replace to dashboard when jwt is valid", async () => {
+ const validToken = "valid-token";
+ (useUIConfig as ReturnType<typeof vi.fn>).mockReturnValue({
+ data: { auto_redirect_to_sso: false, server_root_path: "/", proxy_base_url: null },
+ isLoading: false,
+ });
+ (getCookie as ReturnType<typeof vi.fn>).mockReturnValue(validToken);
+ (isJwtExpired as ReturnType<typeof vi.fn>).mockReturnValue(false);
+
+ const queryClient = createQueryClient();
+ render(
+ <QueryClientProvider client={queryClient}>
+ <LoginPage />
+ </QueryClientProvider>,
+ );
+
+ await waitFor(() => {
+ expect(mockReplace).toHaveBeenCalledWith("http://localhost:4000/ui");
+ });
+ });
+
+ it("should call router.push to SSO when jwt is invalid and auto_redirect_to_sso is true", async () => {
+ const invalidToken = "invalid-token";
+ (useUIConfig as ReturnType<typeof vi.fn>).mockReturnValue({
+ data: { auto_redirect_to_sso: true, server_root_path: "/", proxy_base_url: null },
+ isLoading: false,
+ });
+ (getCookie as ReturnType<typeof vi.fn>).mockReturnValue(invalidToken);
+ (isJwtExpired as ReturnType<typeof vi.fn>).mockReturnValue(true);
+
+ const queryClient = createQueryClient();
+ render(
+ <QueryClientProvider client={queryClient}>
+ <LoginPage />
+ </QueryClientProvider>,
+ );
+
+ await waitFor(() => {
+ expect(mockPush).toHaveBeenCalledWith("http://localhost:4000/sso/key/generate");
+ });
+ });
+
+ it("should not call router when jwt is invalid and auto_redirect_to_sso is false", async () => {
+ const invalidToken = "invalid-token";
+ (useUIConfig as ReturnType<typeof vi.fn>).mockReturnValue({
+ data: { auto_redirect_to_sso: false, server_root_path: "/", proxy_base_url: null },
+ isLoading: false,
+ });
+ (getCookie as ReturnType<typeof vi.fn>).mockReturnValue(invalidToken);
+ (isJwtExpired as ReturnType<typeof vi.fn>).mockReturnValue(true);
+
+ const queryClient = createQueryClient();
+ render(
+ <QueryClientProvider client={queryClient}>
+ <LoginPage />
+ </QueryClientProvider>,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByRole("heading", { name: "Login" })).toBeInTheDocument();
+ });
+
+ expect(mockPush).not.toHaveBeenCalled();
+ expect(mockReplace).not.toHaveBeenCalled();
+ });
+
+ it("should send user to dashboard when jwt is valid even if auto_redirect_to_sso is true", async () => {
+ const validToken = "valid-token";
+ (useUIConfig as ReturnType<typeof vi.fn>).mockReturnValue({
+ data: { auto_redirect_to_sso: true, server_root_path: "/", proxy_base_url: null },
+ isLoading: false,
+ });
+ (getCookie as ReturnType<typeof vi.fn>).mockReturnValue(validToken);
+ (isJwtExpired as ReturnType<typeof vi.fn>).mockReturnValue(false);
+
+ const queryClient = createQueryClient();
+ render(
+ <QueryClientProvider client={queryClient}>
+ <LoginPage />
+ </QueryClientProvider>,
+ );
+
+ await waitFor(() => {
+ expect(mockReplace).toHaveBeenCalledWith("http://localhost:4000/ui");
+ });
+
+ expect(mockPush).not.toHaveBeenCalled();
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/login/LoginPage.tsx b/ui/litellm-dashboard/src/app/login/LoginPage.tsx
new file mode 100644
index 00000000000..85f2c6dd870
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/login/LoginPage.tsx
@@ -0,0 +1,159 @@
+"use client";
+
+import { useLogin } from "@/app/(dashboard)/hooks/login/useLogin";
+import { useUIConfig } from "@/app/(dashboard)/hooks/uiConfig/useUIConfig";
+import LoadingScreen from "@/components/common_components/LoadingScreen";
+import { getProxyBaseUrl } from "@/components/networking";
+import { getCookie } from "@/utils/cookieUtils";
+import { isJwtExpired } from "@/utils/jwtUtils";
+import { InfoCircleOutlined } from "@ant-design/icons";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { Alert, Button, Card, Form, Input, Space, Typography } from "antd";
+import { useRouter } from "next/navigation";
+import { useEffect, useState } from "react";
+
+function LoginPageContent() {
+ const [username, setUsername] = useState("");
+ const [password, setPassword] = useState("");
+ const [isLoading, setIsLoading] = useState(true);
+ const { data: uiConfig, isLoading: isConfigLoading } = useUIConfig();
+ const loginMutation = useLogin();
+ const router = useRouter();
+
+ useEffect(() => {
+ if (isConfigLoading) {
+ return;
+ }
+
+ const rawToken = getCookie("token");
+ if (rawToken && !isJwtExpired(rawToken)) {
+ router.replace(`${getProxyBaseUrl()}/ui`);
+ return;
+ }
+
+ if (uiConfig && uiConfig.auto_redirect_to_sso) {
+ router.push(`${getProxyBaseUrl()}/sso/key/generate`);
+ return;
+ }
+
+ setIsLoading(false);
+ }, [isConfigLoading, router, uiConfig]);
+
+ const handleSubmit = () => {
+ loginMutation.mutate(
+ { username, password },
+ {
+ onSuccess: (data) => {
+ router.push(data.redirect_url);
+ },
+ },
+ );
+ };
+
+ const error = loginMutation.error instanceof Error ? loginMutation.error.message : null;
+ const isLoginLoading = loginMutation.isPending;
+
+ const { Title, Text, Paragraph } = Typography;
+
+ if (isConfigLoading || isLoading) {
+ return <LoadingScreen />;
+ }
+
+ return (
+ <div className="min-h-screen flex items-center justify-center bg-gray-50">
+ <Card className="w-full max-w-lg shadow-md">
+ <Space direction="vertical" size="middle" className="w-full">
+ <div className="text-center">
+ <Title level={2}>🚅 LiteLLM</Title>
+ </div>
+
+ <div className="text-center">
+ <Title level={3}>Login</Title>
+ <Text type="secondary">Access your LiteLLM Admin UI.</Text>
+ </div>
+
+ <Alert
+ message="Default Credentials"
+ description={
+ <>
+ <Paragraph className="text-sm">
+ By default, Username is <code className="bg-gray-100 px-1 py-0.5 rounded text-xs">admin</code> and
+ Password is your set LiteLLM Proxy
+ <code className="bg-gray-100 px-1 py-0.5 rounded text-xs">MASTER_KEY</code>.
+ </Paragraph>
+ <Paragraph className="text-sm">
+ Need to set UI credentials or SSO?{" "}
+ <a href="https://docs.litellm.ai/docs/proxy/ui" target="_blank" rel="noopener noreferrer">
+ Check the documentation
+ </a>
+ .
+ </Paragraph>
+ </>
+ }
+ type="info"
+ icon={<InfoCircleOutlined />}
+ showIcon
+ />
+
+ {error && <Alert message={error} type="error" showIcon />}
+
+ <Form onFinish={handleSubmit} layout="vertical" requiredMark={true}>
+ <Form.Item
+ label="Username"
+ name="username"
+ rules={[{ required: true, message: "Please enter your username" }]}
+ >
+ <Input
+ placeholder="Enter your username"
+ autoComplete="username"
+ value={username}
+ onChange={(e) => setUsername(e.target.value)}
+ disabled={isLoginLoading}
+ size="large"
+ className="rounded-md border-gray-300"
+ />
+ </Form.Item>
+
+ <Form.Item
+ label="Password"
+ name="password"
+ rules={[{ required: true, message: "Please enter your password" }]}
+ >
+ <Input.Password
+ placeholder="Enter your password"
+ autoComplete="current-password"
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ disabled={isLoginLoading}
+ size="large"
+ />
+ </Form.Item>
+
+ <Form.Item>
+ <Button
+ type="primary"
+ htmlType="submit"
+ loading={isLoginLoading}
+ disabled={isLoginLoading}
+ block
+ size="large"
+ >
+ {isLoginLoading ? "Logging in..." : "Login"}
+ </Button>
+ </Form.Item>
+ </Form>
+ </Space>
+ </Card>
+ </div>
+ );
+}
+
+export default function LoginPage() {
+ const queryClient = new QueryClient();
+
+ return (
+ <QueryClientProvider client={queryClient}>
+ <LoginPageContent />
+ </QueryClientProvider>
+ );
+}
diff --git a/ui/litellm-dashboard/src/app/login/page.tsx b/ui/litellm-dashboard/src/app/login/page.tsx
index bd24240a6cf..a539f87ee5e 100644
--- a/ui/litellm-dashboard/src/app/login/page.tsx
+++ b/ui/litellm-dashboard/src/app/login/page.tsx
@@ -1,154 +1,5 @@
"use client";
-import { useLogin } from "@/app/(dashboard)/hooks/login/useLogin";
-import { useUIConfig } from "@/app/(dashboard)/hooks/uiConfig/useUIConfig";
-import LoadingScreen from "@/components/common_components/LoadingScreen";
-import { getProxyBaseUrl } from "@/components/networking";
-import { getCookie } from "@/utils/cookieUtils";
-import { isJwtExpired } from "@/utils/jwtUtils";
-import { InfoCircleOutlined } from "@ant-design/icons";
-import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { Alert, Button, Card, Form, Input, Space, Typography } from "antd";
-import { useRouter } from "next/navigation";
-import { useEffect, useState } from "react";
+import LoginPage from "./LoginPage";
-function LoginPageContent() {
- const [username, setUsername] = useState("");
- const [password, setPassword] = useState("");
- const [isLoading, setIsLoading] = useState(true);
- const { isLoading: isConfigLoading } = useUIConfig();
- const loginMutation = useLogin();
- const router = useRouter();
-
- useEffect(() => {
- if (isConfigLoading) {
- return;
- }
-
- const rawToken = getCookie("token");
- if (rawToken && !isJwtExpired(rawToken)) {
- router.replace(`${getProxyBaseUrl()}/ui`);
- return;
- }
-
- setIsLoading(false);
- }, [isConfigLoading, router]);
-
- const handleSubmit = () => {
- loginMutation.mutate(
- { username, password },
- {
- onSuccess: (data) => {
- router.push(data.redirect_url);
- },
- },
- );
- };
-
- const error = loginMutation.error instanceof Error ? loginMutation.error.message : null;
- const isLoginLoading = loginMutation.isPending;
-
- const { Title, Text, Paragraph } = Typography;
-
- if (isConfigLoading || isLoading) {
- return <LoadingScreen />;
- }
-
- return (
- <div className="min-h-screen flex items-center justify-center bg-gray-50">
- <Card className="w-full max-w-lg shadow-md">
- <Space direction="vertical" size="middle" className="w-full">
- <div className="text-center">
- <Title level={2}>🚅 LiteLLM</Title>
- </div>
-
- <div className="text-center">
- <Title level={3}>Login</Title>
- <Text type="secondary">Access your LiteLLM Admin UI.</Text>
- </div>
-
- <Alert
- message="Default Credentials"
- description={
- <>
- <Paragraph className="text-sm">
- By default, Username is <code className="bg-gray-100 px-1 py-0.5 rounded text-xs">admin</code> and
- Password is your set LiteLLM Proxy
- <code className="bg-gray-100 px-1 py-0.5 rounded text-xs">MASTER_KEY</code>.
- </Paragraph>
- <Paragraph className="text-sm">
- Need to set UI credentials or SSO?{" "}
- <a href="https://docs.litellm.ai/docs/proxy/ui" target="_blank" rel="noopener noreferrer">
- Check the documentation
- </a>
- .
- </Paragraph>
- </>
- }
- type="info"
- icon={<InfoCircleOutlined />}
- showIcon
- />
-
- {error && <Alert message={error} type="error" showIcon />}
-
- <Form onFinish={handleSubmit} layout="vertical" requiredMark={true}>
- <Form.Item
- label="Username"
- name="username"
- rules={[{ required: true, message: "Please enter your username" }]}
- >
- <Input
- placeholder="Enter your username"
- autoComplete="username"
- value={username}
- onChange={(e) => setUsername(e.target.value)}
- disabled={isLoginLoading}
- size="large"
- className="rounded-md border-gray-300"
- />
- </Form.Item>
-
- <Form.Item
- label="Password"
- name="password"
- rules={[{ required: true, message: "Please enter your password" }]}
- >
- <Input.Password
- placeholder="Enter your password"
- autoComplete="current-password"
- value={password}
- onChange={(e) => setPassword(e.target.value)}
- disabled={isLoginLoading}
- size="large"
- />
- </Form.Item>
-
- <Form.Item>
- <Button
- type="primary"
- htmlType="submit"
- loading={isLoginLoading}
- disabled={isLoginLoading}
- block
- size="large"
- >
- {isLoginLoading ? "Logging in..." : "Login"}
- </Button>
- </Form.Item>
- </Form>
- </Space>
- </Card>
- </div>
- );
-}
-
-export default function LoginPage() {
- const queryClient = new QueryClient();
-
- return (
- <QueryClientProvider client={queryClient}>
- <LoginPageContent />
- </QueryClientProvider>
- );
-}
+export default LoginPage;
diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx
index 061d62d6700..0e45c0f3a91 100644
--- a/ui/litellm-dashboard/src/components/networking.tsx
+++ b/ui/litellm-dashboard/src/components/networking.tsx
@@ -205,6 +205,7 @@ export interface PublicModelHubInfo {
export interface LiteLLMWellKnownUiConfig {
server_root_path: string;
proxy_base_url: string | null;
+ auto_redirect_to_sso: boolean;
}
export interface CredentialsResponse {