Bring your own keys (Pro)
ProIncluded in $99One row per provider: the masked key, whether it works, when it was last used, and a test that runs in place.
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 { ByokKeys } from "@/components/ui/chatcn/pro/byok-keys"
<ByokKeys
providers={[
{
id: "anthropic",
name: "Anthropic",
format: apiKeyFormats.anthropic,
key: { prefix: "sk-ant-", last4: "r0Xt", lastUsedAt },
status: "ok",
checkedAt,
usage: requestsPerDay, // 14 numbers, oldest first
usedFor: "Chats on Claude models",
},
{ id: "google", name: "Google", key: null },
]}
onTest={(provider) => testStoredKey(provider)}
onSave={(provider, key) => storeKey(provider, key)}
onRemove={(provider) => deleteKey(provider)}
/>Keys are described, never shown: the prefix and last four characters, with fixed dots between so the length does not leak. Each row says in plain words whether the key works and when it was last checked; a failing key carries its reason on the row (a revoked key, an empty balance), not in a toast that has gone by the time anyone looks. Test runs one real request with the stored key and reports how long it took. Two weeks of use sit beside the last used time, so a key that stopped being used is obvious. Replace opens the free api-key-input inside the row, with its paste cleanup and checks; remove asks first and says what will stop working.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
providers | ByokProvider[] | { id, name, icon?, format?, key?, status?, error?, checkedAt?, usage?, usedFor? } |
onTest | (provider) => Promise<{ ok, latencyMs?, error? }> | Shows Test on rows with a key |
onValidate | (provider, key, { signal }) => Promise<ApiKeyValidation> | Live check while replacing |
onSave | (provider, key) => void | Promise<void> | New or replacement key |
onRemove | (provider) => void | Promise<void> | Shows Remove in the menu |
now | Date | Pins relative times |
labels | Partial<ByokKeysLabels> | Every string, for translation |
Accessibility
- Each key's state is a status region, so a test result is heard.
- The masked key reads as the prefix and the last four characters.
- The usage bars are an image labelled with the total.
- Remove asks inside the row with Cancel focused; Escape cancels and focus returns to the menu.
Motion
None beyond the spinner while a test or removal runs.