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]

[Feature] UI - Add Key Type Select in Key Settings (#16034)

yuneng-jiang1b234108c0c3
diff --git a/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx b/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx
index 552b9b705cd..695d0571419 100644
--- a/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx
+++ b/ui/litellm-dashboard/src/components/key_team_helpers/key_list.tsx
@@ -37,6 +37,7 @@ export interface KeyResponse {
budget_duration: string;
budget_reset_at: string;
allowed_cache_controls: string[];
+ allowed_routes: string[];
permissions: Record<string, unknown>;
model_spend: Record<string, number>;
model_max_budget: Record<string, number>;
diff --git a/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
new file mode 100644
index 00000000000..9033bb373e3
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/templates/key_edit_view.test.tsx
@@ -0,0 +1,107 @@
+import { render, waitFor } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+import { KeyEditView } from "./key_edit_view";
+import { KeyResponse } from "../key_team_helpers/key_list";
+
+// Mock window.matchMedia
+Object.defineProperty(window, "matchMedia", {
+ writable: true,
+ value: vi.fn().mockImplementation((query) => ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: vi.fn(),
+ removeListener: vi.fn(),
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ dispatchEvent: vi.fn(),
+ })),
+});
+
+describe("KeyEditView", () => {
+ const MOCK_KEY_DATA: KeyResponse = {
+ token: "40b7608ea43423400d5b82bb5ee11042bfb2ed4655f05b5992b5abbc2f294931",
+ token_id: "40b7608ea43423400d5b82bb5ee11042bfb2ed4655f05b5992b5abbc2f294931",
+ key_name: "sk-...TUuw",
+ key_alias: "asdasdas",
+ spend: 0,
+ max_budget: 0,
+ expires: "null",
+ models: [],
+ aliases: {},
+ config: {},
+ user_id: "default_user_id",
+ team_id: null,
+ max_parallel_requests: 10,
+ metadata: {
+ logging: [],
+ },
+ tpm_limit: 10,
+ rpm_limit: 10,
+ duration: "30d",
+ budget_duration: "30d",
+ budget_reset_at: "never",
+ allowed_cache_controls: [],
+ allowed_routes: [],
+ permissions: {},
+ model_spend: {},
+ model_max_budget: {},
+ soft_budget_cooldown: false,
+ blocked: false,
+ litellm_budget_table: {},
+ organization_id: null,
+ created_at: "2025-10-29T01:26:41.613000Z",
+ updated_at: "2025-10-29T01:47:33.980000Z",
+ team_spend: 100,
+ team_alias: "",
+ team_tpm_limit: 100,
+ team_rpm_limit: 100,
+ team_max_budget: 100,
+ team_models: [],
+ team_blocked: false,
+ soft_budget: 200,
+ team_model_aliases: {},
+ team_member_spend: 0,
+ team_metadata: {},
+ end_user_id: "default_user_id",
+ end_user_tpm_limit: 10,
+ end_user_rpm_limit: 10,
+ end_user_max_budget: 0,
+ last_refreshed_at: Date.now(),
+ api_key: "sk-...TUuw",
+ user_role: "user",
+ rpm_limit_per_model: {},
+ tpm_limit_per_model: {},
+ user_tpm_limit: 10,
+ user_rpm_limit: 10,
+ user_email: "[email protected]",
+ object_permission: {
+ object_permission_id: "067002ed-3b01-4bb3-b942-cefa400f0049",
+ mcp_servers: [],
+ mcp_access_groups: [],
+ mcp_tool_permissions: {},
+ vector_stores: [],
+ },
+ auto_rotate: false,
+ rotation_interval: undefined,
+ last_rotation_at: undefined,
+ key_rotation_at: undefined,
+ };
+ it("should render", async () => {
+ const { getByText } = render(
+ <KeyEditView
+ keyData={MOCK_KEY_DATA}
+ onCancel={() => {}}
+ onSubmit={async () => {}}
+ accessToken={""}
+ userID={""}
+ userRole={""}
+ premiumUser={false}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(getByText("Save Changes")).toBeInTheDocument();
+ });
+ });
+});
diff --git a/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx b/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx
index 598f2b1f7ec..3b9cf3c30da 100644
--- a/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx
+++ b/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx
@@ -47,6 +47,27 @@ const getAvailableModelsForKey = (keyData: KeyResponse, teams: any[] | null): st
return [];
};
+// Helper function to determine key_type display value from allowed_routes
+const getKeyTypeFromRoutes = (allowedRoutes: string[] | null | undefined): string => {
+ if (!allowedRoutes || allowedRoutes.length === 0) {
+ return "default";
+ }
+
+ if (allowedRoutes.includes("llm_api_routes")) {
+ return "llm_api";
+ }
+
+ if (allowedRoutes.includes("management_routes")) {
+ return "management";
+ }
+
+ if (allowedRoutes.includes("info_routes")) {
+ return "read_only";
+ }
+
+ return "default";
+};
+
export function KeyEditView({
keyData,
onCancel,
@@ -154,6 +175,7 @@ export function KeyEditView({
: [],
auto_rotate: keyData.auto_rotate || false,
...(keyData.rotation_interval && { rotation_interval: keyData.rotation_interval }),
+ allowed_routes: keyData.allowed_routes,
};
useEffect(() => {
@@ -176,6 +198,7 @@ export function KeyEditView({
: [],
auto_rotate: keyData.auto_rotate || false,
...(keyData.rotation_interval && { rotation_interval: keyData.rotation_interval }),
+ allowed_routes: keyData.allowed_routes,
});
}, [keyData, form]);
@@ -199,16 +222,104 @@ export function KeyEditView({
</Form.Item>
<Form.Item label="Models" name="models">
- <Select mode="multiple" placeholder="Select models" style={{ width: "100%" }}>
- {/* Only show All Team Models if team has models */}
- {availableModels.length > 0 && <Select.Option value="all-team-models">All Team Models</Select.Option>}
- {/* Show available team models */}
- {availableModels.map((model) => (
- <Select.Option key={model} value={model}>
- {model}
- </Select.Option>
- ))}
- </Select>
+ <Form.Item
+ noStyle
+ shouldUpdate={(prevValues, currentValues) =>
+ prevValues.allowed_routes !== currentValues.allowed_routes || prevValues.models !== currentValues.models
+ }
+ >
+ {({ getFieldValue, setFieldValue }) => {
+ const allowedRoutes = getFieldValue("allowed_routes") || [];
+ const isDisabled = allowedRoutes.includes("management_routes") || allowedRoutes.includes("info_routes");
+ const models = getFieldValue("models") || [];
+
+ return (
+ <>
+ <Select
+ mode="multiple"
+ placeholder="Select models"
+ style={{ width: "100%" }}
+ disabled={isDisabled}
+ value={isDisabled ? [] : models}
+ onChange={(value) => setFieldValue("models", value)}
+ >
+ {/* Only show All Team Models if team has models */}
+ {availableModels.length > 0 && <Select.Option value="all-team-models">All Team Models</Select.Option>}
+ {availableModels.map((model) => (
+ <Select.Option key={model} value={model}>
+ {model}
+ </Select.Option>
+ ))}
+ </Select>
+ {isDisabled && (
+ <div style={{ fontSize: "11px", color: "#6b7280", marginTop: "2px" }}>
+ Models field is disabled for this key type
+ </div>
+ )}
+ </>
+ );
+ }}
+ </Form.Item>
+ </Form.Item>
+
+ <Form.Item label="Key Type">
+ <Form.Item
+ noStyle
+ shouldUpdate={(prevValues, currentValues) => prevValues.allowed_routes !== currentValues.allowed_routes}
+ >
+ {({ getFieldValue, setFieldValue }) => {
+ const allowedRoutes = getFieldValue("allowed_routes");
+ const keyTypeValue = getKeyTypeFromRoutes(allowedRoutes);
+
+ return (
+ <Select
+ placeholder="Select key type"
+ style={{ width: "100%" }}
+ optionLabelProp="label"
+ value={keyTypeValue}
+ onChange={(value) => {
+ switch (value) {
+ case "default":
+ setFieldValue("allowed_routes", []);
+ break;
+ case "llm_api":
+ setFieldValue("allowed_routes", ["llm_api_routes"]);
+ break;
+ case "management":
+ setFieldValue("allowed_routes", ["management_routes"]);
+ setFieldValue("models", []);
+ break;
+ }
+ }}
+ >
+ <Select.Option value="default" label="Default">
+ <div style={{ padding: "4px 0" }}>
+ <div style={{ fontWeight: 500 }}>Default</div>
+ <div style={{ fontSize: "11px", color: "#6b7280", marginTop: "2px" }}>
+ Can call LLM API + Management routes
+ </div>
+ </div>
+ </Select.Option>
+ <Select.Option value="llm_api" label="LLM API">
+ <div style={{ padding: "4px 0" }}>
+ <div style={{ fontWeight: 500 }}>LLM API</div>
+ <div style={{ fontSize: "11px", color: "#6b7280", marginTop: "2px" }}>
+ Can call only LLM API routes (chat/completions, embeddings, etc.)
+ </div>
+ </div>
+ </Select.Option>
+ <Select.Option value="management" label="Management">
+ <div style={{ padding: "4px 0" }}>
+ <div style={{ fontWeight: 500 }}>Management</div>
+ <div style={{ fontSize: "11px", color: "#6b7280", marginTop: "2px" }}>
+ Can call only management routes (user/team/key management)
+ </div>
+ </div>
+ </Select.Option>
+ </Select>
+ );
+ }}
+ </Form.Item>
</Form.Item>
<Form.Item label="Max Budget (USD)" name="max_budget">
@@ -278,7 +389,10 @@ export function KeyEditView({
</Form.Item>
<Form.Item label="Allowed Pass Through Routes" name="allowed_passthrough_routes">
- <Tooltip title={!premiumUser ? "Setting allowed pass through routes by key is a premium feature" : ""} placement="top">
+ <Tooltip
+ title={!premiumUser ? "Setting allowed pass through routes by key is a premium feature" : ""}
+ placement="top"
+ >
<PassThroughRoutesSelector
onChange={(values: string[]) => form.setFieldValue("allowed_passthrough_routes", values)}
value={form.getFieldValue("allowed_passthrough_routes")}
@@ -286,7 +400,8 @@ export function KeyEditView({
placeholder={
!premiumUser
? "Premium feature - Upgrade to set allowed pass through routes by key"
- : Array.isArray(keyData.metadata?.allowed_passthrough_routes) && keyData.metadata.allowed_passthrough_routes.length > 0
+ : Array.isArray(keyData.metadata?.allowed_passthrough_routes) &&
+ keyData.metadata.allowed_passthrough_routes.length > 0
? `Current: ${keyData.metadata.allowed_passthrough_routes.join(", ")}`
: "Select or enter allowed pass through routes"
}
@@ -382,6 +497,11 @@ export function KeyEditView({
<Input />
</Form.Item>
+ {/* Hidden form field for allowed_routes */}
+ <Form.Item name="allowed_routes" hidden>
+ <Input />
+ </Form.Item>
+
{/* Hidden form field for disabled callbacks */}
<Form.Item name="disabled_callbacks" hidden>
<Input />