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

# Errors

> Error format, status codes, and what to do about each one.

A request that cannot be accepted returns a JSON error with a stable `code`:

```json theme={null}
{ "error": { "code": "bad_request", "message": "size must be one of: 1:1, 4:3, 3:4, 16:9, 9:16, 3:2, 2:3" } }
```

## Request errors

| HTTP | `code` | Meaning | What to do |
| - | - | - | - |
| 400 | `bad_request` | A field is missing, out of range or not supported by the model | Read `message`; it names the field |
| 401 | `unauthorized` | No key, a wrong key or a revoked key | Check the `Authorization` header |
| 402 | `insufficient_credits` | The balance does not cover the task | Add credits. Nothing was started or charged |
| 404 | `not_found` | Unknown model, unknown task id, or a task that belongs to another account | Check the model name and the id |
| 405 | `method_not_allowed` | Wrong HTTP method | Create with `POST`, read with `GET` |
| 429 | `rate_limited` | Too many requests, or five tasks already running | Wait for the seconds in `Retry-After` |
| 502 | `bad_gateway` | The service could not complete the request | Retry after a short pause |

## Task errors

A task can be accepted and still fail while it runs. The HTTP status is 200 and the task carries the reason:

```json theme={null}
{
  "code": 200,
  "data": {
    "id": "task_82e7b2d4c77fc139f0dab1abc431e6e0",
    "status": "failed",
    "cost": 0,
    "credits_cost": 0,
    "error": { "code": "generation_failed", "message": "Generation failed" }
  }
}
```

| `error.code` | Meaning |
| - | - |
| `generation_failed` | The model did not produce an output. This includes prompts the safety filter rejects |
| `timed_out` | The task did not finish within 20 minutes |

A failed task is always refunded in full. It is safe to create the task again.


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