---
agent:
  instructions: "Search crawlapi docs via GET /.well-known/search?q={query} (add &format=json or Accept: application/json for JSON)."
  endpoint: "https://docs.crawlapi.dev/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.crawlapi.dev/llms.txt"
---

> Documentation index: https://docs.crawlapi.dev/llms.txt
> Search docs: https://docs.crawlapi.dev/.well-known/search?q={query}
> OpenAPI 3.1 specification: https://docs.crawlapi.dev/openapi.json

# Errors and retries

> Error response schema, retry code, and every API error code.

Every API error returns the same JSON shape with `success: false`, `request_id`, and an `error` object.

## Error object

```json
{
  "success": false,
  "request_id": "req_41e813f088955c316776",
  "error": {
    "code": "BLOCKED",
    "message": "The site's bot protection (Akamai) refused access.",
    "retryable": true,
    "doc_url": "https://docs.crawlapi.dev/errors#BLOCKED",
    "target_status": 403,
    "vendor": "akamai"
  }
}
```

| Field | Presence | Meaning |
| --- | --- | --- |
| `code` | Always | Machine-readable error code from the table below |
| `message` | Always | Plain-text summary of what happened |
| `retryable` | Always | Whether retrying the same request may succeed |
| `doc_url` | Always | Direct link to this code's entry below |
| `param` | On `INVALID_REQUEST` | Offending request field (`url`, `format`, `timeout`, or unknown key) |
| `required_credits` | On `INSUFFICIENT_CREDITS` | Credits required for this request (`1`) |
| `target_status` | When target answered | HTTP status code returned by the target site |
| `vendor` | When identified | Protection service that refused access |

`request_id` is also sent in the `x-request-id` response header. Include it when writing to support.

## Retry policy

Treat `error.retryable` on the response as authoritative rather than inferring retryability from the HTTP status or code alone (for example, `BLOCKED` sets `retryable: false` on HTTP `402`, and `NO_CONTENT` sets `retryable: false` when `format: "json"` finds no structured data).

- **`retryable: true`:** Wait `Retry-After` seconds when the header is present (`429 RATE_LIMITED` and transient `500 INTERNAL`). Otherwise use exponential backoff starting at `1` second, up to **3 total attempts**.
- **`retryable: false`:** Stop immediately. Retrying the same request returns the same error.
- **`401 UNAUTHORIZED` / `402 INSUFFICIENT_CREDITS`:** Fix your key or add credits before retrying.
- **`403 ACCOUNT_SUSPENDED`:** Stop all requests and contact `support@crawlapi.dev`.
- **Non-JSON gateway errors:** If an upstream gateway returns `502` or `504` with a non-JSON body during a brief blip, retry with backoff.

**TypeScript**

```typescript
async function scrapeWithRetry(url: string, format: 'markdown' | 'json' = 'markdown') {
  for (let attempt = 0; attempt < 3; attempt++) {
    const response = await fetch('https://api.crawlapi.dev/v1/scrape', {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.CRAWLAPI_API_KEY}`,
        'content-type': 'application/json',
      },
      body: JSON.stringify({ url, format }),
    });
    if (response.status === 502 || response.status === 504) {
      if (attempt === 2) throw new Error(`HTTP ${response.status}`);
      await new Promise((resolve) => setTimeout(resolve, 1000 * 2 ** attempt));
      continue;
    }
    const body = await response.json();
    if (body.success) return body.data;
    if (!body.error.retryable || attempt === 2) {
      throw new Error(`${body.error.code}: ${body.error.message}`);
    }
    const retryAfter = Number(response.headers.get('retry-after'));
    const waitMs =
      Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter * 1000 : 1000 * 2 ** attempt;
    await new Promise((resolve) => setTimeout(resolve, waitMs));
  }
  throw new Error('Retries exhausted');
}
```

**Python**

```python
import os
import time
import requests

def scrape_with_retry(url: str, fmt: str = "markdown") -> dict:
    for attempt in range(3):
        response = requests.post(
            "https://api.crawlapi.dev/v1/scrape",
            headers={"Authorization": f"Bearer {os.environ['CRAWLAPI_API_KEY']}"},
            json={"url": url, "format": fmt},
            timeout=65,
        )
        if response.status_code in (502, 504):
            if attempt == 2:
                response.raise_for_status()
            time.sleep(2**attempt)
            continue
        body = response.json()
        if body["success"]:
            return body["data"]
        if not body["error"]["retryable"] or attempt == 2:
            raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
        retry_after = response.headers.get("Retry-After")
        wait_s = int(retry_after) if retry_after and retry_after.isdigit() else 2**attempt
        time.sleep(wait_s)
    raise RuntimeError("Retries exhausted")
