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

# Errors

> Status codes, error bodies, and how to handle them

Errors that occur before streaming begins are ordinary JSON responses:

```json theme={null}
{
  "statusCode": 401,
  "message": "Invalid API key",
  "error": "Unauthorized"
}
```

* `statusCode` - the HTTP status, repeated in the body.
* `message` - a human-readable description. For validation errors this is an
  **array** of strings, one per problem.
* `error` - the status text. Present on most errors; treat it as optional.
* `code` - a stable machine-readable identifier, present only on the errors
  that define one (`idempotency_key_reused`, `model_unavailable`,
  `model_input_unsupported`).
  Those bodies carry `message` and `code` only, without `statusCode` or
  `error`, so always key off the HTTP status first.

Failures after streaming has begun arrive as an `error` frame inside the
200 stream instead - see [Streaming](https://docs.f13.com/streaming.md#failure-modes-to-handle).

## Status codes

| Status | Meaning | What to do |
| - | - | - |
| `400` | Invalid request - a validation failure (for example a missing prompt, one over 2,000 characters, or a reference image that is not a supported HTTPS or data URL), an unknown `parentAssetId`, or a malformed `Idempotency-Key`. | Fix the request. The `message` array names each failed constraint. |
| `401` | Missing, invalid, or revoked API key. | Check the `Authorization` header and the key's status in the dashboard. |
| `402` | The workspace cannot be charged: it is out of credits (`"Out of credits - add credits from the billing page to continue."`) or a payment on it is under dispute (generation is paused until the dispute is resolved). | Add credits in the [dashboard](https://app.f13.com) billing page, then retry; for a dispute, contact support. |
| `403` | The model the request names (`model`), or the one the workspace is set to, is not available to it (`code` is `model_unavailable`). Nothing was charged. | For a named model, pick one from `GET /v1/models`; otherwise do not retry, contact support. |
| `409` | A request with the same `Idempotency-Key` is still in progress. | Wait for the original to finish, then retry the same key to receive its stored result. |
| `422` | The `Idempotency-Key` was already used with a different request body (`code` is `idempotency_key_reused`), or the workspace's model does not take what was sent: an edit (`parentAssetId`), more reference images than it takes (some take none), or (on models that need one) no prompt (`code` is `model_input_unsupported`). A model's `capabilities` in `GET /v1/models` list what it takes. Nothing was charged. | Send the new request under a new key; for `model_input_unsupported`, drop what the model does not take. |
| `429` | Rate limit exceeded - per-key or per-workspace, per minute or (for a workspace with a per-second limit) per second. Or, for a workspace with a concurrency limit, that many generations are already in progress (`code` is `concurrency_limit_exceeded`, `limit` is the number; `Retry-After: 1`). Nothing was charged. | Wait the number of seconds in the `Retry-After` header, then retry. For `concurrency_limit_exceeded`, a place frees as soon as one of the generations in progress ends. |
| `503` | Not right now: the billing row is busy under a burst of concurrent generations. Nothing was charged. | Wait the seconds in `Retry-After`, then retry with the same key. |
| `5xx` | Anything else failed on our side. | Retry with backoff, reusing the same `Idempotency-Key` so a request that did complete is not billed twice. |

### Example: validation error

```json theme={null}
{
  "statusCode": 400,
  "message": ["prompt should not be empty"],
  "error": "Bad Request"
}
```

### Example: rate limited

```http theme={null}
HTTP/1.1 429 Too Many Requests
Retry-After: 12

{"statusCode":429,"message":"Rate limit exceeded"}
```

### Example: concurrency limit reached

```http theme={null}
HTTP/1.1 429 Too Many Requests
Retry-After: 1

{"message":"This workspace runs at most 5 generations at once and that many are in progress. Retry when one finishes. You were not charged.","code":"concurrency_limit_exceeded","limit":5}
```

### Example: idempotency key reused

```json theme={null}
{
  "message": "This Idempotency-Key was already used with a different request body. Use a new key for a new request.",
  "code": "idempotency_key_reused"
}
```

## Retry guidance

* Honor `Retry-After` on `429` and `503` rather than retrying immediately.
* Use an [`Idempotency-Key`](https://docs.f13.com/api-reference/introduction#idempotency) on
  every request you might retry - it makes retries after timeouts, dropped
  connections, and `5xx` responses safe.
* Do not retry `400`, `401`, `402`, or `422` unchanged; they will fail the
  same way until the underlying problem is fixed.


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