> Documentation index: https://docs.crawlapi.dev/llms.txt
> Fetch the index before exploring further; it lists every page with its description.

# POST /v1/scrape

> Read one URL and return it as markdown or JSON. From 1 credit; a failure costs 0.

`POST /v1/scrape` reads one URL and returns it as markdown or JSON. From 1 credit; a failure costs 0.

## Authorization

Send the key as `Authorization: Bearer <key>` or as the `x-api-key` header. A missing, unknown, revoked or suspended key answers `401 UNAUTHORIZED`, and so do two different keys in one request (both headers with the same key is one key).

## Body

A JSON object, at most 64 KiB, read as JSON whatever its `content-type`. An unknown field, a wrong type or an out-of-range value answers `400 INVALID_REQUEST`. Any method but `POST` answers `405`, and a path with a trailing slash `404`.

| Field | Type | Required | What it is | Default and limits |
|---|---|---|---|---|
| `url` | string | required | The page to read. Public http and https on the ports 80, 443, 8080, 8443 only; private and reserved addresses, credentials in the URL and other ports are UNSAFE_URL. | 1–8,192 characters |
| `format` | one of markdown, json | optional | markdown returns the page's text; json returns its structured data. | default markdown |
| `timeout` | integer or null | optional | Deadline in milliseconds for the whole request. Defaults to 30000. | default 30000, 1000–60000 ms |

## Response

One JSON object with `success`, `request_id`, `data` and `usage`; `data` holds `markdown` or `json`, never both. `usage.credits` says what the page cost.

| Field | Type | Required | What it is | Default and limits |
|---|---|---|---|---|
| `success` | true | required | true on a success, including a login wall. |  |
| `request_id` | string | required | The request's id; the same value is in x-request-id. |  |
| `data` | object | required | The page: its metadata and links, and markdown or json. |  |
| `data.metadata` | object | required | What the page says about itself, and how the request ended. |  |
| `data.metadata.title` | string | required | The page's title, up to 1,000 characters. |  |
| `data.metadata.description` | string | required | The page's meta description, up to 1,000 characters. |  |
| `data.metadata.language` | string or null | required | The page's language, when it declares one. |  |
| `data.metadata.status` | integer | required | The HTTP status the site answered with. |  |
| `data.metadata.final_url` | string | required | The URL the page was read from, after redirects, without the query parameters that only track visitors or that a bot check left behind; an X post's own address. |  |
| `data.metadata.truncated` | boolean | optional | A cap cut the page: a byte cap, or the 2 MiB output cap. | default false |
| `data.metadata.login_required` | boolean | optional | A sign-in wall: the wall's own text, 0 credits. | default false |
| `data.links` | array of string | required | Every absolute URL on the page, in document order, up to 5,000. |  |
| `data.markdown` | string or null | optional | The page's text, at most 2 MiB. Present when format is markdown. |  |
| `data.json` | object or null | optional | The page's structured data. Present when format is json. |  |
| `data.json.structured` | object or null | optional | The one object the page declares itself to be, read as its most specific type, or an X post; left out when the page declares none. |  |
| `data.json.tables` | array of object | required | Record tables: JSON-LD and embedded arrays first, then HTML tables, then the page's repeated cards. |  |
| `data.json.jsonld` | array of object | required | The page's JSON-LD blocks, as written. |  |
| `data.json.embedded` | array of object | required | The page's state blobs (__NEXT_DATA__, application/json scripts, …), largest first. |  |
| `usage` | object | required | What this request charged, and what is left to spend. |  |
| `usage.credits` | integer | required | The credits this request charged: the price of the page's level, 0 on a failure or a login wall. |  |
| `usage.remaining` | integer | required | The balance left after this request. |  |

## Errors

