# Errors

Errors on `/v1/*` use the OpenAI format. Branch on the HTTP status and `error.code`; the human-readable `message` may change.

## Format

`type` is a coarse class and is not identical on every endpoint, so rely on `code` and the status.

```json
{
  "error": {
    "message": "...",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}
```

## Codes

| Status | code | When |
| --- | --- | --- |
| 400 | `invalid_request` | Bad JSON or parameters, or a key whose budget is used up. |
| 400 | `model_not_found` | The model is not available, or is not a supported video or music model. |
| 400 | `content_policy_violation` | A video or music task was blocked by content rules. |
| 401 | `invalid_api_key` | Missing, invalid, disabled or expired key. |
| 402 | `insufficient_quota` | Not enough balance for the call or task. |
| 403 | `model_not_allowed` | The model is not in the key's allowlist. |
| 403 | `permission_denied` | The caller IP is not in the key's IP allowlist. |
| 404 | `not_found` | Unknown task id, or one that belongs to another account. Also `video_not_ready` for a video that is not finished. |
| 413 | `invalid_request` | Request body too large. |
| 429 | `rate_limit_exceeded`, `task_limit_reached` | Too many requests, or the task limit was reached when submitting an async task. |
| 5xx | `server_error`, `upstream_error`, `upstream_auth_error`, `no_provider`, `audio_fetch_failed`, `transcription_failed`, `transcript_unavailable`, `upload_failed` | A server or provider problem. 503 `no_provider` means no provider matched the request. |

## Async tasks

For video, music and ffmpeg, a task that fails after being accepted is not an HTTP error: the poll call returns 200 with `status: failed` and an `error` object.
