Tools & Approvals
API Key Card
Issue a key to an agent from chat — name, scope chips and a lifetime, the key revealed once with a scramble, then masked with usage, Rotate and a hold-to-revoke.
1 variantMIT
Preview
Linear API key
Requested by triage-agent
Needs access
triage-agent wants to file the 6 bugs it found in the checkout logs and link them to the incident.
Scopes
Pick at least one scope.
Expires
Until Nov 20, 2026
The key is shown once, after it is created.
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://tuffui.com/r/api-key-card.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { ApiKeyCard, type ApiKey } from "@/components/ui/api-key-card";
// Rendered when an agent asks for access to a service it isn't connected to.
export function GrantAccess({ request }: Props) {
const [key, setKey] = useState<ApiKey | null>(null);
const [busy, setBusy] = useState(false);
return (
<ApiKeyCard
service="Linear"
requester={request.agent} // "triage-agent"
reason={request.reason}
scopes={[
{ value: "read", label: "read", description: "Issues, projects and comments." },
{ value: "write", label: "write", description: "Create and edit issues." },
{ value: "admin", label: "admin", description: "Members and webhooks.", elevated: true },
]}
defaultDraft={{ scopes: ["read"], lifetime: "30d" }}
apiKey={key}
creating={busy}
onCreate={async (draft) => {
setBusy(true);
// The secret comes back once; keep only last4 after it is shown.
setKey(await api.keys.create(draft));
setBusy(false);
}}
onSecretHidden={() => setKey((k) => k && { ...k, secret: undefined })}
onRotate={async (k) => setKey(await api.keys.rotate(k.id))}
onRevoke={async (k) => setKey(await api.keys.revoke(k.id))}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| service* | string | — | The service the key is for, used in the title: "Linear API key". |
| serviceIcon | Icon | Key | Phosphor icon in the header tile. |
| requester | string | — | Who asked for access, usually the agent. Also seeds the default key name. |
| reason | ReactNode | — | Why access is needed, shown above the form. |
| scopes* | ApiKeyScope[] | — | Scopes as check chips. A checked scope shows its description below; `elevated` ones turn warning. |
| lifetimes | ApiKeyLifetime[] | 7 days / 30 days / Never | Segmented lifetime options. A `hint` shows next to the selected one. |
| draft | ApiKeyDraft | — | Controlled form: name, scopes and lifetime. |
| defaultDraft | Partial<ApiKeyDraft> | — | Starting form when uncontrolled. The name defaults to "requester · service", the lifetime to the second option. |
| onDraftChange | (draft: ApiKeyDraft) => void | — | Called on every edit of the form. |
| apiKey | ApiKey | null | null | The issued key. With a `secret` it is revealed once; without, it shows masked with usage, Rotate and Revoke. `null` shows the form. |
| creating | boolean | false | Spinner on Create key. |
| rotating | boolean | false | Spinner on Rotate. |
| onCreate | (draft: ApiKeyDraft) => void | — | Create key was pressed. Disabled until a scope is picked and the name is set. |
| onCopy | (secret: string) => void | — | Called after the secret is written to the clipboard. |
| copied | boolean | — | Controlled copied state of the revealed secret. |
| onSecretHidden | (key: ApiKey) => void | — | The secret was masked, by Done or after a copy. Drop it from your state here. |
| hideAfterCopyMs | number | 1400 | Masks the secret this long after it is copied. 0 waits for Done. |
| onRotate | (key: ApiKey) => void | — | Shows Rotate. Pass back a key with a new `id` and `secret` to reveal it. |
| onRevoke | (key: ApiKey) => void | — | Shows Hold to revoke. Called once it has been held for `revokeHoldMs`; pass back the key with `status: "revoked"`. |
| revokeHoldMs | number | 1200 | How long Revoke must be held, with the pointer or Enter / Space. |
| usageLabel | string | "requests · 24 h" | Label next to the usage total above the sparkline. |
| className | string | — | Extra classes for the root element. |
type ApiKeyScope = {
value: string;
label: string; // "write"
description?: string; // "Create and edit issues."
elevated?: boolean; // admin-like: warning tone when checked
};
type ApiKeyLifetime = { value: string; label: string; hint?: string };
type ApiKeyDraft = { name: string; scopes: string[]; lifetime: string };
type ApiKey = {
id: string;
name: string;
secret?: string; // full key, revealed once
prefix?: string; // "sk-lin-"
last4: string; // "a91f" → sk-lin-…a91f
scopes: string[];
expires?: string; // "Expires Dec 13, 2026"
lastUsed?: string; // "2 min ago"
usage?: number[]; // requests per bucket, oldest first
status?: "active" | "revoked";
};