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_/nifty-knuth-f7f2c6
Yuneng Jiang25172e94d01c
diff --cc ui/litellm-dashboard/src/utils/capabilities.test.tsindex ab3358b80ac,98752456166..56eaecd7a5f--- a/ui/litellm-dashboard/src/utils/capabilities.test.ts+++ b/ui/litellm-dashboard/src/utils/capabilities.test.ts@@@ -1,118 -1,42 +1,76 @@@import { describe, expect, it } from "vitest";- import { hasCapability, rolesWithCapability } from "./capabilities";+ import { hasCapability, rolesWithCapability, type Capability } from "./capabilities";+import { effectiveSessionRole } from "./roles";- describe("hasCapability", () => {- it.each(["Admin", "Admin Viewer", "proxy_admin", "proxy_admin_viewer"])(- "should grant viewToolPolicies to %s",- (role) => {- expect(hasCapability(role, "viewToolPolicies")).toBe(true);- },- );-- it.each(["Internal User", "Internal Viewer", "App User", "Org Admin", "Unknown Role", "", null, undefined])(- "should deny viewToolPolicies to %s",- (role) => {- expect(hasCapability(role, "viewToolPolicies")).toBe(false);- },- );-- it.each(["Admin", "Admin Viewer", "proxy_admin", "proxy_admin_viewer"])("should grant viewPolicies to %s", (role) => {- expect(hasCapability(role, "viewPolicies")).toBe(true);- });-- it.each([- "Internal User",- "Internal Viewer",- "internal_user",- "App User",- "Org Admin",- "Unknown Role",- "",- null,- undefined,- ])("should deny viewPolicies to %s", (role) => {- expect(hasCapability(role, "viewPolicies")).toBe(false);- });-- it.each(["Admin", "Admin Viewer", "proxy_admin", "proxy_admin_viewer"])("should grant viewPrompts to %s", (role) => {- expect(hasCapability(role, "viewPrompts")).toBe(true);- });-- it.each([- "Internal User",- "Internal Viewer",- "internal_user",- "App User",- "Org Admin",- "Unknown Role",- "",- null,- undefined,- ])("should deny viewPrompts to %s", (role) => {- expect(hasCapability(role, "viewPrompts")).toBe(false);- });- });+ const ADMIN_ROLES = ["Admin", "Admin Viewer", "proxy_admin", "proxy_admin_viewer"];+ const NON_ADMIN_ROLES = [+ "Internal User",+ "Internal Viewer",+ "internal_user",+ "App User",+ "Org Admin",+ "Unknown Role",+ "",+ null,+ undefined,+ ];++ const ADMIN_ONLY_CAPABILITIES: Capability[] = [+ "viewToolPolicies",+ "viewAuditLogs",+ "viewDeletedTeams",+ "viewPolicies",+ "viewPrompts",+ "viewOrganizationUsage",+ "viewAgentUsage",+ ];- describe.each(["viewAuditLogs", "viewDeletedTeams"] 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", () => {+ describe.each(ADMIN_ONLY_CAPABILITIES)("%s", (capability) => {+ it.each(ADMIN_ROLES)("should grant it to %s", (role) => {+ expect(hasCapability(role, capability)).toBe(true);+ });- it.each(["Internal User", "Internal Viewer", "App User", "Org Admin", "Unknown Role", "", null, undefined])(- "should deny it to %s",- (role) => {+ it.each(NON_ADMIN_ROLES)("should deny it to %s", (role) => {expect(hasCapability(role, capability)).toBe(false);- },- );+ });+ });});+// Backend truth table for the `/global/spend/*` routes the Old Usage page calls+// (verified against a live proxy): only proxy_admin and proxy_admin_viewer are+// served. Org admins and team admins carry `internal_user` as their top-level+// user_role, so `effectiveSessionRole` renders them "Internal User" — an org+// admin never reaches the UI as "Org Admin" or `org_admin`.+describe("hasCapability - viewGlobalSpend", () => {- it.each(["Admin", "Admin Viewer", "proxy_admin", "proxy_admin_viewer"])("should grant it to %s", (role) => {++ 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",- "org_admin",- "App User",- "Unknown Role",- "",- null,- undefined,- ])("should deny it to %s", (role) => {++ 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);+ });+});+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 014bf8530f4,6be75ba402e..29c8c3819d5--- a/ui/litellm-dashboard/src/utils/capabilities.ts+++ b/ui/litellm-dashboard/src/utils/capabilities.ts@@@ -8,7 -6,8 +8,9 @@@ const CAPABILITY_ROLES =viewDeletedTeams: all_admin_roles,viewPolicies: all_admin_roles,viewPrompts: all_admin_roles,+ viewOrganizationUsage: all_admin_roles,+ viewAgentUsage: all_admin_roles,+ viewGlobalSpend: proxyAdminOnlyRoles,} as const satisfies Record<string, readonly string[]>;export type Capability = keyof typeof CAPABILITY_ROLES;