---
agent:
  instructions: "Search the site by keyword or question. The search API returns Markdown."
  endpoint: "https://platform.invideo.io/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Errors

> API error codes, their causes, and how to respond.

When the API rejects a call, it returns an HTTP error with a JSON body. Most use `{error, message}`. The `invalid_input` error uses `{error, detail}`.

| HTTP | `error` | When | What to do |
| --- | --- | --- | --- |
| 400 | | The body is not valid JSON. | Fix the body. |
| 401 | `unauthorized` | The API key is missing, invalid, disabled or expired. | Check `Authorization: Bearer iv_...`. |
| 404 | `model_not_found` | No such model or mode, or it is off for this workspace. | Check `GET /v1/models`. |
| 404 | `not_found` | No request with this id in this workspace. | Check the id. |
| 410 | `log_expired` | The request's logs are older than 90 days. | |
| 413 | | The body is over 64 MB. | Send large files as an `https` URL. |
| 422 | `invalid_input` | The input does not fit the model's schema. | Read `detail`. |
| 422 | `model_not_priced` | These options have no price yet. | Pick other options. |
| 429 | `rate_limited` | Over the workspace's requests per minute. | Wait `Retry-After` seconds. |
| 402 | `insufficient_balance` | The balance is $0 or less, or less is available than this request's estimated cost. | [Add funds](/docs/billing), then retry. |
| 429 | `spend_limit_exceeded` | A spend limit (daily or monthly; for the workspace, a model or a key) has been reached. | Wait until `resets_at`, or raise the limit in the console. |
| 500 | `server_error` | Something went wrong on our end. Please try again. | Retry with the same `Idempotency-Key`. |

## invalid_input

```json
{
  "error": "invalid_input",
  "detail": [{ "loc": ["body", "input", "duration"], "msg": "must be one of 5, 10", "type": "enum" }]
}
```

`loc` is the path to the field; its last item is the field's name.

## A failed run is not an error

A request that was accepted and then failed answers `200` with `status: "failed"` and an `error` object. See [Requests](/docs/requests#failures).

## Chat completions errors

`POST /v1/chat/completions` and `POST /v1/responses` answer errors in the OpenAI shape, so OpenAI SDKs read them. The Anthropic and Gemini doors answer in their own shapes with the same codes and HTTP statuses: see [Formats and model IDs](/docs/chat/formats#errors).

```json
{ "error": { "type": "invalid_request_error", "code": "context_length_exceeded", "message": "...", "param": "messages" } }
```

| HTTP | `code` | When |
| --- | --- | --- |
| 400 | `invalid_request` | The body does not fit the chat completions shape. |
| 400 | `context_length_exceeded` | The messages are longer than the model's context window. |
| 400 | `max_tokens_too_low` | The answer reached `max_tokens` before it could finish. Charged for the tokens used. |
| 400 | `content_filtered` | The model refused the prompt or stopped its answer. Charged for the tokens used. |
| 400 | `model_not_chat` | The model is not a language model: use `POST /v1/request`. |
| 404 | `model_not_found` | No such model, or it is off for this workspace. |
| 422 | `model_not_priced` | The model has no price yet. |
| 429 | `spend_limit_exceeded` | The workspace's spend limit is used up. |
| 429 | `rate_limited` | Over the workspace's requests per minute. Wait `Retry-After` seconds. |
| 429 | `upstream_rate_limited` | The model is busy. Retry after a short wait. |
| 500 | `internal_error` | Something went wrong on our end. Please try again. |
| 502 | `upstream_error` | The model failed. Retry. |
| 504 | `upstream_timeout` | The model took too long. Retry, or ask for a shorter answer. |

### What a failed chat call costs

- A call that fails because of its own settings (`max_tokens_too_low`, `content_filtered`) is charged for the tokens the model used: the error has `charged_usd` and says so, e.g. "Charged $0.0000858 for 30 tokens used before max_tokens was reached."
- A failure on our side or the model provider's side (`internal_error`, `upstream_*`, `rate_limited`) costs nothing.
- A caller who closes a stream early: the model finishes the answer in the background and the call is charged its real tokens.
