---
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

# Scrape a URL

> Turn a web page or document into clean markdown or structured JSON.

Endpoint: `POST https://api.crawlapi.dev/v1/scrape`
OpenAPI 3.1 spec: https://docs.crawlapi.dev/openapi.json

Reads a public web page or document within a single `timeout` deadline and returns clean `markdown` or structured `json`. `usage.credits` reports the price charged (`1` credit per returned page).

## Authentication

| Scheme | Header | Details |
| --- | --- | --- |
| bearer | `Authorization: Bearer <key>` | Send your API key in `Authorization: Bearer <key>`. Keys start with `ck_` and are created at https://app.crawlapi.dev/keys. |
| apiKey | `x-api-key` | Alternative header for your API key (`ck_...`). |

## Request body

Send a JSON object with `url`, optional `format`, and optional `timeout`.

| Field | Type | Rules | Description |
| --- | --- | --- | --- |
| `url` | `string<uri>` | required | Public `http` or `https` URL to read. Private addresses and embedded credentials return `UNSAFE_URL`. |
| `format` | `string` | optional, default `markdown` | Output format: `markdown` returns clean page text; `json` returns structured objects, tables, JSON-LD, and embedded state. |
| `timeout` | `integer` | optional, default `30000`, 1000–60000 | Overall deadline in milliseconds for the request. Defaults to `30000`. |

## Response headers

| Header | Type | Description |
| --- | --- | --- |
| `X-Request-Id` | `string` | Unique request identifier (`req_...`). Quote this value to support. |
| `RateLimit-Policy` | `string` | Account rate-limit policy sent on authenticated responses: `"minute"` sets `q` requests per minute (`w=60`), `"concurrency"` sets `q` in-flight requests at once. |
| `RateLimit` | `string` | Remaining quota when the response leaves: `"minute";r=` requests that can start now and `t=` seconds until the next token refills (omitted when your full per-minute allowance is available); `"concurrency";r=` free in-flight slots. |
| `Retry-After` | `integer` | Whole seconds to wait before retrying. |
| `Allow` | `string` | HTTP methods accepted on this route. |
| `WWW-Authenticate` | `string` | Authentication scheme expected for this endpoint. |

## Success response (200)

