API key field
Enter and manage an API key for an AI provider. Empty, it is a password field
with a reveal toggle; with a key saved, it shows the key the way your server
masked it ("sk-…a1b2") with Replace and Remove. ds::provider-keys is a panel
of them, one per provider.

Needs Alpine and the package's script for the reveal toggle, Remove's confirmation and Test's
testevent. See getting started. Without them it is an ordinary form: the key posts, Test postsintent=test, and Remove stays hidden behind its first press, which fails safe.
Security
The component never receives, renders or stores a key.
- It takes
hint, a masked form your server makes ("sk-…a1b2"), never the key. Avalueis refused with an exception. - The input is always empty on the page. Its reveal toggle shows only what the reader is typing now, and hides it again when the form submits.
autocomplete="off",spellcheck="false",autocapitalize="off"andautocorrect="off"are set, so the browser neither offers to save it nor sends it to a spelling service. The password managers' opt-out attributes (data-1p-ignore,data-lpignore,data-bwignore) are written too, as a courtesy: none of them is a contract, so do not rely on them.- Nothing is written to storage or logged by the script.
Store keys encrypted (Laravel's encrypted cast), make the hint on the
server, and check a key only on the server.
Use it
<x-ds::api-key-field
provider="OpenAI"
name="openai_key"
:hint="$team->openai_key ? Str::mask($team->openai_key, '…', 3, -4) : null"
:status="$team->openai_key_status"
prefix="sk-"
help="Create one under API keys in your OpenAI dashboard."
:test="true"
:action="route('settings.keys.update')"
/>
public function update(Request $request)
{
$team = $request->user()->team;
match ($request->input('intent')) {
'remove' => $team->update(['openai_key' => null]),
'test' => $team->update(['openai_key_status' => OpenAiKey::check($request->input('openai_key') ?: $team->openai_key)]),
default => $request->filled('openai_key') && $team->update(['openai_key' => $request->input('openai_key'), 'openai_key_status' => 'set']),
};
return back();
}
Several providers in one panel and one form: each field posts keys[id] and
each button intent[id].

<x-ds::provider-keys :action="route('settings.keys.update')" :providers="[
['id' => 'openai', 'provider' => 'OpenAI', 'hint' => $hints['openai'], 'status' => 'valid', 'prefix' => 'sk-', 'test' => true],
['id' => 'anthropic', 'provider' => 'Anthropic', 'prefix' => 'sk-ant-'],
]" />
In Livewire, cancel test and check the key yourself:
<x-ds::api-key-field provider="Anthropic" wire:model="key" :status="$status" :test="true" x-on:test.prevent="$wire.testKey()" />
Props: api-key-field
| Prop | Type | Default | What it does |
|---|---|---|---|
provider | string | — | The provider's name, used in the label. |
label | string | :provider API key | |
name | string | api_key | The new key's field name. |
hint | string | — | The saved key, masked by your server. Given, the field shows it with Replace and Remove. |
status | unset set valid invalid checking | set with a hint, else unset | What your server knows of the key, as a mark and words. checking, valid and invalid are drawn as the agent components' running, done and failed. |
message | string | per status | The status's words, replacing "The key works", "The key was rejected"… |
help | string | — | Guidance under the field. |
error | string | — | A validation message; opens the field for replacing. |
prefix | string | — | "sk-": a hint ("Keys start with sk-.") and the placeholder. Never a check. |
logo | string | — | An image URL. The logo slot takes markup. |
test | bool | false | A Test button: dispatches test (cancelable), then posts intent=test. The test slot replaces it. |
intent | string | intent | The name Test, Remove and Save post under. |
action | string | — | A URL: the field is its own form, with a Save button. |
disabled | bool | false | |
testLabel, replaceLabel, removeLabel, removeQuestion, saveLabel, revealLabel, prefixText | string | English |
Listeners on the tag (x-on:test, @test) go on the field's root, where its
events bubble to; anything else (wire:model, x-model, data attributes)
lands on the input, and id names it.
Props: provider-keys
| Prop | Type | Default | What it does |
|---|---|---|---|
providers | array | [] | Rows: id, provider, and any of the field's hint, status, message, help, error, prefix, logo, test. |
action | string | — | One form for the panel, with a Save keys button. |
title | string | API keys | |
description | string | — |
Accessibility
- A labelled password field; the status, the error and the help describe it,
and an invalid key marks it
aria-invalid. - The status line is a polite status, in the page from the start: a check the server finishes is read once.
- Reveal is a toggle button named "Show key" that says pressed or not.
- Enter in the replacement field saves; it never presses Remove, which asks before it acts.
Don't
- Don't pass the key, or a hint that is most of it. Four characters at the end is plenty to recognise it.
- Don't validate the format here.
prefixis a hint: providers change formats, and a check that blocks a valid key is worse than none. - Don't keep a key in a public Livewire property after saving it. Public properties travel to the browser in the snapshot; clear it once saved.
From the package repo: edit this page on GitHub.