Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🔑 feat: Agent API Keys management UI in Settings → Data controls (#13819)

Marco Berettaa468becf8c85
diff --git a/client/src/components/Nav/Settings/registry.tsx b/client/src/components/Nav/Settings/registry.tsx
index 07250fc564..415a753bef 100644
--- a/client/src/components/Nav/Settings/registry.tsx
+++ b/client/src/components/Nav/Settings/registry.tsx
@@ -26,7 +26,6 @@ import FontSizeSelector from '../SettingsTabs/Chat/FontSizeSelector';
import AdvancedPrompts from '../SettingsTabs/Chat/AdvancedPrompts';
import DeleteAccount from '../SettingsTabs/Account/DeleteAccount';
import { ForkSettings } from '../SettingsTabs/Chat/ForkSettings';
-import { AgentApiKeys } from '../SettingsTabs/Data/AgentApiKeys';
import ChatDirection from '../SettingsTabs/Chat/ChatDirection';
import { DeleteCache } from '../SettingsTabs/Data/DeleteCache';
import { RevokeKeys } from '../SettingsTabs/Data/RevokeKeys';
@@ -36,6 +35,7 @@ import SharedLinks from '../SettingsTabs/Data/SharedLinks';
import { showThinkingAtom } from '~/store/showThinking';
import Avatar from '../SettingsTabs/Account/Avatar';
import About from '../SettingsTabs/About/About';
+import ApiKeys from '../SettingsTabs/ApiKeys';
import MemoryToggle from './MemoryToggle';
import { TTSEndpoints } from '~/common';
import store from '~/store';
@@ -472,7 +472,7 @@ export const registry: SettingEntry[] = [
section: 'apiKeys',
labelKey: 'com_ui_settings_label_agent_api_keys',
show: (ctx) => ctx.hasRemoteAgents,
- Component: AgentApiKeys,
+ Component: ApiKeys,
},
{
id: 'revokeKeys',
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/Admin.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/Admin.tsx
new file mode 100644
index 0000000000..dd9af62791
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/Admin.tsx
@@ -0,0 +1,46 @@
+import { ShieldEllipsis } from 'lucide-react';
+import { Button, useToastContext } from '@librechat/client';
+import { Permissions, PermissionTypes } from 'librechat-data-provider';
+import type { PermissionConfig } from '~/components/ui';
+import { useUpdateRemoteAgentsPermissionsMutation } from '~/data-provider';
+import { AdminSettingsDialog } from '~/components/ui';
+import { useLocalize } from '~/hooks';
+
+const remoteAgentsPermissions: PermissionConfig[] = [
+ { permission: Permissions.USE, labelKey: 'com_ui_remote_agents_allow_use' },
+ { permission: Permissions.CREATE, labelKey: 'com_ui_remote_agents_allow_create' },
+ { permission: Permissions.SHARE, labelKey: 'com_ui_remote_agents_allow_share' },
+ { permission: Permissions.SHARE_PUBLIC, labelKey: 'com_ui_remote_agents_allow_share_public' },
+];
+
+export default function Admin() {
+ const localize = useLocalize();
+ const { showToast } = useToastContext();
+
+ const mutation = useUpdateRemoteAgentsPermissionsMutation({
+ onSuccess: () => {
+ showToast({ status: 'success', message: localize('com_ui_saved') });
+ },
+ onError: () => {
+ showToast({ status: 'error', message: localize('com_ui_error_save_admin_settings') });
+ },
+ });
+
+ const trigger = (
+ <Button variant="outline" size="sm" className="gap-1.5 text-text-secondary">
+ <ShieldEllipsis className="h-4 w-4" aria-hidden="true" />
+ {localize('com_ui_admin_panel')}
+ </Button>
+ );
+
+ return (
+ <AdminSettingsDialog
+ permissionType={PermissionTypes.REMOTE_AGENTS}
+ sectionKey="com_ui_remote_agents"
+ permissions={remoteAgentsPermissions}
+ menuId="remote-agents-role-dropdown"
+ mutation={mutation}
+ trigger={trigger}
+ />
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/ApiKeys.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/ApiKeys.tsx
new file mode 100644
index 0000000000..a857ddd8c3
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/ApiKeys.tsx
@@ -0,0 +1,55 @@
+import { useState } from 'react';
+import { Plus } from 'lucide-react';
+import {
+ Label,
+ Button,
+ OGDialog,
+ OGDialogTitle,
+ OGDialogHeader,
+ InfoHoverCard,
+ OGDialogTrigger,
+ OGDialogContent,
+} from '@librechat/client';
+import CreateKeyDialog from './CreateKeyDialog';
+import { useLocalize } from '~/hooks';
+import Admin from './Admin';
+import List from './List';
+
+export default function ApiKeys() {
+ const localize = useLocalize();
+ const [open, setOpen] = useState(false);
+ const [createOpen, setCreateOpen] = useState(false);
+
+ return (
+ <div className="flex items-center justify-between">
+ <Label id="agent-api-keys-label">{localize('com_ui_agent_api_keys')}</Label>
+ <OGDialog open={open} onOpenChange={setOpen}>
+ <OGDialogTrigger asChild>
+ <Button variant="outline" aria-labelledby="agent-api-keys-label">
+ {localize('com_ui_manage')}
+ </Button>
+ </OGDialogTrigger>
+ <OGDialogContent
+ className="w-11/12 max-w-2xl bg-background text-text-primary shadow-2xl"
+ aria-describedby={undefined}
+ >
+ <OGDialogHeader className="space-y-0 pr-8 text-left">
+ <div className="flex items-center gap-1.5">
+ <OGDialogTitle>{localize('com_ui_agent_api_keys')}</OGDialogTitle>
+ <InfoHoverCard text={localize('com_ui_api_keys_description')} />
+ </div>
+ </OGDialogHeader>
+ <List onCreate={() => setCreateOpen(true)} />
+ <div className="flex items-center gap-2">
+ <Admin />
+ <Button size="sm" className="ml-auto gap-1.5" onClick={() => setCreateOpen(true)}>
+ <Plus className="h-4 w-4" aria-hidden="true" />
+ {localize('com_ui_create_api_key')}
+ </Button>
+ </div>
+ <CreateKeyDialog open={createOpen} onOpenChange={setCreateOpen} />
+ </OGDialogContent>
+ </OGDialog>
+ </div>
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/Create.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/Create.tsx
new file mode 100644
index 0000000000..20b8f4f479
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/Create.tsx
@@ -0,0 +1,114 @@
+import { useRef, useState } from 'react';
+import { useCreateAgentApiKeyMutation } from 'librechat-data-provider/react-query';
+import { Button, Input, Label, Radio, Spinner, useToastContext } from '@librechat/client';
+import type { TAgentApiKeyCreateResponse } from 'librechat-data-provider';
+import type { FormEvent } from 'react';
+import { computeExpiresAt, formatDate, DEFAULT_EXPIRY, EXPIRY_OPTIONS } from './utils';
+import { useLocalize } from '~/hooks';
+
+type CreateProps = {
+ onCreated: (result: TAgentApiKeyCreateResponse) => void;
+ onCancel: () => void;
+};
+
+export default function Create({ onCreated, onCancel }: CreateProps) {
+ const localize = useLocalize();
+ const { showToast } = useToastContext();
+ const [name, setName] = useState('');
+ const [nameError, setNameError] = useState(false);
+ const [expiry, setExpiry] = useState(DEFAULT_EXPIRY);
+ const inputRef = useRef<HTMLInputElement>(null);
+ const createMutation = useCreateAgentApiKeyMutation();
+
+ const expiresAt = computeExpiresAt(expiry);
+
+ const handleSubmit = async (event: FormEvent) => {
+ event.preventDefault();
+ if (createMutation.isLoading) {
+ return;
+ }
+ if (!name.trim()) {
+ setNameError(true);
+ inputRef.current?.focus();
+ return;
+ }
+ try {
+ const result = await createMutation.mutateAsync({
+ name: name.trim(),
+ expiresAt: computeExpiresAt(expiry),
+ });
+ onCreated(result);
+ } catch {
+ showToast({ message: localize('com_ui_api_key_create_error'), status: 'error' });
+ }
+ };
+
+ return (
+ <form onSubmit={handleSubmit} className="space-y-5">
+ <div className="space-y-2">
+ <Label htmlFor="api-key-name">{localize('com_ui_api_key_name')}</Label>
+ <Input
+ id="api-key-name"
+ ref={inputRef}
+ value={name}
+ maxLength={100}
+ aria-invalid={nameError}
+ aria-describedby={nameError ? 'api-key-name-error' : undefined}
+ onChange={(e) => {
+ setName(e.target.value);
+ if (nameError) {
+ setNameError(false);
+ }
+ }}
+ placeholder={localize('com_ui_api_key_name_placeholder')}
+ />
+ {nameError && (
+ <p
+ id="api-key-name-error"
+ role="alert"
+ className="text-xs text-red-500 dark:text-red-400"
+ >
+ {localize('com_ui_api_key_name_required')}
+ </p>
+ )}
+ </div>
+ <div className="space-y-2">
+ <Label id="api-key-expiry-label">{localize('com_ui_api_key_expiration')}</Label>
+ <Radio
+ fullWidth
+ value={expiry}
+ onChange={setExpiry}
+ aria-labelledby="api-key-expiry-label"
+ options={EXPIRY_OPTIONS.map(({ value, labelKey }) => ({
+ value,
+ label: localize(labelKey),
+ }))}
+ />
+ <p className="text-xs text-text-secondary">
+ {expiresAt == null
+ ? localize('com_ui_api_key_no_expiration')
+ : localize('com_ui_api_key_expires_on', { 0: formatDate(expiresAt) })}
+ </p>
+ </div>
+ <div className="flex justify-end gap-2">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={onCancel}
+ disabled={createMutation.isLoading}
+ >
+ {localize('com_ui_cancel')}
+ </Button>
+ <Button
+ type="submit"
+ variant="submit"
+ disabled={createMutation.isLoading || !name.trim()}
+ aria-busy={createMutation.isLoading}
+ aria-label={localize('com_ui_create')}
+ >
+ {createMutation.isLoading ? <Spinner className="h-4 w-4" /> : localize('com_ui_create')}
+ </Button>
+ </div>
+ </form>
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/CreateKeyDialog.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/CreateKeyDialog.tsx
new file mode 100644
index 0000000000..fc7fe3eb0b
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/CreateKeyDialog.tsx
@@ -0,0 +1,47 @@
+import { useState } from 'react';
+import { OGDialog, OGDialogContent, OGDialogHeader, OGDialogTitle } from '@librechat/client';
+import type { TAgentApiKeyCreateResponse } from 'librechat-data-provider';
+import { useLocalize } from '~/hooks';
+import Create from './Create';
+import Reveal from './Reveal';
+
+type CreateKeyDialogProps = {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+};
+
+export default function CreateKeyDialog({ open, onOpenChange }: CreateKeyDialogProps) {
+ const localize = useLocalize();
+ const [createdKey, setCreatedKey] = useState<TAgentApiKeyCreateResponse | null>(null);
+ const [prevOpen, setPrevOpen] = useState(open);
+
+ if (open !== prevOpen) {
+ setPrevOpen(open);
+ if (open) {
+ setCreatedKey(null);
+ }
+ }
+
+ return (
+ <OGDialog open={open} onOpenChange={onOpenChange}>
+ <OGDialogContent
+ showCloseButton={false}
+ className="w-11/12 max-w-lg"
+ aria-describedby={undefined}
+ >
+ <OGDialogHeader>
+ <OGDialogTitle>
+ {createdKey != null
+ ? localize('com_ui_api_key_created')
+ : localize('com_ui_create_api_key')}
+ </OGDialogTitle>
+ </OGDialogHeader>
+ {createdKey != null ? (
+ <Reveal createdKey={createdKey} onDone={() => onOpenChange(false)} />
+ ) : (
+ <Create onCreated={setCreatedKey} onCancel={() => onOpenChange(false)} />
+ )}
+ </OGDialogContent>
+ </OGDialog>
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/DeleteKeyDialog.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/DeleteKeyDialog.tsx
new file mode 100644
index 0000000000..271cee4e21
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/DeleteKeyDialog.tsx
@@ -0,0 +1,67 @@
+import { useDeleteAgentApiKeyMutation } from 'librechat-data-provider/react-query';
+import { Spinner, OGDialog, OGDialogTemplate, useToastContext } from '@librechat/client';
+import type { RefObject } from 'react';
+import { useLocalize } from '~/hooks';
+
+type DeleteKeyDialogProps = {
+ id: string;
+ name: string;
+ keyPrefix: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ triggerRef?: RefObject<HTMLButtonElement | null>;
+};
+
+export default function DeleteKeyDialog({
+ id,
+ name,
+ keyPrefix,
+ open,
+ onOpenChange,
+ triggerRef,
+}: DeleteKeyDialogProps) {
+ const localize = useLocalize();
+ const { showToast } = useToastContext();
+ const deleteMutation = useDeleteAgentApiKeyMutation();
+
+ const handleDelete = () => {
+ deleteMutation.mutate(id, {
+ onSuccess: () => {
+ showToast({ message: localize('com_ui_api_key_deleted'), status: 'success' });
+ onOpenChange(false);
+ },
+ onError: () => {
+ showToast({ message: localize('com_ui_api_key_delete_error'), status: 'error' });
+ },
+ });
+ };
+
+ return (
+ <OGDialog open={open} onOpenChange={onOpenChange} triggerRef={triggerRef}>
+ <OGDialogTemplate
+ showCloseButton={false}
+ title={localize('com_ui_delete_api_key')}
+ className="max-w-[450px]"
+ main={
+ <div className="space-y-3 text-left">
+ <p className="text-sm text-text-primary">
+ {localize('com_ui_api_key_delete_confirm', { 0: name })}
+ </p>
+ <div className="flex items-center rounded-lg border border-border-light bg-surface-secondary px-3 py-2">
+ <code className="break-all font-mono text-xs text-text-secondary">{keyPrefix}…</code>
+ </div>
+ <p className="text-sm text-text-secondary">
+ {localize('com_ui_api_key_delete_warning')}
+ </p>
+ </div>
+ }
+ selection={{
+ selectHandler: handleDelete,
+ selectClasses:
+ 'bg-surface-destructive text-white transition-all duration-200 hover:bg-surface-destructive-hover',
+ selectText: deleteMutation.isLoading ? <Spinner /> : localize('com_ui_delete'),
+ }}
+ />
+ </OGDialog>
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/Item.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/Item.tsx
new file mode 100644
index 0000000000..ff8a5718f8
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/Item.tsx
@@ -0,0 +1,79 @@
+import { useRef, useState } from 'react';
+import { Trash2 } from 'lucide-react';
+import { Button } from '@librechat/client';
+import type { TAgentApiKeyListItem } from 'librechat-data-provider';
+import { formatDate, formatRelativeTime, getExpiryStatus } from './utils';
+import DeleteKeyDialog from './DeleteKeyDialog';
+import { useLocalize } from '~/hooks';
+
+type ItemProps = {
+ apiKey: TAgentApiKeyListItem;
+};
+
+export default function Item({ apiKey }: ItemProps) {
+ const localize = useLocalize();
+ const deleteButtonRef = useRef<HTMLButtonElement | null>(null);
+ const [deleteOpen, setDeleteOpen] = useState(false);
+
+ const status = getExpiryStatus(apiKey.expiresAt);
+
+ return (
+ <li className="hover:bg-surface-secondary/50 group flex items-start justify-between gap-3 px-4 py-3 transition-colors first:rounded-t-xl last:rounded-b-xl">
+ <div className="min-w-0 flex-1 space-y-1">
+ <div className="flex items-center gap-2">
+ <span className="truncate font-medium text-text-primary">{apiKey.name}</span>
+ {status?.state === 'expired' && (
+ <span className="shrink-0 rounded-full border border-red-500/20 bg-red-500/10 px-2 py-0.5 text-xs font-medium text-red-600 dark:text-red-400">
+ {localize('com_ui_api_key_expired')}
+ </span>
+ )}
+ {status?.state === 'expiring' && (
+ <span className="shrink-0 rounded-full border border-amber-500/20 bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-600 dark:text-amber-500">
+ {status.days === 1
+ ? localize('com_ui_api_key_expires_in_day')
+ : localize('com_ui_api_key_expires_in_days', { 0: status.days })}
+ </span>
+ )}
+ </div>
+ <div className="flex flex-wrap items-center gap-x-2 gap-y-0.5 text-xs text-text-secondary">
+ <code className="font-mono">{apiKey.keyPrefix}…</code>
+ <span aria-hidden="true" className="text-text-tertiary">
+ ·
+ </span>
+ <span>
+ {apiKey.lastUsedAt
+ ? localize('com_ui_api_key_last_used', { 0: formatRelativeTime(apiKey.lastUsedAt) })
+ : localize('com_ui_api_key_never_used')}
+ </span>
+ <span aria-hidden="true" className="text-text-tertiary">
+ ·
+ </span>
+ <span>
+ {apiKey.expiresAt
+ ? localize('com_ui_api_key_expires_on', { 0: formatDate(apiKey.expiresAt) })
+ : localize('com_ui_api_key_no_expiration')}
+ </span>
+ </div>
+ </div>
+ <Button
+ ref={deleteButtonRef}
+ variant="destructive"
+ size="icon"
+ onClick={() => setDeleteOpen(true)}
+ aria-label={localize('com_ui_api_key_delete_name', { 0: apiKey.name })}
+ aria-haspopup="dialog"
+ className="size-8 shrink-0 self-center"
+ >
+ <Trash2 className="icon-sm" aria-hidden="true" />
+ </Button>
+ <DeleteKeyDialog
+ id={apiKey.id}
+ name={apiKey.name}
+ keyPrefix={apiKey.keyPrefix}
+ open={deleteOpen}
+ onOpenChange={setDeleteOpen}
+ triggerRef={deleteButtonRef}
+ />
+ </li>
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/List.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/List.tsx
new file mode 100644
index 0000000000..28e6327b0a
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/List.tsx
@@ -0,0 +1,73 @@
+import { Plus, KeyRound } from 'lucide-react';
+import { Button, Spinner } from '@librechat/client';
+import { useGetAgentApiKeysQuery } from 'librechat-data-provider/react-query';
+import { useLocalize } from '~/hooks';
+import Item from './Item';
+
+type ListProps = {
+ onCreate: () => void;
+ headingId?: string;
+};
+
+export default function List({ onCreate, headingId }: ListProps) {
+ const localize = useLocalize();
+ const { data, isLoading, isError, isFetching, refetch } = useGetAgentApiKeysQuery();
+
+ if (isLoading) {
+ return (
+ <div
+ data-testid="api-keys-loading"
+ className="flex items-center justify-center rounded-xl border border-border-light py-12"
+ >
+ <Spinner className="h-6 w-6 text-text-secondary" />
+ </div>
+ );
+ }
+
+ if (isError && data == null) {
+ return (
+ <div className="flex flex-col items-center gap-3 rounded-xl border border-border-light px-6 py-10 text-center">
+ <p className="text-sm text-text-secondary">{localize('com_ui_api_keys_load_error')}</p>
+ <Button variant="outline" size="sm" onClick={() => refetch()} disabled={isFetching}>
+ {localize('com_ui_retry')}
+ </Button>
+ </div>
+ );
+ }
+
+ const keys = data?.keys ?? [];
+
+ if (keys.length === 0) {
+ return (
+ <div className="flex flex-col items-center gap-3 rounded-xl border border-border-light px-6 py-12 text-center">
+ <span className="flex h-12 w-12 items-center justify-center rounded-full bg-surface-secondary text-text-secondary">
+ <KeyRound className="h-5 w-5" aria-hidden="true" />
+ </span>
+ <div className="space-y-1">
+ <h3 className="text-sm font-medium text-text-primary">
+ {localize('com_ui_api_keys_empty_title')}
+ </h3>
+ <p className="mx-auto max-w-xs text-sm text-text-secondary">
+ {localize('com_ui_api_keys_empty_text')}
+ </p>
+ </div>
+ <Button size="sm" className="mt-1 gap-1.5" onClick={onCreate}>
+ <Plus className="h-4 w-4" aria-hidden="true" />
+ {localize('com_ui_create_api_key')}
+ </Button>
+ </div>
+ );
+ }
+
+ return (
+ <ul
+ className="divide-y divide-border-light overflow-hidden rounded-xl border border-border-light"
+ aria-labelledby={headingId}
+ aria-label={headingId == null ? localize('com_ui_agent_api_keys') : undefined}
+ >
+ {keys.map((apiKey) => (
+ <Item key={apiKey.id} apiKey={apiKey} />
+ ))}
+ </ul>
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/Reveal.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/Reveal.tsx
new file mode 100644
index 0000000000..f4e15cd03f
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/Reveal.tsx
@@ -0,0 +1,47 @@
+import { useState } from 'react';
+import { TriangleAlert } from 'lucide-react';
+import { Button, Label, SecretInput } from '@librechat/client';
+import type { TAgentApiKeyCreateResponse } from 'librechat-data-provider';
+import CopyButton from '~/components/Messages/Content/CopyButton';
+import { useLocalize, useCopyToClipboard } from '~/hooks';
+
+type RevealProps = {
+ createdKey: TAgentApiKeyCreateResponse;
+ onDone: () => void;
+};
+
+export default function Reveal({ createdKey, onDone }: RevealProps) {
+ const localize = useLocalize();
+ const [isCopied, setIsCopied] = useState(false);
+ const copyToClipboard = useCopyToClipboard({ text: createdKey.key });
+
+ return (
+ <div className="min-w-0 space-y-4">
+ <div className="flex gap-2.5 rounded-lg border border-amber-500/20 bg-amber-500/10 p-3">
+ <TriangleAlert
+ className="mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-500"
+ aria-hidden="true"
+ />
+ <p className="text-sm text-amber-700 dark:text-amber-300">
+ {localize('com_ui_api_key_warning')}
+ </p>
+ </div>
+ <div className="space-y-2">
+ <Label htmlFor="reveal-api-key">{localize('com_ui_your_api_key')}</Label>
+ <SecretInput
+ id="reveal-api-key"
+ readOnly
+ value={createdKey.key}
+ className="font-mono"
+ aria-label={localize('com_ui_your_api_key')}
+ copyButton={
+ <CopyButton iconOnly isCopied={isCopied} onClick={() => copyToClipboard(setIsCopied)} />
+ }
+ />
+ </div>
+ <div className="flex justify-end">
+ <Button onClick={onDone}>{localize('com_ui_done')}</Button>
+ </div>
+ </div>
+ );
+}
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/ApiKeys.spec.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/ApiKeys.spec.tsx
new file mode 100644
index 0000000000..a803448f4b
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/ApiKeys.spec.tsx
@@ -0,0 +1,99 @@
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+import {
+ useGetAgentApiKeysQuery,
+ useCreateAgentApiKeyMutation,
+ useDeleteAgentApiKeyMutation,
+} from 'librechat-data-provider/react-query';
+import { render, fireEvent, waitFor } from 'test/layout-test-utils';
+import ApiKeys from '../ApiKeys';
+
+jest.mock('librechat-data-provider/react-query', () => ({
+ ...jest.requireActual('librechat-data-provider/react-query'),
+ useGetAgentApiKeysQuery: jest.fn(),
+ useCreateAgentApiKeyMutation: jest.fn(),
+ useDeleteAgentApiKeyMutation: jest.fn(),
+}));
+
+const mockQuery = useGetAgentApiKeysQuery as jest.Mock;
+const mockCreate = useCreateAgentApiKeyMutation as jest.Mock;
+const mockDelete = useDeleteAgentApiKeyMutation as jest.Mock;
+
+const createdKey = {
+ id: 'new-1',
+ name: 'CI key',
+ key: 'lc-secret-full-key',
+ keyPrefix: 'lc-secret',
+ createdAt: '2026-06-13T00:00:00Z',
+};
+
+function openManageDialog() {
+ const utils = render(<ApiKeys />);
+ fireEvent.click(utils.getByRole('button', { name: 'Agent API Keys' }));
+ return utils;
+}
+
+describe('ApiKeys', () => {
+ beforeEach(() => {
+ mockQuery.mockReturnValue({
+ data: { keys: [] },
+ isLoading: false,
+ isError: false,
+ isFetching: false,
+ refetch: jest.fn(),
+ });
+ mockCreate.mockReturnValue({
+ mutateAsync: jest.fn().mockResolvedValue(createdKey),
+ isLoading: false,
+ });
+ mockDelete.mockReturnValue({ mutateAsync: jest.fn(), isLoading: false });
+ });
+
+ it('renders a manage trigger without opening the dialog', () => {
+ const { getByText, getByRole, queryByRole } = render(<ApiKeys />);
+ expect(getByText('Manage')).toBeInTheDocument();
+ expect(getByRole('button', { name: 'Agent API Keys' })).toBeInTheDocument();
+ expect(queryByRole('heading', { name: 'Agent API Keys' })).not.toBeInTheDocument();
+ });
+
+ it('opens the management dialog with the empty state', () => {
+ const { getByText } = openManageDialog();
+ expect(getByText('Connect your agents to external apps')).toBeInTheDocument();
+ });
+
+ it('opens the create dialog from within the management dialog', () => {
+ const { getAllByRole, getByRole } = openManageDialog();
+ fireEvent.click(getAllByRole('button', { name: 'Create API Key' })[0]);
+ expect(getByRole('heading', { name: 'Create API Key' })).toBeInTheDocument();
+ });
+
+ it('walks through create -> reveal -> close', async () => {
+ const { getAllByRole, getByRole, getByLabelText, getByDisplayValue, queryByRole } =
+ openManageDialog();
+ fireEvent.click(getAllByRole('button', { name: 'Create API Key' })[0]);
+
+ fireEvent.change(getByLabelText('Key Name'), { target: { value: 'CI key' } });
+ fireEvent.click(getByRole('button', { name: 'Create' }));
+
+ await waitFor(() =>
+ expect(getByRole('heading', { name: 'API key created successfully' })).toBeInTheDocument(),
+ );
+ expect(getByDisplayValue('lc-secret-full-key')).toBeInTheDocument();
+
+ fireEvent.click(getByRole('button', { name: 'Done' }));
+ await waitFor(() =>
+ expect(
+ queryByRole('heading', { name: 'API key created successfully' }),
+ ).not.toBeInTheDocument(),
+ );
+ });
+
+ it('closes the create dialog on cancel without creating a key', () => {
+ const mutateAsync = jest.fn();
+ mockCreate.mockReturnValue({ mutateAsync, isLoading: false });
+ const { getAllByRole, getByRole } = openManageDialog();
+ fireEvent.click(getAllByRole('button', { name: 'Create API Key' })[0]);
+ fireEvent.click(getByRole('button', { name: 'Cancel' }));
+ expect(mutateAsync).not.toHaveBeenCalled();
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Create.spec.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Create.spec.tsx
new file mode 100644
index 0000000000..15a7682785
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Create.spec.tsx
@@ -0,0 +1,87 @@
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+import { useCreateAgentApiKeyMutation } from 'librechat-data-provider/react-query';
+import { render, fireEvent, waitFor } from 'test/layout-test-utils';
+import Create from '../Create';
+
+jest.mock('librechat-data-provider/react-query', () => ({
+ ...jest.requireActual('librechat-data-provider/react-query'),
+ useCreateAgentApiKeyMutation: jest.fn(),
+}));
+
+const mockCreate = useCreateAgentApiKeyMutation as jest.Mock;
+
+const createdKey = {
+ id: 'new-1',
+ name: 'CI key',
+ key: 'lc-secret-full-key',
+ keyPrefix: 'lc-secret',
+ createdAt: '2026-06-13T00:00:00Z',
+};
+
+describe('Create', () => {
+ let mutateAsync: jest.Mock;
+
+ beforeEach(() => {
+ mutateAsync = jest.fn().mockResolvedValue(createdKey);
+ mockCreate.mockReturnValue({ mutateAsync, isLoading: false });
+ });
+
+ it('keeps Create disabled until a non-empty name is entered', () => {
+ const { getByRole, getByLabelText } = render(
+ <Create onCreated={jest.fn()} onCancel={jest.fn()} />,
+ );
+ expect(getByRole('button', { name: 'Create' })).toBeDisabled();
+
+ fireEvent.change(getByLabelText('Key Name'), { target: { value: ' ' } });
+ expect(getByRole('button', { name: 'Create' })).toBeDisabled();
+
+ fireEvent.change(getByLabelText('Key Name'), { target: { value: 'CI key' } });
+ expect(getByRole('button', { name: 'Create' })).toBeEnabled();
+ expect(mutateAsync).not.toHaveBeenCalled();
+ });
+
+ it('submits the trimmed name with the default 30-day expiration', async () => {
+ const onCreated = jest.fn();
+ const { getByRole, getByLabelText } = render(
+ <Create onCreated={onCreated} onCancel={jest.fn()} />,
+ );
+
+ fireEvent.change(getByLabelText('Key Name'), { target: { value: ' CI key ' } });
+ fireEvent.click(getByRole('button', { name: 'Create' }));
+
+ await waitFor(() => expect(onCreated).toHaveBeenCalledWith(createdKey));
+
+ const payload = mutateAsync.mock.calls[0][0];
+ expect(payload.name).toBe('CI key');
+ const diffDays = (new Date(payload.expiresAt).getTime() - Date.now()) / 86400000;
+ expect(diffDays).toBeGreaterThan(29.9);
+ expect(diffDays).toBeLessThanOrEqual(30.1);
+ });
+
+ it('calls onCancel from the cancel button', () => {
+ const onCancel = jest.fn();
+ const { getByRole } = render(<Create onCreated={jest.fn()} onCancel={onCancel} />);
+ fireEvent.click(getByRole('button', { name: 'Cancel' }));
+ expect(onCancel).toHaveBeenCalledTimes(1);
+ });
+
+ it('does not call onCreated when creation fails', async () => {
+ mutateAsync.mockRejectedValue(new Error('boom'));
+ const onCreated = jest.fn();
+ const { getByRole, getByLabelText } = render(
+ <Create onCreated={onCreated} onCancel={jest.fn()} />,
+ );
+ fireEvent.change(getByLabelText('Key Name'), { target: { value: 'CI key' } });
+ fireEvent.click(getByRole('button', { name: 'Create' }));
+ await waitFor(() => expect(mutateAsync).toHaveBeenCalled());
+ expect(onCreated).not.toHaveBeenCalled();
+ });
+
+ it('disables actions while creating', () => {
+ mockCreate.mockReturnValue({ mutateAsync, isLoading: true });
+ const { getByRole } = render(<Create onCreated={jest.fn()} onCancel={jest.fn()} />);
+ expect(getByRole('button', { name: 'Create' })).toBeDisabled();
+ expect(getByRole('button', { name: 'Cancel' })).toBeDisabled();
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/CreateKeyDialog.spec.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/CreateKeyDialog.spec.tsx
new file mode 100644
index 0000000000..9c30c06e30
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/CreateKeyDialog.spec.tsx
@@ -0,0 +1,61 @@
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+import { useCreateAgentApiKeyMutation } from 'librechat-data-provider/react-query';
+import { render, fireEvent, waitFor } from 'test/layout-test-utils';
+import CreateKeyDialog from '../CreateKeyDialog';
+
+jest.mock('librechat-data-provider/react-query', () => ({
+ ...jest.requireActual('librechat-data-provider/react-query'),
+ useCreateAgentApiKeyMutation: jest.fn(),
+}));
+
+const mockCreate = useCreateAgentApiKeyMutation as jest.Mock;
+
+const createdKey = {
+ id: 'new-1',
+ name: 'CI key',
+ key: 'lc-secret-full-key',
+ keyPrefix: 'lc-secret',
+ createdAt: '2026-06-13T00:00:00Z',
+};
+
+describe('CreateKeyDialog', () => {
+ let mutateAsync: jest.Mock;
+
+ beforeEach(() => {
+ mutateAsync = jest.fn().mockResolvedValue(createdKey);
+ mockCreate.mockReturnValue({ mutateAsync, isLoading: false });
+ });
+
+ it('renders nothing when closed', () => {
+ const { queryByRole } = render(<CreateKeyDialog open={false} onOpenChange={jest.fn()} />);
+ expect(queryByRole('heading', { name: 'Create API Key' })).not.toBeInTheDocument();
+ });
+
+ it('creates a key, reveals it, and closes on done', async () => {
+ const onOpenChange = jest.fn();
+ const { getByRole, getByLabelText, getByDisplayValue } = render(
+ <CreateKeyDialog open onOpenChange={onOpenChange} />,
+ );
+
+ expect(getByRole('heading', { name: 'Create API Key' })).toBeInTheDocument();
+
+ fireEvent.change(getByLabelText('Key Name'), { target: { value: 'CI key' } });
+ fireEvent.click(getByRole('button', { name: 'Create' }));
+
+ await waitFor(() =>
+ expect(getByRole('heading', { name: 'API key created successfully' })).toBeInTheDocument(),
+ );
+ expect(getByDisplayValue('lc-secret-full-key')).toBeInTheDocument();
+
+ fireEvent.click(getByRole('button', { name: 'Done' }));
+ expect(onOpenChange).toHaveBeenCalledWith(false);
+ });
+
+ it('cancels without creating', () => {
+ const onOpenChange = jest.fn();
+ const { getByRole } = render(<CreateKeyDialog open onOpenChange={onOpenChange} />);
+ fireEvent.click(getByRole('button', { name: 'Cancel' }));
+ expect(onOpenChange).toHaveBeenCalledWith(false);
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/DeleteKeyDialog.spec.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/DeleteKeyDialog.spec.tsx
new file mode 100644
index 0000000000..63dfb28022
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/DeleteKeyDialog.spec.tsx
@@ -0,0 +1,56 @@
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+import { useDeleteAgentApiKeyMutation } from 'librechat-data-provider/react-query';
+import { render, fireEvent, waitFor } from 'test/layout-test-utils';
+import DeleteKeyDialog from '../DeleteKeyDialog';
+
+jest.mock('librechat-data-provider/react-query', () => ({
+ ...jest.requireActual('librechat-data-provider/react-query'),
+ useDeleteAgentApiKeyMutation: jest.fn(),
+}));
+
+const mockDelete = useDeleteAgentApiKeyMutation as jest.Mock;
+
+describe('DeleteKeyDialog', () => {
+ let mutate: jest.Mock;
+
+ beforeEach(() => {
+ mutate = jest.fn();
+ mockDelete.mockReturnValue({ mutate, isLoading: false });
+ });
+
+ it('renders nothing actionable while closed', () => {
+ const { queryByText } = render(
+ <DeleteKeyDialog
+ id="key-1"
+ name="CI Pipeline"
+ keyPrefix="lc-abc123"
+ open={false}
+ onOpenChange={jest.fn()}
+ />,
+ );
+ expect(queryByText(/This action cannot be undone/)).not.toBeInTheDocument();
+ expect(mutate).not.toHaveBeenCalled();
+ });
+
+ it('shows the key details and deletes on confirm', async () => {
+ mutate.mockImplementation((id, opts) => opts?.onSuccess?.());
+ const onOpenChange = jest.fn();
+ const { getByRole, getByText } = render(
+ <DeleteKeyDialog
+ id="key-1"
+ name="CI Pipeline"
+ keyPrefix="lc-abc123"
+ open
+ onOpenChange={onOpenChange}
+ />,
+ );
+
+ expect(getByText(/This action cannot be undone/)).toBeInTheDocument();
+ expect(getByText(/lc-abc123/)).toBeInTheDocument();
+
+ fireEvent.click(getByRole('button', { name: 'Delete' }));
+ await waitFor(() => expect(mutate).toHaveBeenCalledWith('key-1', expect.any(Object)));
+ expect(onOpenChange).toHaveBeenCalledWith(false);
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Item.spec.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Item.spec.tsx
new file mode 100644
index 0000000000..af7bcf63b3
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Item.spec.tsx
@@ -0,0 +1,68 @@
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+import { useDeleteAgentApiKeyMutation } from 'librechat-data-provider/react-query';
+import type { TAgentApiKeyListItem } from 'librechat-data-provider';
+import { render, fireEvent } from 'test/layout-test-utils';
+import Item from '../Item';
+
+jest.mock('librechat-data-provider/react-query', () => ({
+ ...jest.requireActual('librechat-data-provider/react-query'),
+ useDeleteAgentApiKeyMutation: jest.fn(),
+}));
+
+const mockDelete = useDeleteAgentApiKeyMutation as jest.Mock;
+
+const baseKey: TAgentApiKeyListItem = {
+ id: 'key-1',
+ name: 'CI Pipeline',
+ keyPrefix: 'lc-abc123',
+ createdAt: '2026-06-01T00:00:00Z',
+};
+
+function renderItem(apiKey = baseKey) {
+ return render(
+ <ul>
+ <Item apiKey={apiKey} />
+ </ul>,
+ );
+}
+
+beforeEach(() => {
+ mockDelete.mockReturnValue({ mutate: jest.fn(), isLoading: false });
+});
+
+describe('Item', () => {
+ it('renders the name, prefix, and readable metadata', () => {
+ const { getByText } = renderItem();
+ expect(getByText('CI Pipeline')).toBeInTheDocument();
+ expect(getByText(/lc-abc123/)).toBeInTheDocument();
+ expect(getByText(/Never used/)).toBeInTheDocument();
+ expect(getByText(/No expiration/)).toBeInTheDocument();
+ });
+
+ it('shows the expiring badge within 14 days', () => {
+ const expiresAt = new Date(Date.now() + 5 * 86400000).toISOString();
+ const { getByText } = renderItem({ ...baseKey, expiresAt });
+ expect(getByText(/Expires in \d+ days/)).toBeInTheDocument();
+ });
+
+ it('uses the singular badge at exactly 1 day', () => {
+ const expiresAt = new Date(Date.now() + 12 * 3600000).toISOString();
+ const { getByText } = renderItem({ ...baseKey, expiresAt });
+ expect(getByText('Expires in 1 day')).toBeInTheDocument();
+ });
+
+ it('shows the expired badge for past expiry', () => {
+ const { getByText } = renderItem({ ...baseKey, expiresAt: '2020-01-01T00:00:00Z' });
+ expect(getByText('Expired')).toBeInTheDocument();
+ });
+
+ it('exposes a labelled delete button that opens the delete dialog', async () => {
+ const { getByRole, findByText } = renderItem();
+ const deleteButton = getByRole('button', { name: 'Delete API key CI Pipeline' });
+ expect(deleteButton).toBeInTheDocument();
+
+ fireEvent.click(deleteButton);
+ expect(await findByText(/This action cannot be undone/)).toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/List.spec.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/List.spec.tsx
new file mode 100644
index 0000000000..9f51af29ba
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/List.spec.tsx
@@ -0,0 +1,102 @@
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+import {
+ useGetAgentApiKeysQuery,
+ useDeleteAgentApiKeyMutation,
+} from 'librechat-data-provider/react-query';
+import { render, fireEvent } from 'test/layout-test-utils';
+import List from '../List';
+
+jest.mock('librechat-data-provider/react-query', () => ({
+ ...jest.requireActual('librechat-data-provider/react-query'),
+ useGetAgentApiKeysQuery: jest.fn(),
+ useDeleteAgentApiKeyMutation: jest.fn(),
+}));
+
+const mockQuery = useGetAgentApiKeysQuery as jest.Mock;
+const mockDelete = useDeleteAgentApiKeyMutation as jest.Mock;
+
+function renderList(props: Partial<React.ComponentProps<typeof List>> = {}) {
+ return render(<List onCreate={jest.fn()} {...props} />);
+}
+
+describe('List', () => {
+ beforeEach(() => {
+ mockDelete.mockReturnValue({ mutateAsync: jest.fn(), isLoading: false });
+ mockQuery.mockReturnValue({
+ data: { keys: [] },
+ isLoading: false,
+ isError: false,
+ isFetching: false,
+ refetch: jest.fn(),
+ });
+ });
+
+ it('shows a loading indicator', () => {
+ mockQuery.mockReturnValue({
+ data: undefined,
+ isLoading: true,
+ isError: false,
+ refetch: jest.fn(),
+ });
+ const { getByTestId } = renderList();
+ expect(getByTestId('api-keys-loading')).toBeInTheDocument();
+ });
+
+ it('shows the error state and retries', () => {
+ const refetch = jest.fn();
+ mockQuery.mockReturnValue({
+ data: undefined,
+ isLoading: false,
+ isError: true,
+ isFetching: false,
+ refetch,
+ });
+ const { getByText, getByRole } = renderList();
+ expect(getByText('Failed to load API keys')).toBeInTheDocument();
+ fireEvent.click(getByRole('button', { name: 'Retry' }));
+ expect(refetch).toHaveBeenCalled();
+ });
+
+ it('shows the onboarding empty state with a create CTA', () => {
+ const onCreate = jest.fn();
+ const { getByText, getByRole } = renderList({ onCreate });
+ expect(getByText('Connect your agents to external apps')).toBeInTheDocument();
+ fireEvent.click(getByRole('button', { name: 'Create API Key' }));
+ expect(onCreate).toHaveBeenCalled();
+ });
+
+ it('renders a semantic list of keys', () => {
+ mockQuery.mockReturnValue({
+ data: {
+ keys: [
+ { id: '1', name: 'Alpha', keyPrefix: 'lc-aaa', createdAt: '2026-01-01T00:00:00Z' },
+ { id: '2', name: 'Beta', keyPrefix: 'lc-bbb', createdAt: '2026-02-01T00:00:00Z' },
+ ],
+ },
+ isLoading: false,
+ isError: false,
+ isFetching: false,
+ refetch: jest.fn(),
+ });
+ const { getByRole, getByText } = renderList();
+ expect(getByRole('list', { name: 'Agent API Keys' })).toBeInTheDocument();
+ expect(getByText('Alpha')).toBeInTheDocument();
+ expect(getByText('Beta')).toBeInTheDocument();
+ });
+
+ it('keeps showing cached keys when a background refetch fails', () => {
+ mockQuery.mockReturnValue({
+ data: {
+ keys: [{ id: '1', name: 'Alpha', keyPrefix: 'lc-aaa', createdAt: '2026-01-01T00:00:00Z' }],
+ },
+ isLoading: false,
+ isError: true,
+ isFetching: false,
+ refetch: jest.fn(),
+ });
+ const { getByText, queryByText } = renderList();
+ expect(getByText('Alpha')).toBeInTheDocument();
+ expect(queryByText('Failed to load API keys')).not.toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Reveal.spec.tsx b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Reveal.spec.tsx
new file mode 100644
index 0000000000..5577280703
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Reveal.spec.tsx
@@ -0,0 +1,45 @@
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+import { render, fireEvent } from 'test/layout-test-utils';
+import Reveal from '../Reveal';
+
+const createdKey = {
+ id: 'new-1',
+ name: 'CI key',
+ key: 'lc-secret-full-key',
+ keyPrefix: 'lc-secret',
+ createdAt: '2026-06-13T00:00:00Z',
+};
+
+describe('Reveal', () => {
+ it('shows the one-time warning and the key value', () => {
+ const { getByText, getByDisplayValue } = render(
+ <Reveal createdKey={createdKey} onDone={jest.fn()} />,
+ );
+ expect(getByText(/You won't be able to see it again/)).toBeInTheDocument();
+ expect(getByDisplayValue('lc-secret-full-key')).toBeInTheDocument();
+ });
+
+ it('hides the key by default behind a password field', () => {
+ const { getByDisplayValue } = render(<Reveal createdKey={createdKey} onDone={jest.fn()} />);
+ expect(getByDisplayValue('lc-secret-full-key')).toHaveAttribute('type', 'password');
+ });
+
+ it('calls onDone', () => {
+ const onDone = jest.fn();
+ const { getByRole } = render(<Reveal createdKey={createdKey} onDone={onDone} />);
+ fireEvent.click(getByRole('button', { name: 'Done' }));
+ expect(onDone).toHaveBeenCalled();
+ });
+
+ it('renders the standardized copy control inside the input', () => {
+ const { getByRole } = render(<Reveal createdKey={createdKey} onDone={jest.fn()} />);
+ expect(getByRole('button', { name: 'Copy' })).toBeInTheDocument();
+ });
+
+ it('shows copied feedback after clicking copy', async () => {
+ const { getByRole, findByRole } = render(<Reveal createdKey={createdKey} onDone={jest.fn()} />);
+ fireEvent.click(getByRole('button', { name: 'Copy' }));
+ expect(await findByRole('button', { name: /Copied/ })).toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/utils.spec.ts b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/utils.spec.ts
new file mode 100644
index 0000000000..f41cdb0015
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/utils.spec.ts
@@ -0,0 +1,61 @@
+import {
+ computeExpiresAt,
+ getExpiryStatus,
+ formatDate,
+ EXPIRY_NEVER,
+ DEFAULT_EXPIRY,
+} from '../utils';
+
+describe('computeExpiresAt', () => {
+ it('returns null for the never option', () => {
+ expect(computeExpiresAt(EXPIRY_NEVER)).toBeNull();
+ });
+
+ it('returns an ISO date the given number of days ahead', () => {
+ const result = computeExpiresAt('7');
+ expect(result).not.toBeNull();
+ const diffDays = (new Date(result as string).getTime() - Date.now()) / 86400000;
+ expect(diffDays).toBeGreaterThan(6.9);
+ expect(diffDays).toBeLessThanOrEqual(7.1);
+ });
+
+ it('returns null for non-numeric input', () => {
+ expect(computeExpiresAt('abc')).toBeNull();
+ });
+});
+
+describe('getExpiryStatus', () => {
+ const now = new Date('2026-06-13T12:00:00Z');
+
+ it('returns null when there is no expiration', () => {
+ expect(getExpiryStatus(undefined, now)).toBeNull();
+ });
+
+ it('returns null when expiration is more than 14 days away', () => {
+ expect(getExpiryStatus('2026-12-01T00:00:00Z', now)).toBeNull();
+ });
+
+ it('returns expiring with day count within 14 days', () => {
+ expect(getExpiryStatus('2026-06-18T12:00:00Z', now)).toEqual({ state: 'expiring', days: 5 });
+ });
+
+ it('returns expired for past dates', () => {
+ expect(getExpiryStatus('2026-06-01T00:00:00Z', now)).toEqual({ state: 'expired' });
+ });
+});
+
+describe('formatDate', () => {
+ it('formats a valid ISO date', () => {
+ expect(formatDate('2026-06-01T00:00:00Z')).toContain('2026');
+ });
+
+ it('returns an empty string for invalid input', () => {
+ expect(formatDate('garbage')).toBe('');
+ });
+});
+
+describe('DEFAULT_EXPIRY', () => {
+ it('is 30 days', () => {
+ expect(DEFAULT_EXPIRY).toBe('30');
+ });
+});
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/index.ts b/client/src/components/Nav/SettingsTabs/ApiKeys/index.ts
new file mode 100644
index 0000000000..176b46e5da
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/index.ts
@@ -0,0 +1 @@
+export { default } from './ApiKeys';
diff --git a/client/src/components/Nav/SettingsTabs/ApiKeys/utils.ts b/client/src/components/Nav/SettingsTabs/ApiKeys/utils.ts
new file mode 100644
index 0000000000..5b96aad32a
--- /dev/null
+++ b/client/src/components/Nav/SettingsTabs/ApiKeys/utils.ts
@@ -0,0 +1,65 @@
+import { formatDistanceToNow } from 'date-fns';
+
+import type { TranslationKeys } from '~/hooks';
+
+export const EXPIRY_NEVER = 'never';
+export const DEFAULT_EXPIRY = '30';
+
+export const EXPIRY_OPTIONS: { value: string; labelKey: TranslationKeys }[] = [
+ { value: '7', labelKey: 'com_ui_api_key_expire_7d' },
+ { value: '30', labelKey: 'com_ui_api_key_expire_30d' },
+ { value: '90', labelKey: 'com_ui_api_key_expire_90d' },
+ { value: '365', labelKey: 'com_ui_api_key_expire_1y' },
+ { value: EXPIRY_NEVER, labelKey: 'com_ui_api_key_expire_never' },
+];
+
+const MS_PER_DAY = 86400000;
+const EXPIRING_THRESHOLD_DAYS = 14;
+
+export function computeExpiresAt(option: string): string | null {
+ if (option === EXPIRY_NEVER) {
+ return null;
+ }
+ const days = Number(option);
+ if (!Number.isFinite(days) || days <= 0) {
+ return null;
+ }
+ return new Date(Date.now() + days * MS_PER_DAY).toISOString();
+}
+
+export function formatDate(dateStr: string): string {
+ const date = new Date(dateStr);
+ if (isNaN(date.getTime())) {
+ return '';
+ }
+ return date.toLocaleDateString(undefined, {
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric',
+ });
+}
+
+export function formatRelativeTime(dateStr: string): string {
+ const date = new Date(dateStr);
+ if (isNaN(date.getTime())) {
+ return '';
+ }
+ return formatDistanceToNow(date, { addSuffix: true });
+}
+
+export type ExpiryStatus = { state: 'expired' } | { state: 'expiring'; days: number } | null;
+
+export function getExpiryStatus(expiresAt?: string, now: Date = new Date()): ExpiryStatus {
+ if (!expiresAt) {
+ return null;
+ }
+ const diffMs = new Date(expiresAt).getTime() - now.getTime();
+ if (diffMs <= 0) {
+ return { state: 'expired' };
+ }
+ const days = Math.ceil(diffMs / MS_PER_DAY);
+ if (days <= EXPIRING_THRESHOLD_DAYS) {
+ return { state: 'expiring', days };
+ }
+ return null;
+}
diff --git a/client/src/components/Nav/SettingsTabs/Data/AgentApiKeys.tsx b/client/src/components/Nav/SettingsTabs/Data/AgentApiKeys.tsx
deleted file mode 100644
index 379d9b7356..0000000000
--- a/client/src/components/Nav/SettingsTabs/Data/AgentApiKeys.tsx
+++ /dev/null
@@ -1,340 +0,0 @@
-import React, { useState } from 'react';
-import {
- useGetAgentApiKeysQuery,
- useCreateAgentApiKeyMutation,
- useDeleteAgentApiKeyMutation,
-} from 'librechat-data-provider/react-query';
-import { Permissions, PermissionTypes } from 'librechat-data-provider';
-import { Plus, Trash2, Key, ShieldEllipsis } from 'lucide-react';
-import {
- Button,
- Input,
- Label,
- Spinner,
- SecretInput,
- OGDialog,
- OGDialogClose,
- OGDialogTitle,
- OGDialogHeader,
- OGDialogContent,
- OGDialogTrigger,
- useToastContext,
-} from '@librechat/client';
-import type { PermissionConfig } from '~/components/ui';
-import { useUpdateRemoteAgentsPermissionsMutation } from '~/data-provider';
-import { useLocalize } from '~/hooks';
-import { AdminSettingsDialog } from '~/components/ui';
-
-function CreateKeyDialog({ onKeyCreated }: { onKeyCreated?: () => void }) {
- const localize = useLocalize();
- const { showToast } = useToastContext();
- const [open, setOpen] = useState(false);
- const [name, setName] = useState('');
- const [newKey, setNewKey] = useState<string | null>(null);
- const createMutation = useCreateAgentApiKeyMutation();
-
- const handleCreate = async () => {
- if (!name.trim()) {
- showToast({ message: localize('com_ui_api_key_name_required'), status: 'error' });
- return;
- }
-
- try {
- const result = await createMutation.mutateAsync({ name: name.trim() });
- setNewKey(result.key);
- showToast({ message: localize('com_ui_api_key_created'), status: 'success' });
- onKeyCreated?.();
- } catch {
- showToast({ message: localize('com_ui_api_key_create_error'), status: 'error' });
- }
- };
-
- const handleClose = () => {
- setName('');
- setNewKey(null);
- setOpen(false);
- };
-
- const handleCopy = () => {
- showToast({ message: localize('com_ui_api_key_copied'), status: 'success' });
- };
-
- return (
- <OGDialog open={open} onOpenChange={setOpen}>
- <OGDialogTrigger asChild>
- <Button variant="outline" size="sm" className="gap-2">
- <Plus className="h-4 w-4" />
- {localize('com_ui_create_api_key')}
- </Button>
- </OGDialogTrigger>
- <OGDialogContent className="max-w-md">
- <OGDialogTitle>{localize('com_ui_create_api_key')}</OGDialogTitle>
- <div className="space-y-4 py-4">
- {!newKey ? (
- <>
- <div className="space-y-2">
- <Label htmlFor="key-name">{localize('com_ui_api_key_name')}</Label>
- <Input
- id="key-name"
- value={name}
- onChange={(e) => setName(e.target.value)}
- placeholder={localize('com_ui_api_key_name_placeholder')}
- />
- </div>
- <div className="flex justify-end gap-2">
- <OGDialogClose asChild>
- <Button variant="outline" onClick={handleClose}>
- {localize('com_ui_cancel')}
- </Button>
- </OGDialogClose>
- <Button onClick={handleCreate} disabled={createMutation.isLoading}>
- {createMutation.isLoading ? (
- <Spinner className="h-4 w-4" />
- ) : (
- localize('com_ui_create')
- )}
- </Button>
- </div>
- </>
- ) : (
- <>
- <div className="rounded-lg border border-yellow-500/50 bg-yellow-50 p-4 dark:bg-yellow-900/20">
- <p className="text-sm text-yellow-800 dark:text-yellow-200">
- {localize('com_ui_api_key_warning')}
- </p>
- </div>
- <div className="space-y-2">
- <Label>{localize('com_ui_your_api_key')}</Label>
- <SecretInput
- value={newKey}
- readOnly
- showCopy
- controlsOnHover
- onCopy={handleCopy}
- aria-label={localize('com_ui_your_api_key')}
- className="font-mono text-sm"
- />
- </div>
- <div className="flex justify-end">
- <Button onClick={handleClose}>{localize('com_ui_done')}</Button>
- </div>
- </>
- )}
- </div>
- </OGDialogContent>
- </OGDialog>
- );
-}
-
-function KeyItem({
- id,
- name,
- keyPrefix,
- createdAt,
- lastUsedAt,
-}: {
- id: string;
- name: string;
- keyPrefix: string;
- createdAt: string;
- lastUsedAt?: string;
-}) {
- const localize = useLocalize();
- const { showToast } = useToastContext();
- const [confirmDelete, setConfirmDelete] = useState(false);
- const deleteMutation = useDeleteAgentApiKeyMutation();
-
- const handleDelete = async () => {
- try {
- await deleteMutation.mutateAsync(id);
- showToast({ message: localize('com_ui_api_key_deleted'), status: 'success' });
- } catch {
- showToast({ message: localize('com_ui_api_key_delete_error'), status: 'error' });
- }
- setConfirmDelete(false);
- };
-
- const formatDate = (dateStr: string) => {
- return new Date(dateStr).toLocaleDateString(undefined, {
- year: 'numeric',
- month: 'short',
- day: 'numeric',
- });
- };
-
- return (
- <div className="flex items-center justify-between rounded-lg border border-border-light p-3">
- <div className="flex items-center gap-3">
- <Key className="h-5 w-5 text-text-secondary" />
- <div>
- <div className="font-medium">{name}</div>
- <div className="text-sm text-text-secondary">
- <span className="font-mono">{keyPrefix}...</span>
- <span className="mx-2">•</span>
- <span>
- {localize('com_ui_created')} {formatDate(createdAt)}
- </span>
- {lastUsedAt && (
- <>
- <span className="mx-2">•</span>
- <span>
- {localize('com_ui_last_used')} {formatDate(lastUsedAt)}
- </span>
- </>
- )}
- </div>
- </div>
- </div>
- <div>
- {confirmDelete ? (
- <div className="flex gap-2">
- <Button variant="outline" size="sm" onClick={() => setConfirmDelete(false)}>
- {localize('com_ui_cancel')}
- </Button>
- <Button
- variant="destructive"
- size="sm"
- onClick={handleDelete}
- disabled={deleteMutation.isLoading}
- >
- {deleteMutation.isLoading ? (
- <Spinner className="h-4 w-4" />
- ) : (
- localize('com_ui_delete')
- )}
- </Button>
- </div>
- ) : (
- <Button
- variant="ghost"
- size="icon"
- onClick={() => setConfirmDelete(true)}
- title={localize('com_ui_delete')}
- >
- <Trash2 className="h-4 w-4 text-text-secondary hover:text-red-500" />
- </Button>
- )}
- </div>
- </div>
- );
-}
-
-function ApiKeysContent({ isOpen }: { isOpen: boolean }) {
- const localize = useLocalize();
- const { data, isLoading, error } = useGetAgentApiKeysQuery({ enabled: isOpen });
-
- if (error) {
- return <div className="text-sm text-red-500">{localize('com_ui_api_keys_load_error')}</div>;
- }
-
- return (
- <div className="space-y-4">
- <div className="flex items-center justify-end gap-2">
- <RemoteAgentsAdminSettings />
- <CreateKeyDialog />
- </div>
-
- <div className="max-h-[400px] space-y-2 overflow-y-auto">
- {isLoading && (
- <div className="flex items-center justify-center py-8">
- <Spinner className="h-6 w-6" />
- </div>
- )}
- {!isLoading &&
- data?.keys &&
- data.keys.length > 0 &&
- data.keys.map((key) => (
- <KeyItem
- key={key.id}
- id={key.id}
- name={key.name}
- keyPrefix={key.keyPrefix}
- createdAt={key.createdAt}
- lastUsedAt={key.lastUsedAt}
- />
- ))}
- {!isLoading && (!data?.keys || data.keys.length === 0) && (
- <div className="rounded-lg border-2 border-dashed border-border-light p-8 text-center">
- <Key className="mx-auto h-8 w-8 text-text-secondary" />
- <p className="mt-2 text-sm text-text-secondary">{localize('com_ui_no_api_keys')}</p>
- </div>
- )}
- </div>
- </div>
- );
-}
-
-const remoteAgentsPermissions: PermissionConfig[] = [
- { permission: Permissions.USE, labelKey: 'com_ui_remote_agents_allow_use' },
- { permission: Permissions.CREATE, labelKey: 'com_ui_remote_agents_allow_create' },
- { permission: Permissions.SHARE, labelKey: 'com_ui_remote_agents_allow_share' },
- { permission: Permissions.SHARE_PUBLIC, labelKey: 'com_ui_remote_agents_allow_share_public' },
-];
-
-function RemoteAgentsAdminSettings() {
- const localize = useLocalize();
- const { showToast } = useToastContext();
-
- const mutation = useUpdateRemoteAgentsPermissionsMutation({
- onSuccess: () => {
- showToast({ status: 'success', message: localize('com_ui_saved') });
- },
- onError: () => {
- showToast({ status: 'error', message: localize('com_ui_error_save_admin_settings') });
- },
- });
-
- const trigger = (
- <Button
- variant="ghost"
- size="icon"
- className="h-8 w-8"
- aria-label={localize('com_ui_admin_settings')}
- >
- <ShieldEllipsis className="h-5 w-5" aria-hidden="true" />
- </Button>
- );
-
- return (
- <AdminSettingsDialog
- permissionType={PermissionTypes.REMOTE_AGENTS}
- sectionKey="com_ui_remote_agents"
- permissions={remoteAgentsPermissions}
- menuId="remote-agents-role-dropdown"
- mutation={mutation}
- trigger={trigger}
- />
- );
-}
-
-export function AgentApiKeys() {
- const localize = useLocalize();
- const [isOpen, setIsOpen] = useState(false);
-
- return (
- <div className="flex items-center justify-between">
- <Label id="api-keys-label">{localize('com_ui_agent_api_keys')}</Label>
-
- <OGDialog open={isOpen} onOpenChange={setIsOpen}>
- <OGDialogTrigger asChild>
- <Button aria-labelledby="api-keys-label" variant="outline">
- {localize('com_ui_manage')}
- </Button>
- </OGDialogTrigger>
-
- <OGDialogContent
- title={localize('com_ui_agent_api_keys')}
- className="w-11/12 max-w-2xl bg-background text-text-primary shadow-2xl"
- >
- <OGDialogHeader>
- <OGDialogTitle>{localize('com_ui_agent_api_keys')}</OGDialogTitle>
- <p className="text-sm text-text-secondary">
- {localize('com_ui_agent_api_keys_description')}
- </p>
- </OGDialogHeader>
- <ApiKeysContent isOpen={isOpen} />
- </OGDialogContent>
- </OGDialog>
- </div>
- );
-}
diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json
index 072f54123c..92e7596606 100644
--- a/client/src/locales/en/translation.json
+++ b/client/src/locales/en/translation.json
@@ -672,13 +672,13 @@
"com_ui_additional_details": "Additional Details",
"com_ui_admin": "Admin",
"com_ui_admin_access_warning": "Disabling Admin access to this feature may cause unexpected UI issues requiring refresh. If saved, the only way to revert is via the interface setting in librechat.yaml config which affects all roles.",
+ "com_ui_admin_panel": "Admin Panel",
"com_ui_admin_settings": "Admin Settings",
"com_ui_admin_settings_section": "Admin Settings - {{section}}",
"com_ui_advanced": "Advanced",
"com_ui_advanced_settings": "Advanced Settings",
"com_ui_agent": "Agent",
"com_ui_agent_api_keys": "Agent API Keys",
- "com_ui_agent_api_keys_description": "Create API keys to access agents remotely via the API",
"com_ui_agent_category_aftersales": "After Sales",
"com_ui_agent_category_finance": "Finance",
"com_ui_agent_category_general": "General",
@@ -747,15 +747,33 @@
"com_ui_analyzing": "Analyzing",
"com_ui_analyzing_finished": "Finished analyzing",
"com_ui_api_key": "API Key",
- "com_ui_api_key_copied": "API key copied to clipboard",
"com_ui_api_key_create_error": "Failed to create API key",
"com_ui_api_key_created": "API key created successfully",
+ "com_ui_api_key_delete_confirm": "Delete \"{{0}}\"? This action cannot be undone.",
"com_ui_api_key_delete_error": "Failed to delete API key",
+ "com_ui_api_key_delete_name": "Delete API key {{0}}",
+ "com_ui_api_key_delete_warning": "Applications using this key will immediately lose access.",
"com_ui_api_key_deleted": "API key deleted successfully",
+ "com_ui_api_key_expiration": "Expiration",
+ "com_ui_api_key_expire_1y": "1 year",
+ "com_ui_api_key_expire_30d": "30 days",
+ "com_ui_api_key_expire_7d": "7 days",
+ "com_ui_api_key_expire_90d": "90 days",
+ "com_ui_api_key_expire_never": "Never",
+ "com_ui_api_key_expired": "Expired",
+ "com_ui_api_key_expires_in_day": "Expires in 1 day",
+ "com_ui_api_key_expires_in_days": "Expires in {{0}} days",
+ "com_ui_api_key_expires_on": "Expires on {{0}}",
+ "com_ui_api_key_last_used": "Last used {{0}}",
"com_ui_api_key_name": "Key Name",
"com_ui_api_key_name_placeholder": "My API Key",
"com_ui_api_key_name_required": "API key name is required",
+ "com_ui_api_key_never_used": "Never used",
+ "com_ui_api_key_no_expiration": "No expiration",
"com_ui_api_key_warning": "Make sure to copy your API key now. You won't be able to see it again!",
+ "com_ui_api_keys_description": "API keys let external apps and tools run your agents through LibreChat's OpenAI-compatible API. Treat each one like a password: anyone who has it can act as you, so revoke any keys you no longer use.",
+ "com_ui_api_keys_empty_text": "API keys let external applications run your agents through the OpenAI-compatible API. Create a key to get started.",
+ "com_ui_api_keys_empty_title": "Connect your agents to external apps",
"com_ui_api_keys_load_error": "Failed to load API keys",
"com_ui_archive": "Archive",
"com_ui_archive_delete_error": "Failed to delete archived conversation",
@@ -968,6 +986,7 @@
"com_ui_delete_action_confirm": "Are you sure you want to delete this action?",
"com_ui_delete_agent": "Delete Agent",
"com_ui_delete_agent_confirm": "Are you sure you want to delete this agent?",
+ "com_ui_delete_api_key": "Delete API Key",
"com_ui_delete_assistant": "Delete Assistant",
"com_ui_delete_assistant_confirm": "Are you sure you want to delete this Assistant? This cannot be undone.",
"com_ui_delete_confirm": "This will delete",
@@ -1162,7 +1181,6 @@
"com_ui_key": "Key",
"com_ui_key_required": "API key is required",
"com_ui_labels": "Labels",
- "com_ui_last_used": "Last used",
"com_ui_late_night": "Happy late night",
"com_ui_latest": "latest",
"com_ui_latest_activity": "Latest activity",
@@ -1294,7 +1312,6 @@
"com_ui_next": "Next",
"com_ui_next_result": "Next result",
"com_ui_no": "No",
- "com_ui_no_api_keys": "No API keys yet. Create one to get started.",
"com_ui_no_auth": "None (Auto-detect)",
"com_ui_no_bookmarks": "it seems like you have no bookmarks yet. Click on a chat and add a new one",
"com_ui_no_bookmarks_match": "No bookmarks match your search",
diff --git a/packages/client/src/components/SecretInput.tsx b/packages/client/src/components/SecretInput.tsx
index 57b718a9c4..ba0dda7aaf 100644
--- a/packages/client/src/components/SecretInput.tsx
+++ b/packages/client/src/components/SecretInput.tsx
@@ -5,8 +5,10 @@ import { cn } from '~/utils';
export interface SecretInputProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> {
- /** Show copy button */
+ /** Show the built-in copy button */
showCopy?: boolean;
+ /** Custom copy control rendered inside the input, in place of the built-in one */
+ copyButton?: React.ReactNode;
/** Callback when value is copied */
onCopy?: () => void;
/** Duration in ms to show checkmark after copy (default: 2000) */
@@ -28,6 +30,7 @@ const SecretInput: React.ForwardRefExoticComponent<
label,
className,
showCopy = false,
+ copyButton,
labelClassName,
containerClassName,
controlsClassName,
@@ -79,7 +82,7 @@ const SecretInput: React.ForwardRefExoticComponent<
className={cn(
'flex h-10 w-full rounded-lg border border-border-light bg-transparent py-2 pl-3 text-sm transition-colors placeholder:text-muted-foreground hover:border-border-medium focus-visible:border-border-heavy focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50',
className ?? '',
- showCopy ? 'pr-20' : 'pr-11',
+ copyButton != null || showCopy ? 'pr-20' : 'pr-11',
)}
ref={ref}
disabled={disabled}
@@ -95,13 +98,14 @@ const SecretInput: React.ForwardRefExoticComponent<
)}
<div
className={cn(
- 'pointer-events-none absolute inset-y-0 right-1.5 flex items-center gap-0.5 [&>button]:pointer-events-auto',
+ 'pointer-events-none absolute inset-y-0 right-1.5 flex items-center gap-0.5 [&_button]:pointer-events-auto',
controlsOnHover &&
'opacity-0 transition-opacity duration-150 group-focus-within/secret-input:opacity-100 group-hover/secret-input:opacity-100',
controlsClassName,
)}
>
- {showCopy && (
+ {copyButton}
+ {showCopy && copyButton == null && (
<button
type="button"
onClick={handleCopy}