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
fix(ui): repoint the key detail URL to the rotated hash after regenerating (#37968)
yuneng-jiang7113685a76fb
diff --git a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsx b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsxindex 9ef849dbeb2..643da71e8b1 100644--- a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsx+++ b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.test.tsx@@ -8,6 +8,7 @@ import { KeyResponse, Team } from "../key_team_helpers/key_list";import { useKeyInfo } from "@/app/(dashboard)/hooks/keys/useKeyInfo";import { KeysResponse, useKeys } from "@/app/(dashboard)/hooks/keys/useKeys";import useTeams from "@/app/(dashboard)/hooks/useTeams";+import { regenerateKeyCall } from "../networking";// Resolve debounced values synchronously so an applied filter lands in the useKeys query within the test tick.vi.mock("@tanstack/react-pacer/debouncer", async () => {@@ -25,6 +26,11 @@ vi.mock("@tanstack/react-pacer/debouncer", async () => {vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn() }) }));+vi.mock("../networking", async (importOriginal) => ({+ ...(await importOriginal<typeof import("../networking")>()),+ regenerateKeyCall: vi.fn(),+}));+vi.mock("@/app/(dashboard)/hooks/useAuthorized", () => ({default: vi.fn(() => ({accessToken: "test-token",@@ -389,6 +395,28 @@ it("renders KeyInfoView when the URL has ?key= for a key on the current page, wiexpect(screen.getByTestId("pagination-range")).toBeInTheDocument();});+it("repoints ?key= to the rotated hash once the regenerate dialog is dismissed", async () => {+ const user = userEvent.setup();+ vi.mocked(regenerateKeyCall).mockResolvedValue({+ key: "sk-rotated-plaintext",+ token: null,+ token_id: "rotated-hash-456",+ });+ const onUrlUpdate = vi.fn<OnUrlUpdateFunction>();+ renderWithProviders(<VirtualKeysTable />, { searchParams: { key: mockKey.token }, onUrlUpdate });++ await user.click(await screen.findByRole("button", { name: /regenerate key/i }));+ await user.click(await screen.findByRole("button", { name: /^Regenerate$/ }));+ expect(await screen.findAllByText("sk-rotated-plaintext")).not.toHaveLength(0);+ expect(lastKeyParam(onUrlUpdate)).toBeUndefined();++ await user.click(screen.getAllByRole("button", { name: "Close" })[0]);++ await waitFor(() => {+ expect(lastKeyParam(onUrlUpdate)).toBe("rotated-hash-456");+ });+});+it("fetches the key by id when the URL has ?key= for a key not in the loaded page", async () => {mockUseKeyInfo.mockReturnValue(keyInfoResult({ ...mockKey, token: "other-key-hash", key_alias: "Fetched Key Alias" }),diff --git a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsx b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsxindex b278b4f675d..fbdcf2d8d83 100644--- a/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsx+++ b/ui/litellm-dashboard/src/components/VirtualKeysPage/VirtualKeysTable.tsx@@ -20,7 +20,7 @@ import { KeyRound } from "lucide-react";import { parseAsString, useQueryState } from "nuqs";import React, { useCallback, useMemo, useState } from "react";-import { Team } from "../key_team_helpers/key_list";+import { KeyResponse, Team } from "../key_team_helpers/key_list";import KeyInfoView from "../templates/key_info_view";import { getKeyTableColumns, KEY_TABLE_HIDDEN_COLUMNS } from "./keyTableColumns";@@ -139,6 +139,16 @@ export function VirtualKeysTable({ headerActions }: VirtualKeysTableProps) {[organizations],);+ const handleSelectedKeyDataUpdate = useCallback(+ (updated: Partial<KeyResponse>) => {+ const rotatedToken = updated.token ?? updated.token_id;+ if (!rotatedToken || rotatedToken === selectedKeyId) return;+ void setSelectedKeyId(rotatedToken);+ void refetch();+ },+ [refetch, selectedKeyId, setSelectedKeyId],+ );+const formatFilterValue = useCallback((columnId: string, value: unknown): string => {const raw = String(value);@@ -165,6 +175,7 @@ export function VirtualKeysTable({ headerActions }: VirtualKeysTableProps) {keyData={selectedKey}teams={allTeams}onDelete={refetch}+ onKeyDataUpdate={handleSelectedKeyDataUpdate}/></div>);diff --git a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsx b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsxindex 180f9d1f265..262ce9669f2 100644--- a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsx+++ b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsx@@ -427,4 +427,21 @@ describe("RegenerateKeyModal", () => {);});});++ it("should report the rotated hash from token_id when the API leaves token null", async () => {+ const user = userEvent.setup();+ mockRegenerateKeyCall.mockResolvedValue({+ key: "sk-new-regenerated-key",+ token: null,+ token_id: "rotated-hash-456",+ });++ renderWithProviders(<RegenerateKeyModal {...defaultProps} />);+ await user.click(screen.getByRole("button", { name: /Regenerate/ }));++ await waitFor(() => {+ expect(mockOnKeyUpdate).toHaveBeenCalledOnce();+ });+ expect(mockOnKeyUpdate.mock.calls[0][0].token).toBe("rotated-hash-456");+ });});diff --git a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsx b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsxindex d85e6cb5f91..a2658985f32 100644--- a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsx+++ b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsx@@ -107,7 +107,7 @@ export function RegenerateKeyModal({ selectedToken, visible, onClose, onKeyUpdat// formatted preview, otherwise downstream expiry parsing breaks.const updatedKeyData: Partial<KeyResponse> = {...response,- token: response.token || response.key_id || selectedToken.token,+ token: response.token_id || response.token || selectedToken.token,key_name: response.key,max_budget: formValues.max_budget,tpm_limit: formValues.tpm_limit,diff --git a/ui/litellm-dashboard/src/components/templates/key_info_view.tsx b/ui/litellm-dashboard/src/components/templates/key_info_view.tsxindex 5cfa737397b..59950303c45 100644--- a/ui/litellm-dashboard/src/components/templates/key_info_view.tsx+++ b/ui/litellm-dashboard/src/components/templates/key_info_view.tsx@@ -100,6 +100,9 @@ export default function KeyInfoView({// Add local state to maintain key data and track regenerationconst [currentKeyData, setCurrentKeyData] = useState<KeyResponse | undefined>(keyData);const [lastRegeneratedAt, setLastRegeneratedAt] = useState<Date | null>(null);+ const [keyDataUpdateHeldUntilModalClose, setKeyDataUpdateHeldUntilModalClose] = useState<Partial<KeyResponse> | null>(+ null,+ );const [isRecentlyRegenerated, setIsRecentlyRegenerated] = useState(false);const [policyGuardrails, setPolicyGuardrails] = useState<Record<string, string[]>>({});const [loadingPolicies, setLoadingPolicies] = useState(false);@@ -352,6 +355,7 @@ export default function KeyInfoView({};const handleRegenerateKeyUpdate = (updatedKeyData: Partial<KeyResponse>) => {+ const regeneratedAt = new Date();// Update local state immediately with ALL the new datasetCurrentKeyData((prevData) => {if (!prevData) return undefined;@@ -359,20 +363,26 @@ export default function KeyInfoView({...prevData,...updatedKeyData, // This should include the new token (key-id)// Update the created_at to show when it was regenerated- created_at: new Date().toLocaleString(),+ created_at: regeneratedAt.toLocaleString(),};return newData;});// Track regeneration timestamp- setLastRegeneratedAt(new Date());+ setLastRegeneratedAt(regeneratedAt);setIsRecentlyRegenerated(true);- if (onKeyDataUpdate) {- onKeyDataUpdate({- ...updatedKeyData,- created_at: new Date().toLocaleString(),- });+ setKeyDataUpdateHeldUntilModalClose({+ ...updatedKeyData,+ created_at: regeneratedAt.toLocaleString(),+ });+ };++ const handleRegenerateModalClose = () => {+ setIsRegenerateModalOpen(false);+ if (keyDataUpdateHeldUntilModalClose) {+ setKeyDataUpdateHeldUntilModalClose(null);+ onKeyDataUpdate?.(keyDataUpdateHeldUntilModalClose);}};@@ -506,7 +516,7 @@ export default function KeyInfoView({<RegenerateKeyModalselectedToken={currentKeyData}visible={isRegenerateModalOpen}- onClose={() => setIsRegenerateModalOpen(false)}+ onClose={handleRegenerateModalClose}onKeyUpdate={handleRegenerateKeyUpdate}/>