| Field | Type | Rules | Description |
| --- | --- | --- | --- |
| `success` | `true` | required | Always `true` on success. |
| `request_id` | `string` | required | Unique request identifier, echoed in the `x-request-id` header. |
| `data` | `markdown | json` | required | Extracted page content: `metadata`, `links`, and either `markdown` or `json`. |
| `data.metadata` | `object` | required | Page metadata and completion flags. |
| `data.metadata.title` | `string` | required | Page title. |
| `data.metadata.description` | `string` | required | Meta description. |
| `data.metadata.language` | `string | null` | required | Declared page language, or `null` when undeclared. |
| `data.metadata.status` | `integer` | required | HTTP status code returned by the target site. |
| `data.metadata.final_url` | `string` | required | Final URL after redirects, stripped of tracking parameters (or the canonical URL for X posts and YouTube videos). |
| `data.metadata.truncated` | `boolean` | optional | Present and `true` when the response was truncated (for example at the 2 MiB output cap). Omitted when `false`. |
| `data.metadata.login_required` | `boolean` | optional | Present and `true` when the target is a sign-in wall returned as its own text (`0` credits). Omitted when `false`. |
| `data.links` | `string[]` | required | Unique absolute `http(s)` URLs from the whole page in document order (entry links for RSS/Atom feeds; empty for other documents). |
| `data.markdown` | `string` | required | Extracted page text in markdown, up to 2 MiB. Present when `format` is `markdown`. |
| `data.json` | `object` | required | Extracted structured data. Present when `format` is `json`. |
| `data.json.structured` | `object` | optional | Normalized object the page declares itself to be (most specific schema.org type, X post, or YouTube video). Omitted when the page declares none. |
| `data.json.structured.type` | `string` | required | Most specific declared object type; the object sits under the matching property. |
| `data.json.structured.source` | `string` | required | Primary declaration source (`jsonld`, `microdata`, `opengraph`, `x`, `youtube`); blank fields are filled from other sources declaring the same object. |
| `data.json.structured.product` | `object` | optional | Declared product. |
| `data.json.structured.article` | `object` | optional | Declared article. |
| `data.json.structured.listing` | `object` | optional | Declared item listing. |
| `data.json.structured.recipe` | `object` | optional | Declared recipe. |
| `data.json.structured.software_app` | `object` | optional | Declared application or game. |
| `data.json.structured.creative_work` | `object` | optional | Declared film, series, episode, book, album, song, or podcast. |
| `data.json.structured.event` | `object` | optional | Declared event. |
| `data.json.structured.job` | `object` | optional | Declared job posting. |
| `data.json.structured.faq` | `object[]` | optional | Declared questions and answers. |
| `data.json.structured.local_business` | `object` | optional | Declared business, shop, restaurant, or hotel. |
| `data.json.structured.video` | `object` | optional | Declared video. |
| `data.json.structured.post` | `object` | optional | X post with author, text, counts, media, thread, quoted post, article, and the replies X shows publicly. |
| `data.json.tables` | `object[]` | required | Extracted data tables from the page. Always present; empty when none are found. |
| `data.json.tables.source` | `string` | required | Origin of the table: `html` for an HTML table, `list` for repeated page cards, `embedded` for a record array in page state or JSON-LD, `document` for a document. |
| `data.json.tables.headers` | `string[]` | required | Column headings, or empty if the table has none. |
| `data.json.tables.rows` | `string[][]` | required | Table rows, each a list of cell strings. |
| `data.json.jsonld` | `any[]` | required | Raw JSON-LD blocks from the page. Always present; empty when none exist. |
| `data.json.embedded` | `object[]` | required | Embedded page state blobs parsed from the page, largest first. Always present; empty when none. |
| `data.json.embedded.source` | `string` | required | Where the blob came from: `next-data`, `json-script`, `inline` JS assignment, or `document` for a JSON response. |
| `data.json.embedded.key` | `string | null` | required | Variable name or script `id` holding the blob, or `null` if unnamed. |
| `data.json.embedded.bytes` | `integer` | required | Raw blob size in UTF-8 bytes. |
| `data.json.embedded.value` | `any` | required | Parsed JSON value (nested JSON strings decoded). |
| `usage` | `object` | required | Credits charged and remaining balance. |
| `usage.credits` | `integer` | required | Credits charged for this request: `1` for a page, or `0` for a sign-in wall. |
| `usage.remaining` | `integer` | required | Credit balance remaining after this request. |

## Error response (4xx / 5xx)

| Field | Type | Rules | Description |
| --- | --- | --- | --- |
| `success` | `false` | required | Always `false` on error responses. |
| `request_id` | `string` | required | Unique request identifier, echoed in the `x-request-id` header. |
| `error` | `object` | required | Structured reason for the failure and retry guidance. |
| `error.code` | `string` | required | Machine-readable error code. See Errors and retries. |
| `error.message` | `string` | required | Human- and agent-readable summary. |
| `error.retryable` | `boolean` | required | Whether retrying the same request may succeed. Always read this flag on the response rather than assuming from `code`. |
| `error.doc_url` | `string` | required | Link to this error code's documentation entry. |
| `error.param` | `string` | optional | Request field that failed validation on `INVALID_REQUEST`, when applicable. |
| `error.required_credits` | `integer` | optional | Credits required for this request on `INSUFFICIENT_CREDITS`. |
| `error.target_status` | `integer` | optional | HTTP status code returned by the target site, when it answered. |
| `error.vendor` | `string` | optional | Protection service that refused the page, when identified. |

## HTTP status codes

