> ## Documentation Index
> Fetch the complete documentation index at: https://docs.styne.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Crawl

> POST /v1/crawl starts a crawl job: from one start URL it follows links, within the scope you set, and keeps the text of every page it reads. You start the job, poll it until it ends, and read the pages.

[//]: # "smoke: not executed, the search endpoints are served by the main API host and bill the account that calls them"

Base URL: `https://api.styne.ai`. Every request carries `Authorization: Bearer $STYNE_API_KEY`.

## Quick start

### 1. Start a job

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/v1/crawl \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"url": "https://example.com/docs/", "max_pages": 50, "max_depth": 2, "scope": "path"}'
```

The answer is `202` with the job: its `id`, `status` (`queued`), the limits you set and `counts`.

### 2. Poll and read the pages

```bash theme={"theme":"css-variables"}
curl -sS "https://api.styne.ai/v1/crawl/$JOB_ID?limit=20" \
  -H "Authorization: Bearer $STYNE_API_KEY"
```

`status` goes `queued`, `running`, then `succeeded`, `failed` or `canceled`. The finished pages are in `pages`, in order, 20 by default and up to 100 with `limit`. While `next_cursor` is not null, pass it back as `?cursor=` for the next page of results.

```python theme={"theme":"css-variables"}
import os
import time
import requests

base = "https://api.styne.ai"
headers = {"Authorization": f"Bearer {os.environ['STYNE_API_KEY']}"}

job = requests.post(
    f"{base}/v1/crawl",
    headers=headers,
    json={"url": "https://example.com/docs/", "max_pages": 50, "max_depth": 2, "scope": "path"},
    timeout=30,
).json()

while True:
    state = requests.get(f"{base}/v1/crawl/{job['id']}", headers=headers, timeout=30).json()
    if state["status"] in ("succeeded", "failed", "canceled"):
        break
    time.sleep(3)

cursor = None
while True:
    params = {"limit": 100, **({"cursor": cursor} if cursor else {})}
    page = requests.get(f"{base}/v1/crawl/{job['id']}", headers=headers, params=params, timeout=30).json()
    for p in page["pages"]:
        if p["status"] == "fetched":
            print(p["url"], p["tokens"])
    cursor = page["next_cursor"]
    if not cursor:
        break
```

```typescript theme={"theme":"css-variables"}
const base = "https://api.styne.ai";
const headers = { Authorization: `Bearer ${process.env.STYNE_API_KEY}`, "Content-Type": "application/json" };

const job = await (await fetch(`${base}/v1/crawl`, {
  method: "POST",
  headers,
  body: JSON.stringify({ url: "https://example.com/docs/", max_pages: 50, max_depth: 2, scope: "path" }),
})).json();

let state = job;
while (!["succeeded", "failed", "canceled"].includes(state.status)) {
  await new Promise((resolve) => setTimeout(resolve, 3000));
  state = await (await fetch(`${base}/v1/crawl/${job.id}`, { headers })).json();
}

let cursor: string | null = null;
do {
  const url = `${base}/v1/crawl/${job.id}?limit=100${cursor ? `&cursor=${cursor}` : ""}`;
  const page = await (await fetch(url, { headers })).json();
  for (const p of page.pages) if (p.status === "fetched") console.log(p.url, p.tokens);
  cursor = page.next_cursor;
} while (cursor);
```

### 3. Stop a job

```bash theme={"theme":"css-variables"}
curl -sS -X DELETE https://api.styne.ai/v1/crawl/$JOB_ID \
  -H "Authorization: Bearer $STYNE_API_KEY"
```

The job ends as `canceled`, and the pages it had read stay readable until the job expires.

## Request fields

Only `url` is required.

| Field | Type | What it does |
| - | - | - |
| `url` | string | The start URL, public `http` or `https`. |
| `max_pages` | integer, 1 to 10,000 | Pages to read at most. Default 50. The ceiling is your plan's: 1,000 without a plan, 2,000 on Builder, 5,000 on Startup, 10,000 on Scale. |
| `max_depth` | integer, 0 to 10 | Link hops from the start URL. Default 2. |
| `max_breadth` | integer, 1 to 500 | The most links one page adds to the crawl. |
| `scope` | `host`, `domain` or `path` | `host` (default): the host of the start URL. `domain`: its registrable domain. `path`: its host and directory. |
| `allow_external` | boolean | Follow links off the start site. `scope` is then ignored. |
| `include`, `exclude` | list of path patterns | Prefix patterns with `*` and `$`. A page must match one `include`, and no `exclude`. |
| `format` | `markdown` or `text` | Default `markdown`. |

## Response fields

The job, from `POST /v1/crawl` and `GET /v1/crawl/{id}`:

| Field | What it is |
| - | - |
| `id`, `request_id` | The job id and the id of this request. |
| `status` | `queued`, `running`, `succeeded`, `failed` or `canceled`. |
| `url`, `max_pages`, `max_depth`, `scope`, `include`, `exclude`, `format` | The job as it was started. |
| `error` | Why a job ended early: `insufficient_credit`, `spend_cap_reached`, `key_revoked`, `account_frozen`, `no_page_fetched`, `time_limit`, `max_pages` or `canceled`. |
| `created_at`, `started_at`, `finished_at`, `expires_at` | Times. The pages and their text are deleted at `expires_at`, 24 hours after the job ends. |
| `counts` | `queued`, `fetched`, `failed`, `blocked`, `skipped`, `duplicates`. |
| `usage` | `pages_billed`, `cost_usd`, `cost_micro`. |
| `pages` | `GET` only: the finished pages, in order. |
| `next_cursor` | `GET` only: the cursor for the next page of results, or null. |

Each entry of `pages`:

| Field | What it is |
| - | - |
| `url`, `final_url`, `depth` | The page, where it ended and its link distance from the start. |
| `status` | `fetched`, `failed`, `robots_blocked`, `skipped` or `duplicate`. Only `fetched` pages are billed. |
| `reason` | Why a page failed, was skipped or is a duplicate. |
| `http_status`, `title`, `language`, `content_type`, `published_at`, `fetched_at` | Page metadata. |
| `content` | The text, in the format you chose. Kept until `expires_at`. |
| `tokens`, `billed`, `duplicate_of` | Size, whether the page was charged, and the page that holds the same document. |

## Limits

| Limit | Value |
| - | - |
| Pages per job | 1,000 without a plan; 2,000 Builder; 5,000 Startup; 10,000 Scale |
| Depth | 10 |
| Run time of a job | 6 hours |
| Pace per site | one request at a time, at least 1 second apart |
| Results kept | 24 hours after the job ends |

## Pricing

$1 per 1,000 pages ($0.001 a page), charged for each page fetched. Starting a job is free. A blocked, failed, skipped or duplicate page is free. It is billed from your prepaid credit, which never expires; an account with no credit gets `402`. See [Plans and billing](https://docs.styne.ai/billing.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.