# Errors

> The error envelope and every error code, with what it means and what to do.

## The envelope

Every error, on every endpoint, has the same shape and the HTTP status of its code:

```json
{
  "error": {
    "code": "not_found",
    "message": "Nothing was found here.",
    "retryable": false,
    "retry_after_seconds": null,
    "details": {},
    "docs_url": "https://imgsearch.com/developers/errors#not_found",
    "request_id": "01JCEXAMPLEREQUEST000000000"
  }
}
```

- `code` is what your code reads. New codes may be added within v2; treat one you do not know by its HTTP status.
- `message` is plain words for a person. Show it, but never parse it.
- `retryable` says whether the same request can succeed later. Retry only when it is true, and after `retry_after_seconds` when that is set.
- `details` is always an object; each code below lists the keys it can carry.
- `docs_url` links to the code’s section on this page.
- `request_id` is also the `X-Request-Id` header. Quote it when you write to support.

## Retry-After and WWW-Authenticate

- Whenever `retry_after_seconds` is set, the `Retry-After` header carries the same number of seconds.
- A `401` carries `WWW-Authenticate: Bearer realm="ImgSearch API"`, with `error="invalid_token"` when a token was sent.
- A `405` carries `Allow` with the methods the path takes.

## Validation

A request that does not pass validation answers `422 invalid_request` with `details.fields`: each field as you sent it (`max_usd`, `reference.url`, `Idempotency-Key`, `cursor`, …) and its messages.

```json
{
  "error": {
    "code": "invalid_request",
    "message": "The request is not valid.",
    "retryable": false,
    "retry_after_seconds": null,
    "details": {"fields": {"max_usd": ["Send max_usd: the most US dollars the user allows this generation to cost."]}},
    "docs_url": "https://imgsearch.com/developers/errors#invalid_request",
    "request_id": "01JCEXAMPLEREQUEST000000000"
  }
}
```

A body that is not valid JSON answers `422` too.

## Request bodies

A JSON body may be up to 256 KiB long, with at most 1,024 member names (those of nested objects count), each name at most 128 bytes, and at most 4,096 values (every list, every object and every item in one). The calls of this API are a few kilobytes, so none comes near these numbers. The counts read the body as text: a comma, a bracket or a quote before a colon inside a string counts as well.

A body over any of them is not read. It answers `422 invalid_request` with a message that starts "The request is too large" and names the four numbers, and with empty `details`. Sending it again unchanged gets the same answer: make it smaller. The same holds for a body that starts with `{` or `[` under another content type.

Pictures do not travel as JSON. Send one as a multipart form to `POST /uploads`, or as raw bytes with the picture’s own content type to an upload link; each has its own size limit.

The MCP server has the same limits and answers a JSON-RPC error (`-32600`) with HTTP status `413`.

## Codes

