# Errors, Limits, and Retries

Read error responses and rate-limit headers, retry safely, and diagnose common failures.

Every Felo API returns a JSON error body with a stable error code and a request ID. Read the HTTP status first, then the code, then the message.

## Error envelope

Current production responses use the HTTP status as `status`:

```json
{
  "status": 401,
  "code": "UNAUTHORIZED",
  "message": "Invalid API Key",
  "request_id": "202610221444486982113280416060637185"
}
```

| Field | Meaning |
|-------|---------|
| `status` | HTTP status code, repeated in the body |
| `code` | Machine-readable error code |
| `message` | Human-readable explanation |
| `request_id` | Opaque identifier for this request; include it in support requests |

Some older endpoint examples use `status: "error"` and a different code string. Branch on the HTTP status and `code`, not on the exact wording of `message`.

## Common codes

| HTTP | Code | What it means | What to do |
|------|------|---------------|------------|
| 400 | Endpoint-specific validation code | A parameter is missing or invalid | Fix the request; do not retry unchanged |
| 401 | `UNAUTHORIZED` | Missing, invalid, expired, or revoked API key | Send `Authorization: Bearer $FELO_API_KEY`; rotate the key if revoked |
| 402 | `INSUFFICIENT_CREDITS` | Not enough service credits | Top up in Console Billing, then retry |
| 404 | Endpoint-specific | Unknown model, task, or route | Check the model ID or task ID and the endpoint path |
| 429 | `RATE_LIMITED` | A rate limit was exceeded | Wait for `Retry-After`, then retry |
| 5xx | `CHAT_FAILED`, `*_FAILED`, `SERVICE_UNAVAILABLE` | Upstream or service failure | Retry with backoff; contact support if it persists |

Endpoint references list the codes specific to that endpoint. Start with the [Chat API errors](https://openapi.felo.ai/docs/api-reference/chat.md#error-codes) or the reference for the endpoint you are calling.

## Model generation endpoints

`POST /api/v1/images/generations` and `POST /api/v1/videos/generations` return endpoint-level errors in the OpenAI envelope instead of the envelope above:

```json
{
  "error": {
    "message": "Model kind does not match this generation endpoint",
    "type": "invalid_request_error",
    "param": null,
    "code": "model_kind_mismatch"
  }
}
```

For video generation, `param` names the field that caused the `400`, such as `input`, `first_frame_url`, or `frame_images.0.frame_type`. Legacy fields, unsupported fields, and values the selected channel cannot run are rejected rather than ignored.

The request ID is in the `X-Request-Id` response header, not in the body. A rejected request does not create a task. Once a task exists, most failures arrive as a terminal task status in a `200` response rather than an HTTP error: check `status` for `failed` or `interrupted`, then read `error.message`. See [Image Generation](https://openapi.felo.ai/docs/guides/image-generation.md) and [Async Tasks](https://openapi.felo.ai/docs/guides/async-tasks.md).

## Request IDs

Felo error bodies include `request_id`. Log it with the endpoint, HTTP status, error code, model ID, and task ID. Never log the full API key.

The Model API also accepts an optional `X-Request-Id` request header. When you send one, it is echoed back for diagnostics, which lets you correlate your own logs with a request. If you do not send one, use the returned `request_id`.

## Rate limits

`/v2/chat` is the only Felo endpoint with documented enforced rate limits:

- Per API key, 1-minute window.
- Per user, 1-minute window.
- Per user, 1-hour window.

Users with an effective paid Felo subscription, including enterprise subscriptions, are exempt and receive no `X-RateLimit-*` headers. If subscription status cannot be verified, the limits still apply.

| Header | Meaning |
|--------|---------|
| `X-RateLimit-Limit` | Limit of the tightest dimension currently in effect |
| `X-RateLimit-Remaining` | Minimum remaining quota across the three dimensions |
| `X-RateLimit-Reset` | Unix timestamp in seconds when the current window resets |
| `Retry-After` | On a 429, the recommended delay in seconds |

Other `/v2/**` endpoints currently have no enforced rate limits. Model API requests can still be limited by the upstream provider, which can surface as a 429.

Do not hardcode numeric limits. Read the headers on each response.

## Retry policy

| Situation | Retry? |
|-----------|--------|
| 400, 401, 402, 404 | No. Fix the request, the key, or the balance first. |
| 429 | Yes, after `Retry-After` or `X-RateLimit-Reset`. |
| 5xx, timeouts, connection resets | Yes, with exponential backoff and jitter. |
| Streaming connection dropped mid-response | Retry only if your application can tolerate a duplicate generation. |

Recommended loop:

1. Retry only idempotent or safe-to-repeat requests.
2. Use exponential backoff: start around 1 second, double it, cap at 30 seconds.
3. Add random jitter so clients do not retry in lockstep.
4. Stop after a small number of attempts and surface the error.
5. On 429, honor `Retry-After` instead of your own schedule.

## Debugging sequence

1. Check that the key is present and not revoked.
2. Call `GET /api/v1/models` with the same key to confirm authentication.
3. Send the smallest valid request to the target endpoint.
4. Add streaming, tools, or large inputs one at a time.
5. For async work, check the task status before resubmitting.

## Related

- [Authentication](https://openapi.felo.ai/docs/authentication.md)
- [Why does the same model have different prices?](https://openapi.felo.ai/docs/guides/provider-routing.md)
- [Async Tasks](https://openapi.felo.ai/docs/guides/async-tasks.md)
- [Troubleshooting](https://openapi.felo.ai/docs/faq/troubleshooting.md)
