> ## 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.

# Voice Agents API Errors

> Status codes, error shapes, and recovery guidance for every /v1/agent endpoint

Errors from `/v1/agent/*` come back as JSON with a `status` and a `message`:

```json theme={null}
{ "status": 404, "message": "Agent not found" }
```

The exceptions to that shape:

* **Validation failures** (`422`) return pydantic's error list, one entry per problem. Offending input values are stripped, so write-only credentials are never echoed back:

  ```json theme={null}
  [
    {
      "type": "value_error",
      "loc": ["body", "prompt", "system_prompt"],
      "msg": "Value error, system_prompt exceeds 64000 tokens (got 65001)",
      "ctx": { "error": "system_prompt exceeds 64000 tokens (got 65001)" }
    }
  ]
  ```

* **Phone-call creation** ([`POST /v1/agent/phone-calls`](https://docs.fish.audio/api-reference/endpoint/agent/create-phone-call)) adds a machine-readable `reason` field to its errors; see [Outbound calls](https://docs.fish.audio/agents/telephony/outbound-calls.md#errors) for the full list.

* **A reached [limit](https://docs.fish.audio/agents/pricing.md#limits)** is named in a machine-readable field. A phone number over the limit returns `403` with the reason `phone_number_limit_reached` next to `status` and `message`. Session creation with every line in use returns `429` with `code`, `message`, and `retry_after`, and no `status`.

* A request body that isn't valid JSON returns `400` with `"Malformed JSON"`; a missing body or wrong `Content-Type` returns a bare `415`.

* A missing or malformed `Authorization` header returns a bare `401` with a `WWW-Authenticate: Bearer` header; a present-but-bad credential returns the JSON shape (`"Invalid token"`, `"Token expired"`).

## Status codes

| Status | Meaning | What to do |
| - | - | - |
| `400` | The request is well-formed JSON but semantically wrong | Read the `message`; it names the field or rule. |
| `401` | Missing, invalid, or expired API key | Send `Authorization: Bearer <key>`; check it on [API Keys](https://fish.audio/app/api-keys). |
| `402` | Out of API credit | Top up. Only session creation and phone-number purchase charge up front, so a `402` never leaves a partial charge. |
| `403` | The action is not allowed for this caller | See [403 causes](#403-what-was-refused) below. |
| `404` | The resource doesn't exist, or isn't yours | Cross-team access returns the same `404` as a missing id, so treat both identically. |
| `409` | A state conflict blocks the action | See [409 conflicts](#409-conflicts) below. |
| `415` | Missing body or wrong `Content-Type` | JSON endpoints need `application/json`; knowledge-source uploads need `multipart/form-data`. |
| `422` | Field-level validation failed | Fix the fields listed in the error array. |
| `429` | A [limit](https://docs.fish.audio/agents/pricing.md#limits) was reached, or public session creation is rate limited | Retry after the `retry_after` delay when the response carries one. See [Billing and rate limits](#billing-and-rate-limits). |
| `502` | An upstream dependency (conversation gateway, telephony provider) failed | Retry; for a failed phone-number purchase the row stays visible with status `error` and is safe to release. |
| `503` | A platform dependency is temporarily unavailable | Retry with backoff. |

## 400 vs 422

`422` is field-level validation: unknown fields (the public surface rejects them), length caps, enum values, invalid IANA timezones, dynamic-variable naming. `400` is semantic: an [override](https://docs.fish.audio/agents/deploy/authenticated-sessions.md#overrides) not enabled for the agent, mutually exclusive pagination parameters (`page` + `cursor`), an undecodable cursor, a page offset past 100,000 rows, or a knowledge upload that isn't UTF-8 plain text.

Two quirks worth coding around:

* **Explicit `null` is rejected** on most `PATCH` fields with `422`: omit a field to keep its value, send `""` to clear a text field. Write-only secrets (`llm.custom.api_key`, webhook `secret`) treat `null` like omission and keep the stored value.
* **Path-parameter validation renders `404`, not `422`**: a non-integer `{version_number}` looks like a missing version.

## 403: what was refused

| Message | Cause |
| - | - |
| `Agent is not public` | Anonymous session/widget request against an agent whose public switch is off. |
| `Origin header is required for public agents` | Anonymous request without an `Origin` header to an agent that restricts origins. Browsers send it automatically, curl must set it. |
| `Origin not allowed` | The agent [restricts origins](https://docs.fish.audio/agents/deploy/public-agents.md#restrict-origins) and the page's origin is not on the list. |
| `Agent is unavailable` | The agent's owner can't serve public sessions right now for a reason other than credit (that is `402`); visitors deliberately can't tell why. |
| `Phone number limit reached for this team (N)` | The team holds as many numbers as it may, which is one on a free account. The body also carries the reason `phone_number_limit_reached`. Add API credit to end the free account limit, or release a number. See [Limits](https://docs.fish.audio/agents/pricing.md#phone-numbers). |

## 404: anti-enumeration

A resource that exists but belongs to another team returns the **identical** `404` body as one that never existed. This applies to agents, sessions, tools, knowledge sources, phone numbers, and versions. Released phone numbers and deleted knowledge sources behave the same. Never use `404` vs `403` to probe for existence.

The recording endpoint adds one more meaning: `Recording not found` on a real session means it was [never recorded](https://docs.fish.audio/agents/monitor/conversation-history.md#what-gets-stored).

## 409: conflicts

| Message | Cause and fix |
| - | - |
| `Agent has no published version` | Session creation against a never-published agent: [publish](https://docs.fish.audio/agents/deploy/versions-publishing.md) first. |
| `Knowledge source is attached to N agent(s)…` | Deletion is blocked while any agent references the source in its draft **or published** config: detach everywhere, republish, then delete. |
| `Tool is attached to N agent(s)…` | Deletion is blocked while any agent's **draft** references the tool (published snapshots are frozen copies and don't block): detach, then delete. |
| `This number is already on the platform` | The number is held by a team already; pick another from [search](https://docs.fish.audio/api-reference/endpoint/agent/search-available-phone-numbers.md). |

## Billing and rate limits

Exactly two endpoints charge before acting, and both can return `402 Out of API credit`: [`POST /v1/agent/sessions`](https://docs.fish.audio/api-reference/endpoint/agent/create-agent-session) (API-key and anonymous public callers alike) and [`POST /v1/agent/phone-numbers`](https://docs.fish.audio/api-reference/endpoint/agent/purchase-phone-number) (the first rental day). A public session whose agent owner is out of credit gets the same `402`, which the [Web SDK](https://docs.fish.audio/agents/deploy/web-sdk.md#errors) reports as `insufficient_credit`. Usage is settled after each call and never fails a request.

`429` means a limit was reached. The first two are described under [Limits](https://docs.fish.audio/agents/pricing.md#limits).

| Cause | Where | Body |
| - | - | - |
| Every concurrent line of the team is in use | Session creation, outbound calls | `code` or `reason` is `concurrency_limit_exceeded`, with `retry_after` |
| Outbound calls started faster than the team's dial rate | Outbound calls | `reason` is `cps_limit_exceeded`, with `retry_after` |
| The fixed per-minute windows per agent and per client IP | Anonymous session creation on [public agents](https://docs.fish.audio/agents/deploy/public-agents.md) | `status` and `message` |

Apart from these, API-key traffic is not rate limited on this surface.

## 5xx

`502` names the failing upstream in the message: the conversation gateway (`Agent gateway is unreachable`) or the telephony provider (`Twilio refused the request: …`). Retrying is safe. A failed phone-number purchase leaves the row visible with status `error`, refunds the day charge, and can be released; a failed release keeps the number live so releasing again retries. `503` means a platform dependency was briefly unreachable; retry with backoff.

## Going further

> [card] [Authenticated sessions](https://docs.fish.audio/agents/deploy/authenticated-sessions.md)
>
> The session token flow: request fields, lifetime, errors.

> [card] [Public agents](https://docs.fish.audio/agents/deploy/public-agents.md)
>
> Origin allowlists and the errors unique to keyless access.


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