> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fish.audio/llms.txt
> Use this file to discover all available pages before exploring further.

# API Key Types, Scopes, and Spend Limits

> Configure Classic vs Scoped API keys, least-privilege RBAC scopes, and per-key USD spend caps

Fish Audio supports two API key types — **Scoped** and **Classic** — along with per-key USD spend limits and a self-introspection endpoint so you can enforce least-privilege access and cap usage per service or environment.

Manage your keys on [API Keys](https://fish.audio/app/api-keys/).

## Classic vs. Scoped API keys

| Capability | Scoped (`scoped`) | Classic (`classic`) |
| - | - | - |
| Permission model | Explicit allowlist of one or more scopes | Broad default access (all scopes except `tokens:mint` and `audit_log:read`) |
| Mint ephemeral `ek-fish-` tokens (`POST /v1/auth/tokens`) | Allowed when granted `tokens:mint` plus the target inference/session scope | Not allowed (`403 classic_key_cannot_mint`) |
| Read team audit logs (`GET /v1/audit-logs`) | Allowed when granted `audit_log:read` (owner/admin only) | Not allowed |
| Edit scopes after creation | Supported in the console | Not supported |
| Per-key USD spend limit | Supported | Supported |
| Self-introspection (`GET /apikey/self`) | Supported | Supported |

> [!TIP]
>
> Use **Scoped** keys for production workloads and any backend that mints
> [ephemeral tokens](https://docs.fish.audio/developer-guide/getting-started/ephemeral-tokens.md). Reserve
> **Classic** keys for quick prototyping or existing integrations that expect
> broad access.

## API key scopes

Every scoped API key carries one or more flat `resource:action` scopes. Compatible API endpoints (such as `/v1/audio/speech`, `/v1/audio/transcriptions`, and `/v1/chat/completions`) require the scope of their underlying inference product (`tts:write` for speech/chat, `stt:write` for transcriptions).

| Scope | Category | Covers | Ephemeral-capable | Admin-only |
| - | - | - | - | - |
| `tts:write` | Inference | `POST /v1/tts`, `POST /v1/tts/stream/with-timestamp`, `POST /v1/audio/infill`, `WS /v1/tts/live`, `WS /v1/tts/live/with-timestamp`, pronunciation previews, compatible speech/chat endpoints, and reading individual voice models (`GET /model/{id}`) or pronunciation dictionaries | Yes | No |
| `stt:write` | Inference | `POST /v1/asr`, `WS /v1/asr/realtime`, and compatible transcription endpoints | Yes | No |
| `voice_design:write` | Inference | `POST /v1/voice-design` | Yes | No |
| `realtime:write` | Inference | Realtime inference endpoints under `/v1/realtime` and realtime TTS backends | Yes | No |
| `models:read` | Models | List and inspect voice models (`GET /model`, `GET /model/{id}`) and read pronunciation dictionaries | No | No |
| `models:write` | Models | Create, update, and delete voice models (`POST /model`, `PATCH /model/{id}`, `DELETE /model/{id}`) and write pronunciation dictionaries | No | No |
| `agents:read` | Voice Agents | Read agents, versions, deployments, tools, knowledge sources, tests, phone numbers, sessions, and recordings | No | No |
| `agents:write` | Voice Agents | Create, update, publish, roll back, and delete agents, tools, knowledge sources, tests, and phone numbers (also satisfies ending sessions and outbound calls) | No | No |
| `agents:session` | Voice Agents | Start and end live agent sessions (`POST /v1/agent/sessions`, `POST /v1/agent/sessions/{session_id}/end`) and place outbound phone calls | Reserved (gateway routes only; REST `/v1/agent/sessions` uses `sk-fish-`) | No |
| `tokens:mint` | Auth | Mint single-use `ek-fish-` tokens via [`POST /v1/auth/tokens`](https://docs.fish.audio/api-reference/endpoint/apikey/mint-ephemeral-token); must be paired with at least one ephemeral-capable scope | No | No |
| `billing:read` | Admin | Read API credit balance and package usage (`GET /wallet/{user_id}/api-credit`, `GET /wallet/{user_id}/package`) | No | Yes |
| `audit_log:read` | Admin | Pull team audit logs into a SIEM (`GET /v1/audit-logs`); requires Scale, Enterprise, or approved audit-log access | No | Yes |

> [!NOTE]
>
> For browser or mobile voice-agent clients, create a session on your backend
> with your `sk-fish-` key via `POST /v1/agent/sessions` (which issues its own
> short-lived client join token); see [Authenticated
> Sessions](https://docs.fish.audio/agents/deploy/authenticated-sessions.md).

### Admin-only scopes and editing scopes

* Only team **owners** and **admins** can create, edit, or delete a scoped key that grants `billing:read` or `audit_log:read`.
* You can edit the scopes of an existing **Scoped** key at any time from [API Keys](https://fish.audio/app/api-keys/). Changes take effect immediately for `POST /v1/auth/tokens` and ephemeral token redemption, and within **60 seconds** on cached inference gateway routes.
* A non-admin team member editing another member's scoped key cannot widen its scope set.
* Classic keys cannot be converted to scoped keys or assigned explicit scopes; create a new scoped key and rotate instead.

## Per-key USD spend limits

You can set an optional USD spend cap when creating any Classic or Scoped key to bound costs per service, environment, or customer integration. Editing, removing, or resetting a spend cap on an existing key requires team **owner** or **admin** role:

* **Range:** `$0.01` to `$1,000,000,000.00` (rounded to 2 decimal places).
* **Reset cadence (UTC, defaults to `monthly` when omitted):**
  * `daily` — resets at `00:00 UTC` every day
  * `weekly` — resets on Monday at `00:00 UTC`
  * `monthly` — resets on the 1st of each month at `00:00 UTC`
  * `never` — cumulative lifetime cap until raised or manually reset
* **Unified attribution:** Usage from both direct `sk-fish-` requests and any `ek-fish-` ephemeral tokens minted by that key counts toward the parent key's spend limit.
* **Manual reset:** Team owners and admins can reset the current window's spend counter to `$0.00` at any time using **Reset spend** on [API Keys](https://fish.audio/app/api-keys/).

When a key reaches its limit:

* New HTTP requests and WebSocket upgrades return **`402 Payment Required`** (`api_key_spend_limit_exceeded`).
* Calling `POST /v1/auth/tokens` fails fast with **`402`** (`code: "api_key_spend_limit_exceeded"`).
* Active WebSocket inference sessions that cross the limit mid-stream are closed cleanly at a frame boundary with WebSocket close code **`4002`** (reason `api_key_spend_limit_exceeded`).

> [!NOTE]
>
> Streaming inference usage is settled in short batches, so actual spend can
> slightly exceed the configured cap by the in-flight request or settlement
> window.

## Inspecting your key programmatically

Any valid Classic or Scoped key can inspect its own type, effective scopes, expiration, and live spend-limit balance by calling [`GET /apikey/self`](https://docs.fish.audio/api-reference/endpoint/apikey/get-self-api-key). No additional scope is required.

```bash theme={null}
curl https://api.fish.audio/apikey/self \
  -H "Authorization: Bearer $FISH_API_KEY"
```

## Handling scope and spend errors

Error responses differ depending on whether the check runs at the inference edge gateway or the platform API:

### Inference edge gateway (`/v1/tts`, `/v1/asr`, `/v1/asr/realtime`, `/v1/tts/live`, `/v1/voice-design`)

Gateway errors keep the JSON body fixed to `{"status": <int>, "message": <string>}` for SDK compatibility and put machine-readable codes in response headers:

| HTTP Status | `x-fish-error-code` header | Extra headers | Meaning |
| - | - | - | - |
| `402` | `api_key_spend_limit_exceeded` | `x-fish-error-source: gateway` | The API key (or ephemeral token's parent key) reached its USD spend limit. |
| `403` | `insufficient_scope` | `x-fish-error-source: gateway`, `x-fish-required-scope: <scope>` | The scoped key or ephemeral token lacks the scope required by this endpoint. |

### Platform API (`/v1/auth/tokens`, `/model/*`, `/wallet/*`, `/v1/agent/*`, `/v1/pronunciation-dictionaries/*`)

Platform API scope and spend errors return structured JSON fields (note that `GET /v1/audit-logs` returns `{"status": 403, "message": "This endpoint requires an API key with the audit_log:read scope."}` instead):

```json 403 Missing scope theme={null}
{
  "code": "api_key_scope_forbidden",
  "required_scope": "models:write",
  "required_scopes": ["models:write"],
  "message": "This API key is missing required scope: models:write."
}
```

```json 402 Spend limit exceeded (POST /v1/auth/tokens) theme={null}
{
  "code": "api_key_spend_limit_exceeded",
  "message": "API key spend limit exceeded for the current reset window.",
  "limit_usd": "25.00",
  "spent_usd": "25.04",
  "resets_at": "2026-12-05T00:00:00+00:00"
}
```

## Next steps

> [card] [Ephemeral Tokens](https://docs.fish.audio/developer-guide/getting-started/ephemeral-tokens.md)
>
> Mint single-use ek-fish- tokens for browsers, mobile, and desktop clients.

> [card] [Get Current API Key](https://docs.fish.audio/api-reference/endpoint/apikey/get-self-api-key.md)
>
> Monitor scopes and spend-limit remaining budget via GET /apikey/self.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.