| Code | HTTP status |
|---|---|
| [`unauthenticated`](https://imgsearch.com/developers/errors.md#unauthenticated) | 401 |
| [`token_expired`](https://imgsearch.com/developers/errors.md#token_expired) | 401 |
| [`token_revoked`](https://imgsearch.com/developers/errors.md#token_revoked) | 401 |
| [`insufficient_scope`](https://imgsearch.com/developers/errors.md#insufficient_scope) | 403 |
| [`spending_not_enabled`](https://imgsearch.com/developers/errors.md#spending_not_enabled) | 403 |
| [`email_not_verified`](https://imgsearch.com/developers/errors.md#email_not_verified) | 403 |
| [`adult_confirmation_required`](https://imgsearch.com/developers/errors.md#adult_confirmation_required) | 403 |
| [`safety_locked`](https://imgsearch.com/developers/errors.md#safety_locked) | 403 |
| [`access_blocked`](https://imgsearch.com/developers/errors.md#access_blocked) | 403 |
| [`region_unavailable`](https://imgsearch.com/developers/errors.md#region_unavailable) | 403 |
| [`forbidden`](https://imgsearch.com/developers/errors.md#forbidden) | 403 |
| [`not_found`](https://imgsearch.com/developers/errors.md#not_found) | 404 |
| [`method_not_allowed`](https://imgsearch.com/developers/errors.md#method_not_allowed) | 405 |
| [`content_refused`](https://imgsearch.com/developers/errors.md#content_refused) | 422 |
| [`invalid_request`](https://imgsearch.com/developers/errors.md#invalid_request) | 422 |
| [`plan_required`](https://imgsearch.com/developers/errors.md#plan_required) | 402 |
| [`insufficient_balance`](https://imgsearch.com/developers/errors.md#insufficient_balance) | 402 |
| [`spend_cap_reached`](https://imgsearch.com/developers/errors.md#spend_cap_reached) | 402 |
| [`storage_full`](https://imgsearch.com/developers/errors.md#storage_full) | 403 |
| [`price_above_max`](https://imgsearch.com/developers/errors.md#price_above_max) | 409 |
| [`idempotency_conflict`](https://imgsearch.com/developers/errors.md#idempotency_conflict) | 409 |
| [`not_cancelable`](https://imgsearch.com/developers/errors.md#not_cancelable) | 409 |
| [`still_running`](https://imgsearch.com/developers/errors.md#still_running) | 409 |
| [`asset_changed`](https://imgsearch.com/developers/errors.md#asset_changed) | 409 |
| [`conflict`](https://imgsearch.com/developers/errors.md#conflict) | 409 |
| [`rate_limited`](https://imgsearch.com/developers/errors.md#rate_limited) | 429 |
| [`too_many_active`](https://imgsearch.com/developers/errors.md#too_many_active) | 429 |
| [`checks_busy`](https://imgsearch.com/developers/errors.md#checks_busy) | 429 |
| [`fair_use_reached`](https://imgsearch.com/developers/errors.md#fair_use_reached) | 429 |
| [`model_paused`](https://imgsearch.com/developers/errors.md#model_paused) | 503 |
| [`daily_capacity`](https://imgsearch.com/developers/errors.md#daily_capacity) | 503 |
| [`busy`](https://imgsearch.com/developers/errors.md#busy) | 503 |
| [`safety_check_unavailable`](https://imgsearch.com/developers/errors.md#safety_check_unavailable) | 503 |
| [`generator_disabled`](https://imgsearch.com/developers/errors.md#generator_disabled) | 503 |
| [`api_disabled`](https://imgsearch.com/developers/errors.md#api_disabled) | 503 |
| [`server_error`](https://imgsearch.com/developers/errors.md#server_error) | 500 |
| [`file_unavailable`](https://imgsearch.com/developers/errors.md#file_unavailable) | 503 |

### unauthenticated

HTTP 401.

The request carried no API key or OAuth token, or one that is not valid.

**What to do:** Send a working key or token as "Authorization: Bearer …". Do not retry the same request unchanged.

### token_expired

HTTP 401.

The key or token has expired.

**What to do:** For a key, ask the account holder to make a new one on Account → API keys. An app refreshes its token or signs the person in again.

### token_revoked

HTTP 401.

The key or token was revoked on the website.

**What to do:** Stop using it. Ask the account holder for a new key, or sign the person in again.

### insufficient_scope

HTTP 403.

The key or token does not carry the scope this endpoint needs.

**What to do:** Ask the account holder for a key with that scope (details.required names it); a key's scopes never change. An app connects again to ask for more.

**Details:** `required`.

### spending_not_enabled

HTTP 403.

This key or app may not spend AI balance now: its spending was stopped on the website, or spending is not open. (A key made without spending answers insufficient_scope instead.)

**What to do:** Tell the user. The account holder can allow spending on the page at details.settings_url (left out for ChatGPT). Do not retry until then.

**Details:** `settings_url`.

### email_not_verified

HTTP 403.

The account's email address is not verified yet.

**What to do:** Ask the user to verify their email address on the website, then try again.

### adult_confirmation_required

HTTP 403.

This needs the account holder's one-time confirmation that they are 18 or older, which is missing.

**What to do:** Ask the user to confirm it on the website.

### safety_locked

HTTP 403.

Generating is locked for this account after repeated safety refusals: paused until a date, paused until a person reviews it, or ended.

**What to do:** Stop generating and tell the user. details.locked_until (UTC) says until when; both locked_until null and banned false mean a pause until review; banned true means it has ended, so never retry. Searching and downloads still work.

**Details:** `locked_until`, `banned`.

### access_blocked

HTTP 403.

This account, a group of accounts it belongs to, or its network is blocked; the message gives the reason.

**What to do:** Stop and show the user the message. They can write to support at details.support_url.

**Details:** `support_url`.

### region_unavailable

HTTP 403.

This model is not offered in the account's country, or the account's country is not known.

**What to do:** Choose another model of the same kind; details.model names this one.

**Details:** `model`.

### forbidden

HTTP 403.

The request is not allowed for this account.

**What to do:** Do not retry it as it is.

### not_found

HTTP 404.

Nothing is at this path or id, or it belongs to another account.

**What to do:** Check the path and the id. An item may also have been withdrawn since you found it: search again.

### method_not_allowed

HTTP 405.

This path does not take that HTTP method.

**What to do:** Use a method from the Allow header (details.allowed_methods). A file or link answers only GET.

**Details:** `allowed_methods`.

### content_refused

HTTP 422.

The content checks refused the request: the prompt, a caption or a picture.

**What to do:** Tell the user what was refused (details.field names the part). Never rephrase it or retry it on your own.

**Details:** `field`.

### invalid_request

HTTP 422.

The request is not valid: a missing or wrong field, a body that is not JSON, or a cursor from another list.

**What to do:** Fix the fields named in details.fields and send it again.

**Details:** `fields`.

### plan_required

HTTP 402.

Generating needs a paid plan or AI balance the account bought.

**What to do:** Tell the user. Do not retry until the account has a paid plan or bought AI balance.

### insufficient_balance

HTTP 402.

The account's AI balance is lower than this costs.

**What to do:** Tell the user: details.needed_usd is the price, details.available_usd what the account can spend and details.held_usd what waits for a paid plan, all in US dollars. Do not retry until they have more.

**Details:** `needed_usd`, `available_usd`, `held_usd`.

### spend_cap_reached

HTTP 402.

This would go over the spending limit set for this key or app.

**What to do:** Tell the user. details.limit is monthly (wait for details.resets_at, or ask the account holder to raise the limit) or per_job (choose a cheaper job). details.cap_usd and details.spent_usd are in US dollars.

**Details:** `limit`, `cap_usd`, `spent_usd`, `resets_at`.

### storage_full

HTTP 403.

The account's storage for its creations is full. Nothing was charged.

**What to do:** Tell the user. Deleting generations they no longer need (DELETE /generations/{id}) makes room; details.used_bytes and details.limit_bytes say how full it is.

**Details:** `used_bytes`, `limit_bytes`.

### price_above_max

HTTP 409.

The price is higher than the max_usd sent. Nothing was charged.

**What to do:** Ask the user before sending a higher max_usd; details.price_usd is the price in US dollars.

**Details:** `price_usd`, `max_usd`.

### idempotency_conflict

HTTP 409.

This Idempotency-Key was already used with a different request.

**What to do:** Use a new key for a new request. details.generation_id is the generation the key belongs to.

**Details:** `generation_id`.

### not_cancelable

HTTP 409.

Only a queued generation can be canceled, and this one is not queued any more.

**What to do:** Read the generation for its status.

### still_running

HTTP 409.

The generation is queued or running, so it cannot be deleted yet.

**What to do:** Wait until it finishes, or cancel it while it is queued.

### asset_changed

HTTP 409.

The file changed while it was being delivered. Nothing was counted.

**What to do:** Fetch it again.

### conflict

HTTP 409.

The request conflicts with the current state: a sixth webhook endpoint, an event still being delivered, or a resend to an endpoint that is turned off.

**What to do:** Read the current state and send a request that fits it; details.limit is set when a limit was reached.

**Details:** `limit`.

### rate_limited

HTTP 429, retryable.

Too many requests for one of the limits.

**What to do:** Wait retry_after_seconds (also the Retry-After header), then go on. details.scope says who the limit counts (token, account, ip, group or network); details.limit names the line when a request, search or download line refused it.

**Details:** `limit`, `scope`.

### too_many_active

HTTP 429, retryable.

The account already has as many unfinished generations as it may.

**What to do:** Wait for one to finish (read them after poll_after_seconds), then start the next.

### checks_busy

HTTP 429, retryable.

The safety checks of this account's previous request are still running.

**What to do:** Try again after retry_after_seconds.

### fair_use_reached

HTTP 429.

The account has reached its monthly fair-use limit for new downloads.

**What to do:** Tell the user. Files already downloaded stay free; new ones work again at details.resets_at. details.counter says whether files or videos reached it, and details.support_url is support.

**Details:** `resets_at`, `counter`, `support_url`.

### model_paused

HTTP 503.

The model is paused because its provider is failing.

**What to do:** Use details.alternative, or try this model later.

**Details:** `model`, `alternative`.

### daily_capacity

HTTP 503, retryable.

The AI Generator's capacity for API and MCP generations is used up for today.

**What to do:** Try again after details.retry_at.

**Details:** `retry_at`.

### busy

HTTP 503, retryable.

ImgSearch is busy just now: its limits could not be checked, or the AI Generator is full or has no worker free. Nothing was charged.

**What to do:** Try again after retry_after_seconds when it is set, otherwise in a minute, backing off.

### safety_check_unavailable

HTTP 503, retryable.

A safety check could not run, so nothing was started and nothing was charged.

**What to do:** Try again in a few minutes.

### generator_disabled

HTTP 503.

The AI Generator is turned off.

**What to do:** Try again later. Searching and downloads still work.

### api_disabled

HTTP 503.

The API is not available, or this account is not in its private beta (details.reason is beta).

**What to do:** Try again later. The MCP server and the website work as before.

**Details:** `reason`.

### server_error

HTTP 500, retryable.

Something went wrong on ImgSearch's side.

**What to do:** Try again. If it keeps happening, send the request_id to support.

### file_unavailable

HTTP 503, retryable.

The file could not be fetched or checked just now. Nothing was counted.

**What to do:** Try again in a minute.
