import React, { useState, useEffect, useCallback } from 'react'; import { KeyRound, Plus, Trash2, Copy, Check, Loader2 } from 'lucide-react'; import { apiJson } from '../lib/api'; // API keys for programmatic access (MCP clients, scripts, n8n). The raw key is // returned exactly once by POST /api/keys, so it is surfaced in a one-time // banner the user must copy before it disappears. export default function ApiKeysCard() { const [keys, setKeys] = useState(null); const [name, setName] = useState(''); const [busy, setBusy] = useState(false); const [freshKey, setFreshKey] = useState(null); // { key, name } shown once const [copied, setCopied] = useState(false); const load = useCallback(() => { apiJson('/api/keys').then((d) => setKeys(d.keys || [])).catch(() => setKeys([])); }, []); useEffect(() => { load(); }, [load]); const createKey = useCallback(async () => { setBusy(true); try { const d = await apiJson('/api/keys', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: name.trim() || undefined }), }); setFreshKey(d); setCopied(false); setName(''); load(); } catch (e) { alert(e?.detail || 'Could not create the key.'); } setBusy(false); }, [name, load]); const revoke = useCallback(async (k) => { if (!window.confirm(`Revoke "${k.name}"? Anything using it stops working immediately.`)) return; try { await apiJson(`/api/keys/${k.id}`, { method: 'DELETE' }); load(); } catch (e) { alert(e?.detail || 'Could not revoke the key.'); } }, [load]); const copyKey = useCallback(() => { navigator.clipboard?.writeText(freshKey.key).then(() => setCopied(true)).catch(() => {}); }, [freshKey]); const active = (keys || []).filter((k) => !k.revoked); return (

API keys

Keys for CLI clients, scripts and the REST API (see “Connect an agent” above). Apps connected through claude.ai or ChatGPT show up here too: revoking a key disconnects that app. Keys use your plan's minutes.

{freshKey && (

Copy your new key now. For security it will never be shown again.

{freshKey.key}
)} {keys === null ? (
) : ( <> {active.length > 0 && (
{active.map((k) => (
{k.name}{' '} {k.prefix}…
{k.last_used_at ? `used ${new Date(k.last_used_at).toLocaleDateString()}` : 'never used'}
))}
)}
setName(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') createKey(); }} placeholder="Key name (e.g. n8n, claude)" className="input-field flex-1 text-sm" maxLength={60} />
)}
); }