| Status | Codes | Meaning |
| --- | --- | --- |
| `200` | Success | Page or document returned as `markdown` or `json`. |
| `400` | `INVALID_REQUEST`, `UNSAFE_URL` | Malformed JSON, invalid or unknown request field (`INVALID_REQUEST`), or non-public or disallowed target URL (`UNSAFE_URL`). |
| `401` | `UNAUTHORIZED` | Missing, unknown, or revoked API key (`UNAUTHORIZED`). |
| `402` | `INSUFFICIENT_CREDITS` | Account credit balance cannot cover this request (`INSUFFICIENT_CREDITS`). |
| `403` | `ACCOUNT_SUSPENDED` | The API key's account is suspended (`ACCOUNT_SUSPENDED`). |
| `404` | `ROUTE_NOT_FOUND`, `NOT_FOUND` | Target page does not exist (`NOT_FOUND`), or request path is not `/v1/scrape` (`ROUTE_NOT_FOUND`). |
| `405` | `METHOD_NOT_ALLOWED` | HTTP method is not allowed on this route (`METHOD_NOT_ALLOWED`). |
| `408` | `TIMEOUT` | Request reached its `timeout` deadline before finishing (`TIMEOUT`). |
| `410` | `GONE` | Target site reports the page has been permanently removed (`GONE`). |
| `422` | `HOST_NOT_FOUND`, `LOGIN_REQUIRED`, `UNSUPPORTED_CONTENT`, `SCANNED_PDF`, `BLOCKED`, `NO_CONTENT`, `TARGET_ERROR` | Request was valid but the target could not produce usable content: `BLOCKED`, `NO_CONTENT`, `HOST_NOT_FOUND`, `LOGIN_REQUIRED`, `UNSUPPORTED_CONTENT`, `SCANNED_PDF`, or `TARGET_ERROR`. |
| `429` | `RATE_LIMITED` | Rate limit, concurrency limit, or temporary service load reached (`RATE_LIMITED`). |
| `500` | `ENGINE_FAILED`, `INTERNAL` | Service-side failure (`ENGINE_FAILED` or `INTERNAL`). Nothing was charged. |

## Code examples

### cURL

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

### TypeScript

```typescript
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' }),
});
const body = await response.json();
if (!body.success) throw new Error(`${body.error.code}: ${body.error.message}`);
console.log(body.data.markdown);
```

### Python

```python
import os
import requests

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

### Go

```go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "os"
    "time"
)

func main() {
    payload := []byte(`{"url":"https://example.com"}`)
    req, err := http.NewRequest("POST", "https://api.crawlapi.dev/v1/scrape", bytes.NewReader(payload))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer "+os.Getenv("CRAWLAPI_API_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 65 * time.Second}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    var body struct {
        Success bool `json:"success"`
        Data    struct{ Markdown string `json:"markdown"` } `json:"data"`
        Error   struct{ Code, Message string } `json:"error"`
    }
    if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
        panic(err)
    }
    if !body.Success {
        panic(fmt.Sprintf("%s: %s", body.Error.Code, body.Error.Message))
    }
    fmt.Println(body.Data.Markdown)
}
```

### Ruby

```ruby
require "json"
require "net/http"
require "uri"

uri = URI("https://api.crawlapi.dev/v1/scrape")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer #{ENV.fetch('CRAWLAPI_API_KEY')}"
req["Content-Type"] = "application/json"
req.body = JSON.generate({ url: "https://example.com" })

res = Net::HTTP.start(
  uri.host, uri.port, use_ssl: true, read_timeout: 65
) { |http| http.request(req) }
body = JSON.parse(res.body)
raise "#{body.dig("error", "code")}: #{body.dig("error", "message")}" unless body["success"]
puts body.dig("data", "markdown")
```

### PHP

```php
<?php
$ch = curl_init('https://api.crawlapi.dev/v1/scrape');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 65,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('CRAWLAPI_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode(['url' => 'https://example.com']),
]);
$raw = curl_exec($ch);
if ($raw === false) throw new RuntimeException(curl_error($ch));
$body = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
if (empty($body['success']))
    throw new RuntimeException($body['error']['code'] . ': ' . $body['error']['message']);
echo $body['data']['markdown'];
```