A failure answers `success: false` and an `error` with a `code`, a `message` and a `retryable` flag. Every response carries `x-request-id`. `Retry-After` (seconds to wait) comes with a `429` and with the `500` of a database outage. Every answer to a valid key carries `RateLimit-Policy` (the account's limits: `"minute";q=`, `"concurrency";q=`) and `RateLimit` (what is left: `"minute";r=` requests that can start now and `t=` seconds until one more can, `"concurrency";r=` free slots).

| Field | Type | Required | What it is | Default and limits |
|---|---|---|---|---|
| `success` | false | optional | false on a failure. |  |
| `request_id` | string | required | The request's id; the same value is in x-request-id. |  |
| `error` | object | required | Why it failed and whether a retry can help. |  |
| `error.code` | one of 17 codes | required | The reason code. Every code is on Errors and retries. |  |
| `error.message` | string | required | One to three sentences for the caller, at most 220 characters. |  |
| `error.retryable` | boolean | required | The same request may succeed later, after Retry-After when sent. |  |
| `error.doc_url` | string | required | This code's entry on Errors and retries: what it means and what to do. |  |
| `error.target_status` | integer or null | optional | The HTTP status the site answered with, when the site answered. |  |
| `error.vendor` | string or null | optional | The bot protection that refused the page, when it is known. |  |

| Status | Codes |
|---|---|
| 200 | success |
| 400 | INVALID_REQUEST, UNSAFE_URL |
| 401 | UNAUTHORIZED |
| 402 | INSUFFICIENT_CREDITS |
| 404 | NOT_FOUND |
| 405 | INVALID_REQUEST, the method is not allowed on this path |
| 408 | TIMEOUT |
| 410 | GONE |
| 422 | BLOCKED, HOST_NOT_FOUND, LOGIN_REQUIRED, NO_CONTENT, SCANNED_PDF, TARGET_ERROR, UNSUPPORTED_CONTENT |
| 429 | RATE_LIMITED |
| 500 | ENGINE_FAILED, INTERNAL |

Every code, with its meaning and retry rule: https://docs.crawlapi.dev/errors.md

## Limits

- `timeout`: 1000–60000 ms, 30000 ms by default.
- `url`: at most 8,192 characters.
- Requests per minute and at once: one limit per account. Your limits rise as your purchases add up: once they reach the price of a pack in total, you have its limits. They never go down. (https://docs.crawlapi.dev/rate-limits.md)
- Credits: the price of the page's level; a failure costs 0 (https://docs.crawlapi.dev/credits.md).

## Examples

Request:

```bash
curl -sS https://api.crawlapi.dev/v1/scrape \
  -H "Authorization: Bearer $CRAWLAPI_API_KEY" \
  -H 'content-type: application/json' \
  --data '{"url": "https://example.com", "format": "markdown"}'
```

```python
import os

import httpx

response = httpx.post(
    "https://api.crawlapi.dev/v1/scrape",
    headers={"Authorization": f"Bearer {os.environ['CRAWLAPI_API_KEY']}"},
    json={"url": "https://example.com", "format": "markdown"},
    timeout=60.0,
)
body = response.json()
if not body["success"]:
    print(body["error"]["code"], body["error"]["retryable"])
```

```javascript
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: 'https://example.com', format: 'markdown' }),
});
const body = await response.json();
if (!response.ok) {
  console.log(body.error.code, body.error.retryable);
}
```

`200`: The page was read. usage.credits says what it cost.

```json
{
  "success": true,
  "request_id": "req_1dc0a514d6ee71c4524b",
  "data": {
    "metadata": {
      "title": "Example Domain",
      "description": "",
      "language": "en",
      "status": 200,
      "final_url": "https://example.com/"
    },
    "links": [],
    "markdown": "# Example Domain\n\nThis domain is for use in documentation examples without needing permission. This is not a service; avoid relying on it for testing and monitoring purposes."
  },
  "usage": { "credits": 1, "remaining": 9999 }
}
```

`404`: The site says the page does not exist. Not retryable.

```json
{
  "success": false,
  "request_id": "req_fe9963033461e4fcc81c",
  "error": {
    "code": "NOT_FOUND",
    "message": "The site says this page does not exist (HTTP 404).",
    "retryable": false,
    "doc_url": "https://docs.crawlapi.dev/errors#NOT_FOUND",
    "target_status": 404
  }
}
```

`422`: The site’s bot protection refused access. Retryable, later.

```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"
  }
}
```

`429`: Too many requests for this account, or no capacity to start this one. Retry-After says when. Nothing was charged.

```json
{
  "success": false,
  "request_id": "req_3115cab0d43d3ab5a090",
  "error": {
    "code": "RATE_LIMITED",
    "message": "This account's limit of requests at once (5) is reached; retry when one finishes.",
    "retryable": true,
    "doc_url": "https://docs.crawlapi.dev/errors#RATE_LIMITED"
  }
}
```
