API keys (Pro)
ProIncluded in $99A workspace's keys with scopes, who made them, last use and expiry; create, rotate with a grace period, and revoke.
On this page
Installation
Needs chatcn Pro
This command works with a Pro license, along with every Pro component.
Or start free: sign up and get three Pro components on us, with a new one every month.
Usage
import { ApiKeys } from "@/components/ui/chatcn/pro/api-keys"
<ApiKeys
keys={keys} // { id, name, prefix, last4, scopes, createdAt, createdBy?, lastUsedAt?, expiresAt?, oldSecretUntil? }
scopes={[{ id: "chat", label: "Send messages" }, { id: "files", label: "Read files" }]}
envName="CHATCN_API_KEY"
onCreate={(input) => createKey(input)} // returns { secret }
onRotate={(id) => rotateKey(id)} // returns { secret }
onRevoke={(id) => revokeKey(id)}
/>Each key shows its prefix and last four characters, what it can do, who made it and when, when it was last used and when it expires. A key nobody has used for staleDays (90 by default) says so on its row and suggests revoking it; an expired key says Expired. Create asks for a name, scopes and an expiry and then shows the secret once with key-reveal-once. Rotate makes a new secret and keeps the old one working for graceHours (24 by default) so a deploy can switch over, and the row says when the old one stops; revoke says it is immediate and final. Both confirm inside the row with Cancel focused. Keep secrets on your server: this component only ever sees a secret at the moment it is shown.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
keys | ApiKeyRecord[] | Described without the secret |
scopes | ApiKeyScope[] | { id, label, description? } |
expiries | ApiKeyExpiry[] | Choices when creating; default 30 days, 90 days, 1 year, never |
onCreate | (input) => Promise<{ secret, name? }> | { name, scopes, expiresInDays } |
onRotate, onRevoke | Rotate returns the new { secret } | |
graceHours, staleDays | number | 24 and 90 by default |
envName | string | Offers a .env line when a secret is shown |
now | Date | Pins relative times |
labels | Partial<ApiKeysLabels> | Every string, for translation |
Accessibility
- Each key's masked value reads as the prefix and the last four characters.
- Scopes are a labelled list; create uses native checkboxes and radios.
- Confirmations open inside the row with Cancel focused; Escape cancels and focus returns to the menu.
Motion
None beyond the spinner while an action runs.