Keys
Configure bring-your-own AI provider API keys with brand marks, masked display, clickable connection retesting, timed reveal, inline validation, and removal with undo.
import { ProviderKeys } from '@uthereal/ui/provider-keys'Provider keys playground
Provider keys
Your own keys, encrypted at rest and only used by this workspace.
- Anthropicsk-ant-••••4f2a
- OpenAIsk-proj-••••9c1e
- Google AIAIza••••Qk7w
- Mistral••••h7Qd
- xAIGet one at console.x.aiNot set
Overview
ProviderKeys renders a settings card for bring-your-own-key (BYOK) AI workspaces. Each row displays the provider mark, masked key (sk-ant-••••4f2a), connection status (Connected, Invalid, Not set, or Testing), relative usage time, and row actions. Users can click a status chip to retest a stored key, reveal a key for five seconds with a draining countdown ring, copy it to the clipboard, add or rotate keys in an inline validated form, and remove a key with a five-second undo window.
Use ProviderKeys on account settings, workspace administration, or onboarding screens where customers bring their own model provider credentials. For picking an active model per request, use Models. For tracking token usage and spend limits, use Usage card.
Usage
'use client'
import { useState } from 'react'
import {
ProviderKeys,
type ProviderKeyRuntime,
} from '@uthereal/ui/provider-keys'
export function WorkspaceKeys({
initialKeys,
}: {
initialKeys: ProviderKeyRuntime[]
}) {
const [keys, setKeys] = useState<ProviderKeyRuntime[]>(initialKeys)
return (
<ProviderKeys
keys={keys}
onKeysChange={setKeys}
testKey={async ({ provider, key, signal }) => {
const res = await fetch('/api/provider-keys/test', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ provider, key }),
signal,
})
return res.json()
}}
onSave={(provider, key, mode) => {
void fetch('/api/provider-keys', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ provider, key, mode }),
})
}}
onRemove={(provider) => {
void fetch(`/api/provider-keys/${provider}`, { method: 'DELETE' })
}}
/>
)
}Omit keys, defaultKeys, and testKey to render a standalone interactive workspace with built-in simulated connection tests.
Examples
Masked server keys and empty onboarding
Pass defaultKeys with last4 only (never raw secrets) to disable reveal and copy while keeping status retest, rotation, and removal active. Pass defaultKeys={[]} for a clean onboarding state where every row shows Not set and an Add key action.
Workspace keys
Your own keys, encrypted at rest and only used by this workspace.
- Anthropicsk-ant-••••4f2a
- OpenAIsk-proj-••••9c1e
- Mistral••••h7Qd
Connect your AI providers
Add at least one provider key to enable chat and agent runs.
- AnthropicGet one at console.anthropic.comNot set
- OpenAIGet one at platform.openai.comNot set
- Google AIGet one at aistudio.google.comNot set
Loading skeleton
Set loading while fetching stored metadata to render geometry-matched placeholder rows without layout shift. Pass providers to scope the card to the exact providers your workspace supports.
Provider keys
Your own keys, encrypted at rest and only used by this workspace.
Providers and format validation
The inline Add and Rotate form validates pasted keys as you type using checkFormat(spec, value) before allowing a connection test.
| Provider ID | Display name | Expected prefix / format | Mask preview | Console domain |
|---|---|---|---|---|
anthropic | Anthropic | sk-ant-<segment>-<40+ urlsafe> | sk-ant-••••4f2a | console.anthropic.com |
openai | OpenAI | sk- (proj-, svcacct-, admin-) | sk-proj-••••9c1e | platform.openai.com |
google | Google AI | AIza + 35 urlsafe chars (39 total) | AIza••••Qk7w | aistudio.google.com |
mistral | Mistral | 32 alphanumeric characters | ••••h7Qd | console.mistral.ai |
xai | xAI | xai- + 40+ alphanumeric chars | xai-••••8b2d | console.x.ai |
Security model
- Never put raw secrets in serializable JSON.
providerKeyEntrySchema(defaultKeys) intentionally accepts onlyprovider,status,last4,masked,lastUsedAt,checkedAt, anderror. - Server-safe masking by default. When a row omits
value(passinglast4ormaskedonly), the Reveal and Copy controls stay disabled while Test connection, Rotate, and Remove remain available. - React-only secret channel. Full secret
valuestrings enter exclusively through the React-onlykeysprop (or locally in memory immediately after a user pastes and saves a key). - Deferred deletion. Clicking Remove immediately hides the row and starts the
undoDurationtimer;onRemoveandremoveActionfire only once the undo window expires or the user opens Add key for that provider.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
title | stringDefault: "Provider keys" | Card heading text and accessible section name. |
description | stringDefault: "Your own keys, encrypted at rest and only used by this workspace." | Supporting line under the title. Set to an empty string (or null in React) to hide it. |
footer | stringDefault: "Keys are encrypted with AES-256 and never written to logs." | Quiet encryption note under the provider list. Set to an empty string (or null in React) to hide it. |
providers | ProviderId[]Default: ["anthropic","openai","google","mistral","xai"] | Ordered list of AI providers rendered as rows. Defaults to Anthropic, OpenAI, Google AI, Mistral, and xAI. |
defaultKeys | ProviderKeyEntry[]— | Initial masked keys when uncontrolled (never put raw secret values in serializable JSON). Omit for the sample workspace or pass [] for all rows Not set; edits do not reset a mounted instance. |
revealDuration | integerDefault: 5000 | Milliseconds a revealed key stays visible before re-masking automatically. |
undoDuration | integerDefault: 5000 | Milliseconds Undo stays available after removing a key before deletion commits. |
loading | booleanDefault: false | Shows geometry-matched skeleton placeholder rows while provider keys load. |
saveAction | string— | Registered host action requested when a newly added or rotated key passes validation and saves. |
removeAction | string— | Registered host action requested once a removal commits after the undo window expires. |
testAction | string— | Registered host action requested when the user clicks a row status to retest a stored key. |
copyAction | string— | Registered host action requested after a key is copied to the clipboard. |
locale | string— | BCP 47 locale for date formatting; inherited when omitted. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | ProviderKeysThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | ProviderKeysMotionOptionsDefault: {} | Inline form fold spring and crossfade timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
ProviderKeyEntry accepts { provider, status?, last4?, masked?, lastUsedAt?, checkedAt?, error? }.
React integration
| Prop | Purpose |
|---|---|
keys | Controlled ProviderKeyRuntime[] list. Supports optional value for reveal and copy, plus Date | number | string timestamps. |
onKeysChange(keys) | Called on every change: add, rotate, remove, undo restore, or status retest. |
testKey(request) | Async verifier returning Promise<{ ok: true; detail? } | { ok: false; error }>. Receives { provider, key?, signal }. |
onSave(provider, key, mode) | Called after a pasted key passes its connection test (mode is 'add' or 'rotate'). |
onRemove(provider) | Called once the undo window closes without cancellation. |
onCopy(provider) | Called after a revealed or stored secret is written to the clipboard (useful for audit logging). |
onAction(action, provider) | Called for registered host actions (saveAction, removeAction, testAction, copyAction) with the provider ID. |
description, footer | Also accept null in React to hide the description or encryption footer line. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme. |
ref, className, style | Applied to the root <section> element. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Tab | Moves across header Add key, each row's status button, Reveal, Copy, Rotate, Remove, or Add key. |
Enter | Inside the inline form, validates the key format and starts the connection test. |
Escape | Inside the inline form, aborts any in-flight test, closes the form, and returns focus to its trigger. |
The card renders a <section> labelled by its heading (aria-labelledby) with provider rows in a semantic <ul>. Every action exposes a provider-specific accessible name (for example, "Copy the Anthropic key"), status combines an icon with text (Connected, Invalid, Not set, Testing), Reveal sets aria-pressed, and Add/Rotate set aria-expanded. A pre-mounted polite role="status" region announces reveals, copies, test results, removals, and undo restorations. Focus moves to the input when opening the form, returns to the trigger on cancel, moves to Undo on remove, and returns to Remove on undo.
Container queries adapt the grid automatically: at 560px and wider, rows display four columns (mark | name + key | status + meta | actions); below 560px, status moves beside the provider name and the form stacks cleanly down to 360px without horizontal scroll. Logical CSS properties preserve alignment in RTL (dir="rtl"), and forced-colors: active maps card borders, dividers, focus rings, and the countdown stroke to system colors.
Motion & theming
Status chips, keys, metadata, and helper lines crossfade inside a shared grid cell (100ms out, 160ms in with a 2px rise) so swaps never resize rows. The inline form expands and collapses on a critically damped 240ms bounce-free spring paired with a short opacity fade, and the reveal countdown ring drains linearly over revealDuration. Under prefers-reduced-motion: reduce, the countdown ring, rise travel, press scale, and height springs are removed while preserving 120ms opacity crossfades and slowing the testing spinner. Setting motion="none" makes every state transition immediate (0ms).
theme accepts mode, accent, and typed tokens across five groups:
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-success, --ui-warning, --ui-info |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
type | --ui-font-mono, --ui-font-display |
control | --ui-control-height, --ui-control-padding-x, --ui-control-gap, --ui-icon-size |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, ProviderKeys is a leaf. Supply only masked defaultKeys metadata and wire saveAction, removeAction, testAction, and copyAction to registered host actions. See Building with agents.
{
"type": "ProviderKeys",
"props": {
"title": "Provider keys",
"providers": ["anthropic", "openai", "google", "mistral", "xai"],
"defaultKeys": [
{
"provider": "anthropic",
"status": "connected",
"last4": "4f2a",
"lastUsedAt": "2 min ago"
},
{
"provider": "openai",
"status": "connected",
"last4": "9c1e",
"lastUsedAt": "14 min ago"
},
{
"provider": "mistral",
"status": "invalid",
"last4": "h7Qd",
"checkedAt": "3 days ago",
"error": "401 Unauthorized, the key was revoked"
}
],
"saveAction": "save_provider_key",
"removeAction": "remove_provider_key",
"testAction": "test_provider_key"
},
"children": []
}