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

# Errors

> Status codes, error bodies and what to do with each error returned by the Magnific API

The Magnific API uses standard HTTP status codes. A `2xx` code means the request worked, a `4xx` code means something in the request has to change, and a `5xx` code means the problem is on our side.

## Error body

Error responses are JSON objects with a human-readable `message` and the `request_id` of the request:

```json theme={null}
{
  "request_id": "ak-97f5c07b9dd04324842b8f8b55a0edf1",
  "message": "Insufficient credits",
  "invalid_params": []
}
```

| Field | Description |
| :- | :- |
| `request_id` | Identifier of this HTTP request. Include it when you contact support. |
| `message` | What went wrong. It is meant for people: the text can change, so base your error handling on the status code. |
| `invalid_params` | Only on some errors. For validation errors, it lists each invalid field and the reason. |

> [!NOTE]
>
> A few errors, such as a request to an unknown path, return the description in `detail` instead of `message`. Read `message` first and fall back to `detail`.

### Validation errors

When the request body or its parameters are not valid, the API answers `400 Bad Request` with `Content-Type: application/problem+json` and one entry per invalid field:

```json theme={null}
{
  "request_id": "ak-97f5c07b9dd04324842b8f8b55a0edf1",
  "message": "Validation error",
  "invalid_params": [
    {
      "field": "body.prompt",
      "reason": "Field required"
    }
  ]
}
```

## Request ID

Every response carries the request ID in the `X-Request-Id` header, and error responses also include it in the body as `request_id`. Both hold the same value. When you contact [support](mailto:api@magnific.com) about a failed request, send us its `request_id`: it lets us find that exact request. We generate the ID for every request; log it on your side next to your own request identifiers.

> [!WARNING]
>
> The `request_id` identifies an **HTTP request**, not a task. To follow a generation task, use the `task_id` returned when you create it. The [webhook](https://docs.magnific.com/webhooks.md) body also has a `request_id` field, but there it holds the task ID (the same value as `task_id`) and is not related to the `request_id` of errors.

## Status codes

| Code | Meaning | What to do |
| :-: | :- | :- |
| `400` | **Bad request.** A parameter is missing or not valid. | Fix the fields listed in `invalid_params` (or described in `message`) and send the request again. |
| `401` | **Unauthorized.** The API key is missing or not valid. | Send a valid key in the `x-magnific-api-key` header. See [Authentication](https://docs.magnific.com/authentication.md). |
| `402` | **Payment required.** You do not have enough credits for this request. | Add credits or upgrade your plan, then retry. |
| `403` | **Forbidden.** Your key is valid but cannot use this endpoint or model: your plan does not include it, the endpoint requires another subscription, or access from your IP address is not allowed. | Check your plan and your API key settings. Retrying does not help. |
| `404` | **Not found.** The path does not exist, or no task was found with that ID. | Check the URL and the `task_id`. |
| `410` | **Gone.** The endpoint has been retired. | Move to the replacement listed in the [changelog](https://docs.magnific.com/changelog/2026.md). |
| `422` | **Unprocessable.** The model or tool could not be resolved for your account. | Contact [support](mailto:api@magnific.com) with the `request_id`. |
| `429` | **Too many requests.** You exceeded a rate limit or the quota of your plan. | Wait and retry with backoff. See [Rate limiting](https://docs.magnific.com/ratelimits.md). |
| `500` | **Internal server error.** Something failed on our side. | Retry with backoff. If it persists, contact support with the `request_id`. |
| `502` | **Bad gateway.** A service behind the API, such as the model provider, failed. | Retry with backoff. |
| `503` | **Service unavailable.** The service is temporarily unable to take the request. | Retry with backoff. |
| `504` | **Gateway timeout.** A service behind the API took too long to answer. | Retry with backoff (see the note on retrying `POST` requests below). |

## Retrying requests

Retry only the errors that can succeed later: `429`, `500`, `502`, `503` and `504`. Wait longer between attempts (for example 1, 2, 4 and 8 seconds) and stop after a few attempts. Other `4xx` errors return the same answer until you change the request.

> [!WARNING]
>
> A `502` or `504` on a `POST` that creates a task does not always mean the task was not created: the request may have reached the model before the error. Before you retry, list your recent tasks with the `GET` endpoint of the same model to avoid creating, and paying for, the same task twice.

## Failed tasks

An error status code means the request itself failed. A task that was created correctly can still fail later while it runs: in that case the `GET` endpoint of the task, and the [webhook](https://docs.magnific.com/webhooks.md) if you set one, return the task with `status: FAILED`. Use the `task_id` when you ask us about a failed task.


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