# Crawl guides

The jobs Crawl is built for, each as the requests that do it.

## One section of a site

Start at the section's first page and keep the crawl inside it with `include`:

```bash
curl https://api.millionshort.com/v1/crawl \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.org/docs",
    "max_pages": 200,
    "max_depth": 4,
    "include": ["^/docs/"],
    "exclude": ["^/docs/archive/", "\\.pdf$"]
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/crawl",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "url": "https://example.org/docs",
        "max_pages": 200,
        "max_depth": 4,
        "include": [
            "^/docs/"
        ],
        "exclude": [
            "^/docs/archive/",
            "\\.pdf$"
        ]
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/crawl', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "url": "https://example.org/docs",
    "max_pages": 200,
    "max_depth": 4,
    "include": [
      "^/docs/"
    ],
    "exclude": [
      "^/docs/archive/",
      "\\.pdf$"
    ]
  }),
});
if (!res.ok) throw new Error(`POST /v1/crawl failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

- `include` and `exclude` are regular expressions on the path. `^/docs/` keeps the paths that start with `/docs/`.
- The start page is crawled even when it does not match `include`.
- The sitemap is read at the start, so pages of the section that nothing links to are found too. `"sitemap": "skip"` follows links only.
- Not sure what the section holds? [Map](https://millionshort.com/docs/map) it first with the same `include`. A map of 200 URLs costs 20 credits and shows what a crawl would fetch.

## Poll, and page through the results

A poll returns up to 50 results and a `next` cursor. Wait for the crawl to end, then follow `next` until it is `null`:

```python
import os
import time

from millionshort import MillionShort

client = MillionShort(api_key=os.environ["MILLIONSHORT_API_KEY"])

job = client.crawl(url="https://example.org/docs", max_pages=200, include=["^/docs/"])
while job.status in ("queued", "running"):
    time.sleep(5)
    job = client.get_crawl(job.id)

pages = []
while True:
    for page in job.results:
        if page["status"] == "ok":
            pages.append(page)
    if not job.next:
        break
    job = client.get_crawl(job.id, cursor=job.next)

print(len(pages), "pages,", job.credits_used, "credits,", job.stop_reason)
```

```ts
import { MillionShort } from 'millionshort';

const client = new MillionShort({ apiKey: process.env.MILLIONSHORT_API_KEY });

let job = await client.crawl('https://example.org/docs', { maxPages: 200, include: ['^/docs/'] });
while (job.status === 'queued' || job.status === 'running') {
  await new Promise((resolve) => setTimeout(resolve, 5000));
  job = await client.getCrawl(job.id);
}

const pages = [];
for (;;) {
  for (const page of job.results ?? []) {
    if (page.status === 'ok') pages.push(page);
  }
  if (!job.next) break;
  job = await client.getCrawl(job.id, { cursor: job.next });
}

console.log(pages.length, 'pages,', job.credits_used, 'credits,', job.stop_reason);
```

You can read results while the crawl runs too: a poll returns up to 50 of the pages finished so far, and while the crawl is running, `next` is where to carry on from once any page has been read, even when no more pages are there yet (before the first page finishes it is `null`: poll again without a cursor). Poll again with it and you get only the pages that finished since, or none yet; you never read a page twice. Pages come in the order they finished, so a cursor stays good. `next` is `null` once the crawl has ended and you have read its last page. Polling is free. Keep it to one poll every few seconds: the limit is 120 a minute for your team.

## Be told when it ends

Register a [webhook endpoint](https://millionshort.com/docs/webhooks) once, verify it, and name it on the crawl:

```bash
curl https://api.millionshort.com/v1/crawl \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: docs-2026-11-20" \
  -d '{
    "url": "https://example.org/docs",
    "max_pages": 200,
    "webhook_id": "wh_01jd3v9x7k2m4n6p8q0r2s4t6v"
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/crawl",
    headers={
        "Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"],
        "Idempotency-Key": "docs-2026-11-20",
    },
    json={
        "url": "https://example.org/docs",
        "max_pages": 200,
        "webhook_id": "wh_01jd3v9x7k2m4n6p8q0r2s4t6v"
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/crawl', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': 'docs-2026-11-20',
  },
  body: JSON.stringify({
    "url": "https://example.org/docs",
    "max_pages": 200,
    "webhook_id": "wh_01jd3v9x7k2m4n6p8q0r2s4t6v"
  }),
});
if (!res.ok) throw new Error(`POST /v1/crawl failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

When the crawl ends, the endpoint receives `crawl.completed`, or `crawl.failed` for a crawl that failed, with the crawl's `id`, `status`, `stop_reason` and counts. The event does not carry the pages. Fetch them with `GET /v1/crawl/{id}` and page through them as above.

The `Idempotency-Key` makes a retry safe: sending the same request again within 24 hours returns the crawl that was started, and starts no second one.

## A crawl of stored copies

With `mode: "cached"`, the pages come from the copies we already hold. The site is asked for its robots.txt and its sitemaps (with `sitemap: "skip"`, its robots.txt alone), and for no page at all:

```bash
curl https://api.millionshort.com/v1/crawl \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.org/", "mode": "cached", "max_pages": 100 }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/crawl",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "url": "https://example.org/",
        "mode": "cached",
        "max_pages": 100
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/crawl', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "url": "https://example.org/",
    "mode": "cached",
    "max_pages": 100
  }),
});
if (!res.ok) throw new Error(`POST /v1/crawl failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

- The URLs are the sitemap's and the ones our index holds for the site. Links are not followed, because a stored copy carries none.
- A page we hold comes back with `mode_used: "cached"`. Its `fetched_at` is the earliest day the copy can have been captured, and `captured_before` the latest.
- A page we do not hold comes back as `NOT_IN_CACHE`, free. Read those with [Extract](https://millionshort.com/docs/extract) `live`, or run a `live` crawl.
- A site whose robots.txt closes the start page to our bot is not served from stored copies either: the crawl ends `failed` with `ROBOTS_DISALLOWED`, and costs nothing. When the robots.txt cannot be read, it ends with `ROBOTS_UNAVAILABLE`. The copies themselves are served as Extract's `cached` serves them: robots.txt is not asked about each page.
- Its pages do not count towards your daily limit for the site, because none is fetched. Stored copies are looked up at about 60 a minute per team.

`cached` is switched off for now, as it is for Extract, and may not ship.

## Use the labels

Every page that comes back says what it is, at no charge: `topic`, `page_type` and `source_hint`, each with a confidence. Two ways to use them:

- **Sort after the crawl.** Route pages by `page_type` in your own code: documentation to one index, blog posts to another.
- **Keep only some pages.** With `page_types`, `topics` or `source_hints` on the request, a page that does not match comes back with `filtered: true` and no content, so nothing unwanted reaches your model:

```bash
curl https://api.millionshort.com/v1/crawl \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.org/",
    "max_pages": 300,
    "page_types": ["documentation", "tutorials", "faqs"]
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/crawl",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "url": "https://example.org/",
        "max_pages": 300,
        "page_types": [
            "documentation",
            "tutorials",
            "faqs"
        ]
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/crawl', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "url": "https://example.org/",
    "max_pages": 300,
    "page_types": [
      "documentation",
      "tutorials",
      "faqs"
    ]
  }),
});
if (!res.ok) throw new Error(`POST /v1/crawl failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

A filtered page was fetched to be labelled, so it is charged. When the unwanted pages live under their own paths, `exclude` is cheaper: a path that is excluded is never fetched.

## Staying polite

A crawl follows the rules every fetch of ours follows, and you cannot switch them off:

- **robots.txt.** Every page we fetch is checked. A page it closes to our bot comes back as `ROBOTS_DISALLOWED`, free. A site that closes everything gives a crawl that fails with that code and costs nothing, in `cached` as well.
- **Pace.** A site gets at most one page a second from all our customers together, and one account at most 30 pages of one site a minute. Plan for about two seconds a page: 100 pages in three to four minutes, 1,000 in about 35. A large crawl takes hours.
- **The daily limit.** A team may fetch 2,000 pages of one site a day, the sitemap files a crawl reads included. A page fetched again and found unchanged counts once, so crawling the same section again the same day uses the limit only for what changed. At the limit a crawl ends with `stop_reason: "site_daily_limit"` and keeps its pages, whatever your plan's `max_pages` ceiling.
- Two crawls of the same site share that pace. Run them one after the other.

## Follow links off the site

By default a crawl stays on the host you named. `"include_subdomains": true` widens it to the site's other hosts. `"same_domain": false` lets it follow links to other sites:

```bash
curl https://api.millionshort.com/v1/crawl \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.org/links",
    "max_pages": 100,
    "max_depth": 1,
    "same_domain": false,
    "remove_top_sites": 10000
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/crawl",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "url": "https://example.org/links",
        "max_pages": 100,
        "max_depth": 1,
        "same_domain": False,
        "remove_top_sites": 10000
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/crawl', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "url": "https://example.org/links",
    "max_pages": 100,
    "max_depth": 1,
    "same_domain": false,
    "remove_top_sites": 10000
  }),
});
if (!res.ok) throw new Error(`POST /v1/crawl failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

This reads a page of links and the pages it points at. `remove_top_sites` leaves out links to the 10,000 most popular sites, the same cut [Search](https://millionshort.com/docs/search/remove-top-sites) has, so the crawl spends its pages on the primary sources and not on the large platforms every page links to. Keep `max_depth` small: off the site, the number of links grows fast, and `max_pages` is what stops it.

## Cancel, and what is charged

```bash
curl -X DELETE https://api.millionshort.com/v1/crawl/$CRAWL_ID \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY"
```

```python
import os

import requests

r = requests.delete(
    f"https://api.millionshort.com/v1/crawl/{os.environ['CRAWL_ID']}",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch(`https://api.millionshort.com/v1/crawl/${process.env.CRAWL_ID}`, {
  method: 'DELETE',
  headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
});
if (!res.ok) throw new Error(`DELETE /v1/crawl/… failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

- The pages that came back before the cancel are kept, can still be read for 7 days, and stay charged.
- The rest of the hold is handed back at once.
- Pages that were being fetched at that moment are dropped, and are not charged.

## From an agent, over MCP

The [MCP server](https://millionshort.com/docs/mcp#map-and-crawl) has four tools for this: `map`, `crawl`, `crawl_status` and `crawl_cancel`. `crawl` takes the scope and mode fields of a crawl request (not `formats`, `max_chars`, `json` or `webhook_id`: pages come back as Markdown) and returns the job:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "crawl",
    "arguments": { "url": "https://example.org/docs", "max_pages": 30, "include": ["^/docs/"] }
  }
}
```

A line for your agent's instructions: "To read a section of a site, call `crawl` with a small `max_pages`, then call `crawl_status` with the crawl's id as `crawl_id` every few seconds until its status is no longer `queued` or `running`. Each page costs a credit, so ask for no more pages than you will read."
