# Status codes and errors

> Every status code the API returns, whether it was billed, and how to handle each one, including retries with backoff.

Errors come at two levels. A **request-level** error means nothing ran. A **task-level** error affects one task in an otherwise successful request. No error is billed.

## Compatible routes (DataForSEO envelope)

The top-level `status_code` and the HTTP status describe the request. Each `tasks[].status_code` describes its task. A request with a failed task still returns HTTP 200 and top-level `20000`; count failures with `tasks_error`.

| Code | Message | Level | HTTP | Billed | What to do |
|---|---|---|---|---|---|
| `20000` | Ok. | request, task | 200 | Task: yes | Read `result`. |
| `20100` | Task Created. | task | 200 | No | Queued. Collect it later with `task_get`. |
| `40006` | You can send up to 100 tasks in one request. | request | 400 | No | Split the array. |
| `40100` | Authentication required. | request | 401 | No | Send your key. See [Authentication](https://dataforgaio.com/docs/authentication.md). |
| `40101` | Authentication failed. | request | 401 or 403 | No | Check the key; create a new one if it was revoked. 403 means the key's owner left the organization. |
| `40102` | No Search Results. | task | 200 | No | The search or page returned nothing. Don't retry right away. |
| `40202` | Too many requests. Retry after N s. | request | 429 | No | Wait for `Retry-After` seconds, then retry. |
| `40210` | Insufficient funds. | request | 402 | No | Top up, or lower `max_cost` / `max_level` to lower the reservation. |
| `40400` | Not Found. | request | 404 | No | Check the path. |
| `40401` | Task Not Found. | task | 200 | No | Wrong id, or another organization's task. |
| `40402` | This endpoint isn't available yet. | request, task | 404 / 200 | No | The route isn't served yet. Check `GET /v1/account/support_matrix`. |
| `40501` | Invalid Field: ... | task | 200 | No | Fix the field named in the message. Don't retry unchanged. |
| `40503` | POST Data Is Invalid. | request | 400 (405 for a `GET` on a `POST` route) | No | Send a JSON array of task objects. |
| `40601` | Task Handed. | task | 200 | No | A worker is running it. Check again shortly. |
| `40602` | Task In Queue. | task | 200 | No | Waiting for a worker. Check again later. |
| `50000` | Internal Error. You weren't billed. | request, task | 500 / 200 | No | Retry with backoff. |

Request-level errors return the envelope with an empty `tasks` array:

```json
{
  "version": "0.1.20261203",
  "status_code": 40210,
  "status_message": "Insufficient funds. Your wallet balance is $0.00 and this request can cost up to $0.001800. Top up and retry. You weren't billed.",
  "time": "0.0025 sec.",
  "cost": 0.0,
  "tasks_count": 0,
  "tasks_error": 0,
  "tasks": []
}
```

`GET /v1/account/errors` is DataForSEO's errors list for your account: the failed queued tasks of the last 7 days, newest first (`limit` up to 1,000, `offset`).

## Scale SERP, Outscraper and Apify shapes

These routes return their source product's error body with an HTTP status mapped from the code above:

| Code | HTTP | Scale SERP | Outscraper | Apify `error.type` |
|---|---|---|---|---|
| `40100`, `40101` | 401 | `request_info.success: false` | `status: "Error"` | `user-or-token-not-found` |
| `40210` | 402 | | | `not-enough-usage-to-run-paid-actor` |
| `40400`, `40402` | 404 | | | `record-not-found` |
| `40202` | 429 | | | `rate-limit-exceeded` |
| `50000` | 500 | | | `internal-error` |
| anything else, including `40501` and `40102` | 400 | | | `invalid-input` |

The message is in `request_info.message` (Scale SERP), `errorMessage` (Outscraper) or `error.message` (Apify). An Apify-shaped search that finds no ads therefore returns HTTP 400 with `invalid-input` and the message "No ads found for the input."

## Crawl API routes

Request-level errors use one body:

```json
{ "status": "error", "error": { "http_status": 402, "code": "balance_required", "message": "Your wallet balance is $0.00 and this request can cost up to $0.003000. Top up and retry. You weren't billed." } }
```

| HTTP | `code` | When | What to do |
|---|---|---|---|
| 400 | `invalid_request` | The body isn't valid; `details` names the fields. Also more than 100 batch targets. | Fix and resend. |
| 401 | `unauthorized` | Missing, malformed or revoked key. | Check the key. |
| 402 | `balance_required` | The wallet can't cover the worst case. | Top up. |
| 403 | `forbidden` | The key's owner isn't an active organization member. | Use another key. |
| 404 | `not_found` | No job, task or tracker with that id in your organization. | Check the id. |
| 405 | `method_not_allowed` | Wrong HTTP method. | |
| 415 | `unsupported_media_type` | The body isn't JSON. | Send `application/json`. |
| 422 | `invalid_target` | A URL isn't absolute `http(s)`, is too long, or points to a private host. | Fix the URL. |
| 422 | `max_cost_exceeded` | `max_cost` is below the price of a Standard fetch. | Raise `max_cost`. |
| 429 | `rate_limited` | Over the per-key rate or the per-organization inline limit. | Wait for `Retry-After`. |
| 502 | `upstream_error` | The site or search couldn't be fetched. | Retry later with backoff. |
| 503 | `not_configured` | The feature isn't available on this server yet. | |

A single-URL `POST /v1/crawls` mirrors its task in the HTTP status: 200 completed (including pages billed $0 because they weren't real content), 502 `upstream_error`, 422 `invalid_target` or `max_cost_exceeded`, 503 `level_unavailable`. The body is still the full envelope with a receipt. HTTP 451 `blocked_by_policy` appears only when robots.txt enforcement is turned on for the deployment; it's off by default, and the receipt records what robots.txt said either way.

## Retrying safely

Retry only what can succeed on a second try:

| Retry | Don't retry unchanged |
|---|---|
| `40202` / 429, after `Retry-After` | `40501`, `40503`, `40006`, 400, 415, 422 |
| `50000` / 500, 502 | `40100`, `40101`, 401, 403 |
| Network errors and timeouts on `GET` | `40210` / 402, until you've topped up |
| `40601`, `40602` on `task_get`, after a pause | `40402`, `40400`, `40401` |

Use exponential backoff with jitter: wait about 1 s, then 2 s, 4 s, 8 s, up to a cap of around 60 s, with a random fraction added to each wait. Stop after a handful of attempts.

A `POST` that timed out on your side may have run and been billed. We don't support idempotency keys yet. Before retrying a live `POST`, read the result back where you can (`task_get`, `GET /v1/crawls/{id}`), or prefer `task_post` so you hold the task id before anything runs. [Retrying safely](https://dataforgaio.com/docs/retrying-safely.md) has worked examples.
