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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_/epic-turing-e9b2f0
Yuneng Jiang75e6a26418a7
diff --cc ui/litellm-dashboard/src/components/leftnav.test.tsxindex e7e32718a27,04aae64c768..33a8448da44--- a/ui/litellm-dashboard/src/components/leftnav.test.tsx+++ b/ui/litellm-dashboard/src/components/leftnav.test.tsx@@@ -266,98 -267,32 +267,122 @@@ describe("Sidebar (leftnav)", () =>});expect(screen.queryByText("Prompts")).not.toBeInTheDocument();});++ it("should hide Old Usage from internal users while keeping other Experimental children", async () => {+ mockUseAuthorized.mockReturnValue(internalAuth);+ renderWithProviders(<Sidebar {...defaultProps} />);++ act(() => {+ fireEvent.click(screen.getByText("Experimental"));+ });+ await waitFor(() => {+ expect(screen.getByText("API Playground")).toBeInTheDocument();+ });+ expect(screen.queryByText("Old Usage")).not.toBeInTheDocument();+ });++ it("should show Old Usage to admins", async () => {+ renderWithProviders(<Sidebar {...defaultProps} />);++ act(() => {+ fireEvent.click(screen.getByText("Experimental"));+ });+ await waitFor(() => {+ expect(screen.getByText("Old Usage")).toBeInTheDocument();+ });+ });});+ // Workflow Runs, Memory and Guardrails Monitor render a shell and then 401+ // for every non-proxy-admin role, because their page-load routes sit outside+ // internal_user_routes / self_managed_routes. Cost Optimization does not:+ // its primary call is /user/daily/activity, which every role may make, so+ // the entry stays and only its proxy-wide tabs are gated inside the page.+ describe("capability-gated pages whose data is proxy-admin-only", () => {+ const authFor = (userRole: string) => ({+ userId: "some-user-id",+ accessToken: "test-access-token",+ userRole,+ isViewOnly: false,+ token: "test-token",+ userEmail: "[email protected]",+ premiumUser: false,+ disabledPersonalKeyCreation: false,+ showSSOBanner: false,+ });++ afterEach(() => {+ mockUseAuthorized.mockReset();+ });++ it("hides Workflow Runs and Memory from an internal user under Agentic", async () => {+ mockUseAuthorized.mockReturnValue(authFor("internal"));+ renderWithProviders(<Sidebar {...defaultProps} />);++ act(() => {+ fireEvent.click(screen.getByText("Agentic"));+ });+ // Liveness gate: the sibling Agents child stays visible to this role, so+ // the absences below mean the gate fired, not that the group never opened.+ await waitFor(() => {+ expect(screen.getByText("Agents")).toBeInTheDocument();+ });+ expect(screen.queryByText("Workflow Runs")).not.toBeInTheDocument();+ expect(screen.queryByText("Memory")).not.toBeInTheDocument();+ });++ // An org admin's session role is "Org Admin", which no capability list+ // carries, and the proxy denies these routes to org admins too because+ // `_user_is_org_admin` needs an organization_id the page-load GET never sends.+ // Agents is already out of reach for this role, so gating the other two+ // empties the Agentic group entirely and the parent must go with it rather+ // than degrade into a leaf link to the non-route `?page=agentic`.+ it("drops the whole Agentic group for an org admin once its last child is gated", () => {+ mockUseAuthorized.mockReturnValue(authFor("org_admin"));+ renderWithProviders(<Sidebar {...defaultProps} />);++ // Liveness gate: Logs carries no role list, so it proves the sidebar rendered.+ expect(screen.getByText("Logs")).toBeInTheDocument();+ expect(screen.queryByText("Agentic")).not.toBeInTheDocument();+ expect(screen.queryByText("Workflow Runs")).not.toBeInTheDocument();+ expect(screen.queryByText("Memory")).not.toBeInTheDocument();+ });++ it("keeps the Agentic group for an internal user, who can still see Agents", () => {+ mockUseAuthorized.mockReturnValue(authFor("internal"));+ renderWithProviders(<Sidebar {...defaultProps} />);++ expect(screen.getByText("Agentic")).toBeInTheDocument();+ });++ it("shows Workflow Runs and Memory to admins", async () => {+ renderWithProviders(<Sidebar {...defaultProps} />);++ act(() => {+ fireEvent.click(screen.getByText("Agentic"));+ });+ await waitFor(() => {+ expect(screen.getByText("Workflow Runs")).toBeInTheDocument();+ });+ expect(screen.getByText("Memory")).toBeInTheDocument();+ });++ it("hides Guardrails Monitor from an internal user while keeping Usage and Cost Optimization", () => {+ mockUseAuthorized.mockReturnValue(authFor("internal"));+ renderWithProviders(<Sidebar {...defaultProps} />);++ expect(screen.queryByText("Guardrails Monitor")).not.toBeInTheDocument();+ expect(screen.getByText("Usage")).toBeInTheDocument();+ expect(screen.getByText("Cost Optimization")).toBeInTheDocument();+ });++ it("shows Guardrails Monitor to admins", () => {+ renderWithProviders(<Sidebar {...defaultProps} />);++ expect(screen.getByText("Guardrails Monitor")).toBeInTheDocument();+ });+ });+it("should show Organizations tab for organization admins", () => {mockUseAuthorized.mockReturnValueOnce({userId: "org-admin-user-id",diff --cc ui/litellm-dashboard/src/utils/capabilities.test.tsindex e18ee13eb66,3492223c5e8..df09ccecac3--- a/ui/litellm-dashboard/src/utils/capabilities.test.ts+++ b/ui/litellm-dashboard/src/utils/capabilities.test.ts@@@ -25,6 -26,6 +26,13 @@@ const ADMIN_ONLY_CAPABILITIES: Capabili"viewAgentUsage",];++const PROXY_ADMIN_ONLY_PAGE_CAPABILITIES: Capability[] = [++ "viewWorkflowRuns",++ "viewMemory",++ "viewGuardrailUsage",++ "viewProxyWideCostData",++];++describe("hasCapability", () => {describe.each(ADMIN_ONLY_CAPABILITIES)("%s", (capability) => {it.each(ADMIN_ROLES)("should grant it to %s", (role) => {@@@ -37,36 -38,34 +45,58 @@@});});- // `useAuthorized` supplies `userRole` as the formatted session role from- // `effectiveSessionRole`, which collapses proxy_admin_viewer to "Admin" and- // renders an org admin as "Org Admin". The four sidebar pages behind these- // capabilities call proxy-admin-only routes: `_user_is_org_admin` needs an- // `organization_id` in the request data, which a page-load GET never carries,- // so an org admin is denied at the proxy exactly as it is here.- describe.each(["viewWorkflowRuns", "viewMemory", "viewGuardrailUsage", "viewProxyWideCostData"] as const)(- "hasCapability - %s",- (capability) => {- it.each(["Admin", "Admin Viewer", "proxy_admin", "proxy_admin_viewer"])("should grant it to %s", (role) => {- expect(hasCapability(role, capability)).toBe(true);- });+ describe("hasCapability - viewGlobalSpend", () => {+ it.each(ADMIN_ROLES)("should grant it to %s", (role) => {+ expect(hasCapability(role, "viewGlobalSpend")).toBe(true);+ });- it.each([- "Internal User",- "Internal Viewer",- "internal_user",- "internal_user_viewer",- "Org Admin",- "App User",- "Unknown Role",- "",- null,- undefined,- ])("should deny it to %s", (role) => {- expect(hasCapability(role, capability)).toBe(false);- });- },- );+ it.each([...NON_ADMIN_ROLES, "internal_user_viewer", "org_admin"])("should deny it to %s", (role) => {+ expect(hasCapability(role, "viewGlobalSpend")).toBe(false);+ });++ it("should deny it to every role an org admin or team admin can present at runtime", () => {+ const orgAdminSessionRole = effectiveSessionRole("internal_user");+ const teamAdminSessionRole = effectiveSessionRole("internal_user");++ expect(orgAdminSessionRole).toBe("Internal User");+ expect(hasCapability(orgAdminSessionRole, "viewGlobalSpend")).toBe(false);+ expect(hasCapability(teamAdminSessionRole, "viewGlobalSpend")).toBe(false);+ });++ it.each([+ ["proxy_admin", true],+ ["proxy_admin_viewer", true],+ ["internal_user", false],+ ["internal_user_viewer", false],+ ] as const)("should match the backend for a %s session", (rawRole, expected) => {+ expect(hasCapability(effectiveSessionRole(rawRole), "viewGlobalSpend")).toBe(expected);+ });+ });+++// The four sidebar pages behind these capabilities call routes the proxy serves++// to proxy_admin and proxy_admin_viewer only. An org admin is denied there too,++// because `_user_is_org_admin` needs an organization_id that a page-load GET++// never carries, so `org_admin` must not grant them either.++describe.each(PROXY_ADMIN_ONLY_PAGE_CAPABILITIES)("hasCapability - %s", (capability) => {++ it.each(ADMIN_ROLES)("should grant it to %s", (role) => {++ expect(hasCapability(role, capability)).toBe(true);++ });++++ it.each([...NON_ADMIN_ROLES, "internal_user_viewer", "org_admin"])("should deny it to %s", (role) => {++ expect(hasCapability(role, capability)).toBe(false);++ });++++ it.each([++ ["proxy_admin", true],++ ["proxy_admin_viewer", true],++ ["org_admin", false],++ ["internal_user", false],++ ["internal_user_viewer", false],++ ] as const)("should match the backend for a %s session", (rawRole, expected) => {++ expect(hasCapability(effectiveSessionRole(rawRole), capability)).toBe(expected);++ });++});+describe("rolesWithCapability", () => {it("should return a copy so callers cannot mutate the capability map", () => {const roles = rolesWithCapability("viewToolPolicies");diff --cc ui/litellm-dashboard/src/utils/capabilities.tsindex 0111c0ba93c,29c8c3819d5..36e44ca2026--- a/ui/litellm-dashboard/src/utils/capabilities.ts+++ b/ui/litellm-dashboard/src/utils/capabilities.ts@@@ -8,10 -10,7 +10,11 @@@ const CAPABILITY_ROLES =viewPrompts: all_admin_roles,viewOrganizationUsage: all_admin_roles,viewAgentUsage: all_admin_roles,- viewWorkflowRuns: all_admin_roles,- viewMemory: all_admin_roles,- viewGuardrailUsage: all_admin_roles,- viewProxyWideCostData: all_admin_roles,+ viewGlobalSpend: proxyAdminOnlyRoles,++ viewWorkflowRuns: proxyAdminOnlyRoles,++ viewMemory: proxyAdminOnlyRoles,++ viewGuardrailUsage: proxyAdminOnlyRoles,++ viewProxyWideCostData: proxyAdminOnlyRoles,} as const satisfies Record<string, readonly string[]>;export type Capability = keyof typeof CAPABILITY_ROLES;