Skip to content
Sign upPro
SettingsAPI keysMenu

API keys (Pro)

ProIncluded in $99

A workspace's keys with scopes, who made them, last use and expiry; create, rotate with a grace period, and revoke.

ProFour keys: one mid rotation, one healthy, one unused for months and one expired. Create, rotate or revoke.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/api-keys

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

tsx
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

ProNo keys yet, and a narrow frame where each key stacks.

Props

PropTypeNotes
keysApiKeyRecord[]Described without the secret
scopesApiKeyScope[]{ id, label, description? }
expiriesApiKeyExpiry[]Choices when creating; default 30 days, 90 days, 1 year, never
onCreate(input) => Promise<{ secret, name? }>{ name, scopes, expiresInDays }
onRotate, onRevokeRotate returns the new { secret }
graceHours, staleDaysnumber24 and 90 by default
envNamestringOffers a .env line when a secret is shown
nowDatePins relative times
labelsPartial<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.