```

## HTTP `422` and sign-in walls

Seven target failures share HTTP `422`: `BLOCKED`, `NO_CONTENT`, `HOST_NOT_FOUND`, `LOGIN_REQUIRED`, `UNSUPPORTED_CONTENT`, `SCANNED_PDF`, and `TARGET_ERROR`. Always branch on `error.code`, not on HTTP status alone.

If a target page serves a readable sign-in wall (such as a login prompt or age notice), crawlapi returns HTTP `200` with `metadata.login_required: true` and the wall's text. Check `data.metadata.login_required` before indexing content.

## Quick diagnosis by status

| Status | What to check |
| --- | --- |
| `200` with unexpected text | Check `metadata.login_required` (sign-in wall) and `metadata.truncated` (`2 MiB` cap). |
| `400` | Read `error.param` and `error.message`, fix the request, and do not retry unchanged. |
| `401` | Verify `CRAWLAPI_API_KEY` is present and active at [app.crawlapi.dev/keys](https://app.crawlapi.dev/keys) (see [API keys and billing](https://docs.crawlapi.dev/account.md)). |
| `402` | Top up credits at [app.crawlapi.dev/billing](https://app.crawlapi.dev/billing) before retrying (see [Credits and pricing](https://docs.crawlapi.dev/credits.md)). |
| `403` | Account is suspended — pause traffic and contact `support@crawlapi.dev`. |
| `404` / `410` | Target page is missing or removed; do not retry unchanged. |
| `408` | Page exceeded your `timeout` deadline; raise `timeout` up to `60000` ms or see [Timeouts](https://docs.crawlapi.dev/timeouts.md). |
| `422` | Branch on `error.code` and `error.retryable` (see table below). |
| `429` | Honor `Retry-After` and check [Rate limits](https://docs.crawlapi.dev/rate-limits.md). |
| `5xx` | Transient service or gateway error; retry with exponential backoff up to 3 attempts. |

## All error codes

| Code | HTTP | Retryable | Meaning | What to do |
| --- | --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | no | The request body could not be accepted: malformed JSON, a missing or unknown field, or a value out of range. | Fix the field named in `error.param` and `error.message`, then resend `POST /v1/scrape` with a JSON body containing `url`, optional `format`, and optional `timeout`. |
| `UNSAFE_URL` | 400 | no | Not a public `http` or `https` address: an unsupported scheme, embedded credentials, a malformed URL, or a private or local network address. | Send a public `http` or `https` URL with no username or password in the URL. |
| `UNAUTHORIZED` | 401 | no | The API key is missing, unknown, or revoked. | Send one active API key as `Authorization: Bearer` or `x-api-key`; manage keys at https://app.crawlapi.dev/keys. |
| `ACCOUNT_SUSPENDED` | 403 | no | The API key is active, but the account it belongs to is suspended. | Stop retrying: no key of a suspended account works. Write to support@crawlapi.dev to resolve the suspension. |
| `INSUFFICIENT_CREDITS` | 402 | no | The account balance has no credits left for this request. | Add credits at https://app.crawlapi.dev/billing, then resend the same request. |
| `ROUTE_NOT_FOUND` | 404 | no | No endpoint exists at this path; use `POST /v1/scrape`. | Send `POST /v1/scrape` (with no trailing slash). |
| `METHOD_NOT_ALLOWED` | 405 | no | The HTTP method is not allowed on this path. | Use the HTTP method listed in the `Allow` header (`POST` for `/v1/scrape`). |
| `RATE_LIMITED` | 429 | yes | The account reached its per-minute or concurrency limit, or the service is temporarily busy. `Retry-After` says when to retry. | Wait at least `Retry-After` seconds before retrying; read `RateLimit` to see remaining per-minute and concurrency room. |
| `HOST_NOT_FOUND` | 422 | no | The domain name does not resolve. | Check the domain for typos; retrying the same URL returns the same error. |
| `NOT_FOUND` | 404 | no | The target site says this page does not exist, including a "not found" page served with HTTP 200. | Check the URL; retrying returns the same error and costs `0` credits. |
| `GONE` | 410 | no | The target site says this page has been permanently removed (HTTP 410). | Remove the URL from your list; the site permanently deleted it (`0` credits). |
| `LOGIN_REQUIRED` | 422 | no | The page requires signing in and has no readable wall text to return, or the document is password-protected. | Pass a public URL. Sign-in walls with readable text return HTTP 200 with `metadata.login_required: true` for `0` credits. |
| `UNSUPPORTED_CONTENT` | 422 | no | The URL serves content the service cannot read: neither HTML nor a supported document (for example an image, an archive, or an unreadable or oversized file). | Use another URL: only HTML and documents (PDF, Office, OpenDocument, EPUB, RTF, CSV, JSON and feeds) can be read. |
| `SCANNED_PDF` | 422 | no | Most pages of this PDF are scanned images; OCR is not supported. | Supply a PDF with an embedded text layer or run OCR before scraping. |
| `BLOCKED` | 422 | depends | The target site's bot protection refused access, or the site requires payment (HTTP 402). | Retry with backoff up to 3 attempts while `retryable` is `true`. Sites returning HTTP 402 set `retryable: false`. |
| `NO_CONTENT` | 422 | depends | No usable content was produced: an empty shell, too little readable text, a cookie or age wall, or `format=json` found no records. | If you requested `format=json`, try `format=markdown`; otherwise retry only while `retryable` is `true`. |
| `TARGET_ERROR` | 422 | depends | The target site failed on its side: a 5xx response, a connection or TLS failure, or a malformed reply. | Retry later while `retryable` is `true`. |
| `TIMEOUT` | 408 | yes | The request reached its `timeout` deadline before finishing. | Increase `timeout` up to `60000` ms or retry later. |
| `ENGINE_FAILED` | 500 | yes | A failure on our side while reading or processing the page; nothing was charged. | Retry the same request; the failure was on our side and cost `0` credits. |
| `INTERNAL` | 500 | yes | An unexpected error occurred on our side. Quote `request_id` if you contact support; nothing was charged. | Retry after `Retry-After` when present; if it persists, send `request_id` to support. |

## Reporting an issue

When reporting a reproducible failure, email `support@crawlapi.dev` with the `request_id` (from the JSON body or `x-request-id` header), HTTP status, and `error.code`.
