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]

refactor(ui): polish regenerate key success view

Yuneng Jiang839d9bd5f33a
diff --git a/ui/litellm-dashboard/e2e_tests/tests/proxy-admin/keys.spec.ts b/ui/litellm-dashboard/e2e_tests/tests/proxy-admin/keys.spec.ts
index 9c19bb9b88c..3b9da5d468d 100644
--- a/ui/litellm-dashboard/e2e_tests/tests/proxy-admin/keys.spec.ts
+++ b/ui/litellm-dashboard/e2e_tests/tests/proxy-admin/keys.spec.ts
@@ -68,9 +68,9 @@ test.describe("Proxy Admin - Keys", () => {
const modal = page.locator(".ant-modal:visible");
await modal.getByRole("button", { name: /Regenerate/ }).click();
- // Success view shows the warning banner and a Copy button for the regenerated key
+ // Success view shows the warning banner and a Copy Key button in the footer
await expect(modal.getByText("Save it now, you will not see it again")).toBeVisible({ timeout: 10_000 });
- await expect(modal.getByRole("button", { name: "Copy", exact: true })).toBeVisible({ timeout: 10_000 });
+ await expect(modal.getByRole("button", { name: /Copy Key/ })).toBeVisible({ timeout: 10_000 });
});
test("Update key TPM and RPM limits", async ({ page }) => {
diff --git a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsx b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsx
index d6eb7dd55ac..1237082d2c4 100644
--- a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsx
+++ b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.test.tsx
@@ -152,7 +152,7 @@ describe("RegenerateKeyModal", () => {
expect(screen.queryByRole("button", { name: /Regenerate/ })).not.toBeInTheDocument();
});
- it("should show Copy Virtual Key button after successful regeneration", async () => {
+ it("should show Copy Key button after successful regeneration", async () => {
const user = userEvent.setup();
mockRegenerateKeyCall.mockResolvedValue({
key: "sk-new-regenerated-key",
@@ -163,7 +163,41 @@ describe("RegenerateKeyModal", () => {
await user.click(screen.getByRole("button", { name: /Regenerate/ }));
await waitFor(() => {
- expect(screen.getByRole("button", { name: /Copy/ })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: /Copy Key/ })).toBeInTheDocument();
+ });
+ });
+
+ it("should swap the Copy Key button to 'Copied' after clicking it", async () => {
+ const user = userEvent.setup();
+ mockRegenerateKeyCall.mockResolvedValue({
+ key: "sk-new-regenerated-key",
+ token: "new-token-hash",
+ });
+
+ renderWithProviders(<RegenerateKeyModal {...defaultProps} />);
+ await user.click(screen.getByRole("button", { name: /Regenerate/ }));
+
+ const copyButton = await screen.findByRole("button", { name: /Copy Key/ });
+ await user.click(copyButton);
+
+ await waitFor(() => {
+ expect(screen.getByRole("button", { name: /Copied/ })).toBeInTheDocument();
+ });
+ expect(screen.queryByRole("button", { name: /Copy Key/ })).not.toBeInTheDocument();
+ });
+
+ it("should display the 'Virtual Key' label above the key in the success view", async () => {
+ const user = userEvent.setup();
+ mockRegenerateKeyCall.mockResolvedValue({
+ key: "sk-new-regenerated-key",
+ token: "new-token-hash",
+ });
+
+ renderWithProviders(<RegenerateKeyModal {...defaultProps} />);
+ await user.click(screen.getByRole("button", { name: /Regenerate/ }));
+
+ await waitFor(() => {
+ expect(screen.getByText("Virtual Key")).toBeInTheDocument();
});
});
diff --git a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsx b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsx
index c942832e9f4..3f254319bdb 100644
--- a/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsx
+++ b/ui/litellm-dashboard/src/components/organisms/RegenerateKeyModal.tsx
@@ -1,13 +1,14 @@
import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
-import { SyncOutlined } from "@ant-design/icons";
+import { CheckOutlined, CopyOutlined, SyncOutlined } from "@ant-design/icons";
import { Alert, Button, Col, Flex, Form, Input, InputNumber, Modal, Row, Space, Typography } from "antd";
import { add } from "date-fns";
import { useEffect, useState } from "react";
+import { CopyToClipboard } from "react-copy-to-clipboard";
import { KeyResponse } from "../key_team_helpers/key_list";
import NotificationManager from "../molecules/notifications_manager";
import { regenerateKeyCall } from "../networking";
-const { Text, Paragraph } = Typography;
+const { Text } = Typography;
interface RegenerateKeyModalProps {
selectedToken: KeyResponse | null;
@@ -23,6 +24,7 @@ export function RegenerateKeyModal({ selectedToken, visible, onClose, onKeyUpdat
const [regenerateFormData, setRegenerateFormData] = useState<any>(null);
const [newExpiryTime, setNewExpiryTime] = useState<string | null>(null);
const [isRegenerating, setIsRegenerating] = useState(false);
+ const [copied, setCopied] = useState(false);
// Track whether this is the user's own authentication key
const [isOwnKey, setIsOwnKey] = useState<boolean>(false);
@@ -57,6 +59,7 @@ export function RegenerateKeyModal({ selectedToken, visible, onClose, onKeyUpdat
setIsRegenerating(false);
setIsOwnKey(false);
setCurrentAccessToken(null);
+ setCopied(false);
form.resetFields();
}
}, [visible, form]);
@@ -143,22 +146,33 @@ export function RegenerateKeyModal({ selectedToken, visible, onClose, onKeyUpdat
setIsRegenerating(false);
setIsOwnKey(false);
setCurrentAccessToken(null);
+ setCopied(false);
form.resetFields();
onClose();
};
+ const handleCopyKey = () => {
+ setCopied(true);
+ };
+
return (
<Modal
title="Regenerate Virtual Key"
open={visible}
onCancel={handleClose}
width={520}
+ maskClosable={false}
footer={
regeneratedKey
? [
- <Button key="close" onClick={handleClose}>
- Close
- </Button>,
+ <Space key="footer-actions">
+ <Button onClick={handleClose}>Close</Button>
+ <CopyToClipboard text={regeneratedKey} onCopy={handleCopyKey}>
+ <Button type="primary" icon={copied ? <CheckOutlined /> : <CopyOutlined />}>
+ {copied ? "Copied" : "Copy Key"}
+ </Button>
+ </CopyToClipboard>
+ </Space>,
]
: [
<Space key="footer-actions">
@@ -181,16 +195,25 @@ export function RegenerateKeyModal({ selectedToken, visible, onClose, onKeyUpdat
<Text>{selectedToken?.key_alias || "No alias set"}</Text>
</Flex>
- <Paragraph
- code
- copyable={{
- text: regeneratedKey,
- onCopy: () => NotificationManager.success("Virtual Key copied to clipboard"),
- }}
- style={{ marginBottom: 0, wordBreak: "break-all" }}
- >
- {regeneratedKey}
- </Paragraph>
+ <Flex vertical gap={6}>
+ <Text type="secondary" style={{ fontSize: 12 }}>
+ Virtual Key
+ </Text>
+ <div
+ style={{
+ background: "#f5f5f5",
+ border: "1px solid #e8e8e8",
+ borderRadius: 6,
+ padding: "14px 16px",
+ fontFamily: "SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace",
+ fontSize: 16,
+ wordBreak: "break-all",
+ color: "#262626",
+ }}
+ >
+ {regeneratedKey}
+ </div>
+ </Flex>
</Flex>
) : (
<Form