# API key manager

Review masked key metadata, scopes and lifecycle status with explicit create and revoke requests.

Access: pro. Category: Blocks. Kind: composite.

## When to use

- Use it when a page needs review masked key metadata, scopes and lifecycle status with explicit create and revoke requests.
- Choose it inside an authenticated product surface when the host application owns routing, persistence, and service calls.

## Alternatives

- Choose empty-state instead when empty collections, search results and errors with a clear next action is the actual interface need, rather than api key manager.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install API key manager

```sh
npx shadcn@latest add @tidal-pro/api-key-manager
```

Stylesheets: `components/ui/tidal.css`, `components/ui/api-key-manager.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/api-key-manager.css";
import{TidalApiKeyManager}from"./components/ui/api-key-manager";
export default()=><div className="tidal-scope"><TidalApiKeyManager keys={[{id:"example",name:"Demo",maskedValue:"value",scopes:["value"],status:"active",created:{label:"Demo"}}]} title={"Demo"}/></div>;
```

## Structured props

- `TidalApiKeyManager.keys: ReadonlyArray<TidalApiKeyRecord>`: Required keys value accepted by this exported component.
- `TidalApiKeyManager.title: ReactNode`: Required title value accepted by this exported component.
- `TidalApiKeyManager.createButtonProps?: ButtonProps | undefined`: Optional create button props value accepted by this exported component.
- `TidalApiKeyManager.createButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional create button ref value accepted by this exported component.
- `TidalApiKeyManager.creationPending?: boolean | undefined` (default false): Optional creation pending value accepted by this exported component.
- `TidalApiKeyManager.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalApiKeyManager.dialog?: ReactNode`: Creation, confirmation, and one-time secret UI belong to the consumer. No key is generated or stored here.
- `TidalApiKeyManager.emptyContent?: ReactNode` (default "No API keys yet."): Optional empty content value accepted by this exported component.
- `TidalApiKeyManager.headingLevel?: "h2" | "h3" | "h4" | "h5" | "h6" | undefined` (default "h2"): Optional heading level value accepted by this exported component.
- `TidalApiKeyManager.labels?: Partial<{ create: string; creating: string; revoke: string; revoking: string; active: string; revoked: string; expired: string; created: string; lastUsed: string; unused: string; expires: string; scopes: string; noScopes: string; }> | undefined` (default {}): Optional labels value accepted by this exported component.
- `TidalApiKeyManager.onCreateRequest?: ((event: MouseEvent<HTMLButtonElement>) => void) | undefined`: Callback invoked when the create request interaction is proposed.
- `TidalApiKeyManager.onRevokeRequest?: ((record: TidalApiKeyRecord, event: MouseEvent<HTMLButtonElement>) => void) | undefined`: Callback invoked when the revoke request interaction is proposed.
- `TidalApiKeyManager.pendingKeyId?: string | undefined`: Optional pending key id value accepted by this exported component.
- `TidalApiKeyManager.secret?: ReactNode`: Optional secret value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/api-key-manager.tsx) | [Manifest](https://tidalui.com/examples/api-key-manager.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useId, useRef, useState } from "react";

import { TidalApiKeyManager, type TidalApiKeyRecord } from "./components/ui/api-key-manager";

import { TidalAlertDialog } from "./components/ui/alert-dialog";

import "./components/ui/api-key-manager.css";

import "./components/ui/alert-dialog.css";

import "./components/ui/status-badge.css";



const tidalExampleStyles = ".tidal-scope .api-key-manager-demo {\n  width: min(100%, 740px);\n  max-width: 740px;\n  min-width: 0;\n}\n.tidal-scope .api-key-manager-demo > p {\n  font-size: 11px;\n  line-height: 1.6;\n  color: var(--t-muted);\n  margin: 12px 0 0;\n  overflow-wrap: anywhere;\n}\n.tidal-scope .api-key-demo-form {\n  display: grid;\n  gap: 10px;\n  min-width: 0;\n}\n.tidal-scope .api-key-demo-form label {\n  font-weight: 600;\n}\n.tidal-scope .api-key-demo-form input {\n  box-sizing: border-box;\n  width: 100%;\n  min-width: 0;\n  min-height: 44px;\n  border: 1px solid var(--t-border);\n  border-radius: 8px;\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 16px;\n  padding: 10px 12px;\n}\n.tidal-scope .api-key-demo-form > div {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 8px;\n}\n.tidal-scope .api-key-demo-form button {\n  font: inherit;\n  color: var(--t-ink);\n  background: var(--t-subtle);\n  border: 1px solid var(--t-border);\n  border-radius: 8px;\n  min-height: 44px;\n  min-width: 44px;\n  padding: 10px 14px;\n  cursor: pointer;\n}\n.tidal-scope .api-key-demo-form :is(input, button):focus-visible {\n  outline: 2px solid var(--t-ink);\n  outline-offset: 3px;\n}";

const initial: TidalApiKeyRecord[] = [
  {
    id: "production",
    name: "Production",
    maskedValue: "demo_••••••••••••7a2c",
    scopes: ["projects:read", "projects:write"],
    status: "active",
    created: { label: "Oct 12, 2026", dateTime: "2026-10-12" },
    lastUsed: { label: "Today, 9:41 AM" },
  },
  {
    id: "reporting",
    name: "Reporting",
    maskedValue: "demo_••••••••••••1f8b",
    scopes: ["reports:read"],
    status: "active",
    created: { label: "Oct 8, 2026", dateTime: "2026-10-08" },
    lastUsed: { label: "Yesterday, 3:12 PM" },
  },
];

export function ApiKeyManagerDemo({
  theme = "light",
  dir = "ltr",
}: {
  theme?: "light" | "dark";
  dir?: "ltr" | "rtl";
}) {
  const nameId = `api-key-name-${useId().replace(/:/g, "")}`;
  const [keys, setKeys] = useState(initial),
    [request, setRequest] = useState<TidalApiKeyRecord | null>(null),
    [creating, setCreating] = useState(false),
    [name, setName] = useState(""),
    [message, setMessage] = useState(
      "Sample records. No working keys are shown.",
    );
  const createRef = useRef<HTMLButtonElement>(null),
    opener = useRef<HTMLButtonElement | null>(null);
  const nextId = useRef(1);
  return (
    <div className="api-key-manager-demo" dir={dir}>
      <TidalApiKeyManager
        title="API keys"
        description="Manage access for your applications."
        keys={keys}
        createButtonRef={createRef}
        onCreateRequest={() => setCreating((v) => !v)}
        onRevokeRequest={(key, event) => {
          opener.current = event.currentTarget;
          setRequest(key);
        }}
        secret={
          creating ? (
            <form
              className="api-key-demo-form"
              onSubmit={(e) => {
                e.preventDefault();
                if (!name.trim()) return;
                setKeys((v) => [
                  ...v,
                  {
                    id: `sample-${nextId.current++}`,
                    name: name.trim(),
                    maskedValue: "demo_••••••••••••sample",
                    scopes: ["projects:read"],
                    status: "active",
                    created: { label: "Added in this preview" },
                  },
                ]);
                setMessage(
                  `Added ${name.trim()} as a sample record. No API key was generated.`,
                );
                setName("");
                setCreating(false);
                createRef.current?.focus({ preventScroll: true });
              }}
            >
              <label htmlFor={nameId}>Sample key name</label>
              <input
                id={nameId}
                value={name}
                onChange={(e) => setName(e.target.value)}
                required
                maxLength={80}
                placeholder="Development"
                autoComplete="off"
              />
              <div>
                <button
                  type="button"
                  onClick={() => {
                    setCreating(false);
                    createRef.current?.focus({ preventScroll: true });
                  }}
                >
                  Cancel
                </button>
                <button type="submit">Add sample record</button>
              </div>
            </form>
          ) : undefined
        }
        dialog={
          <TidalAlertDialog
            open={request !== null}
            onOpenChange={(open) => {
              if (!open) setRequest(null);
            }}
            trigger={
              <button type="button" hidden tabIndex={-1}>
                Revoke key
              </button>
            }
            title={`Revoke ${request?.name ?? "key"}?`}
            description="This changes only the sample record. Real key revocation belongs to your backend."
            onCancel={() => setRequest(null)}
            cancelLabel="Cancel"
            confirmLabel="Revoke sample key"
            onConfirm={() => {
              if (request) {
                setKeys((v) =>
                  v.map((key) =>
                    key.id === request.id ? { ...key, status: "revoked" } : key,
                  ),
                );
                setMessage(`${request.name} is revoked in this preview.`);
              }
              setRequest(null);
            }}
            theme={theme}
            dir={dir}
            contentProps={{
              onCloseAutoFocus: (e) => {
                e.preventDefault();
                opener.current?.focus({ preventScroll: true });
              },
            }}
          />
        }
      />
      <p role="status">{message}</p>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <ApiKeyManagerDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Consumer-owned unique-id key records include name, maskedValue, scopes, active/revoked/expired status, exact created/lastUsed/expires time labels, optional native revoke button props/ref and extra actions. Root section props/ref, bounded headingLevel, labels, numeric empty content, create props/ref, creationPending, pendingKeyId and secret/dialog slots are supported. Native handlers can prevent available requests. Pending/revoked/expired actions remain focusable with aria-disabled and reject requests; native disabled button props retain native behavior. The component never generates, retrieves, stores, rotates or revokes keys, and maskedValue must be display-safe metadata. Consumers own authorization, real secrets, one-time reveal/copy UI, confirmations and every backend mutation. The demo uses local non-working records.
