# Crawl

Read many pages of one site as a job.

Reads the pages of one site as an [asynchronous job](https://websearch.fast/docs/concepts/jobs), starting from a URL and following its sitemaps and links within the limits you set. The host of `url` is the scope of the crawl. Pages that `robots.txt` disallows are counted as `skipped_robots` and not read.

Pages can be listed while the crawl runs. A crawl and its pages are kept for 7 days after the job ends.

### What is charged

Each page read with `status: ok` is charged once. Failed and skipped pages are free. A cancelled crawl is charged for the pages read before the cancel took effect.

Units: `crawl_page`. `usage.items` in the response lists them.

## Start a crawl of one site

```
POST https://api.websearch.fast/v1/web/crawl
```

Planned. Until it ships, calls return `501 api_not_implemented`.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string |  | 1 to 128 bytes; a retry with the same key and body within 24 hours returns the same job. 1 to 128 characters. |

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `url` | string | yes | Public http(s) URL, at most 2048 bytes. At most 2048 characters. |
| `limit` | integer |  | 1 to 10,000. Default `100`. |
| `max_depth` | integer |  | 0 to 20. Default `3`. |
| `include_paths` | array of string |  | At most 50 items. |
| `exclude_paths` | array of string |  | At most 50 items. |
| `include_subdomains` | boolean |  | Default `false`. |
| `use_sitemaps` | boolean |  | Default `true`. |
| `ignore_query` | boolean |  | Default `true`. |
| `format` | string |  | One of `markdown`, `text`, `html`. Default `markdown`. |
| `mode` | string |  | One of `main`, `full`. Default `main`. |
| `max_chars` | integer |  | 1000 to 500,000. Default `20000`. |
| `include_links` | boolean |  | Default `false`. |
| `include_metadata` | boolean |  | Default `true`. |
| `webhook_url` | string |  | Public https URL that receives the final job object, signed with webhook_secret. At most 500 characters. |
| `metadata` | object |  | Your own string values, echoed on the job; at most 4 KB. |

### Example request

curl:

```bash
curl https://api.websearch.fast/v1/web/crawl \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://docs.example.org/",
    "limit": 200,
    "include_paths": ["/guide/**"],
    "max_depth": 3
  }'
```

Python:

```python
import os
import uuid
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/crawl",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
        "url": "https://docs.example.org/",
        "limit": 200,
        "include_paths": ["/guide/**"],
        "max_depth": 3,
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/crawl", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    url: "https://docs.example.org/",
    limit: 200,
    include_paths: ["/guide/**"],
    max_depth: 3,
  }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

### Response fields

Job created.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `web.crawl`. |
| `id` | string | yes | At most 64 characters. Starts with `wc_`. |
| `status` | string | yes | One of `queued`, `running`, `succeeded`, `failed`, `cancelled`. |
| `stop_reason` | string |  | One of `completed`, `budget`, `limit`, `cancelled`, `deadline`, `error`. |
| `created_at` | integer | yes |  |
| `started_at` | integer |  |  |
| `completed_at` | integer |  |  |
| `input` | object | yes |  |
| `usage` | object | yes |  |
| `usage.items` | array of object | yes |  |
| `usage.items.unit` | string | yes | Billable unit, for example search_web, content_page, fetch_page, geocode, autocomplete, knowledge. |
| `usage.items.count` | integer | yes |  |
| `error` | object |  |  |
| `error.code` | string | yes |  |
| `error.message` | string |  |  |
| `poll_after_ms` | integer |  |  |
| `webhook_secret` | string |  | Only in the create response, when webhook_url was set. |
| `metadata` | object |  |  |
| `expires_at` | integer |  |  |
| `progress` | object |  |  |
| `progress.discovered` | integer |  |  |
| `progress.queued` | integer |  |  |
| `progress.read` | integer |  |  |
| `progress.failed` | integer |  |  |
| `progress.skipped_robots` | integer |  |  |
| `progress.skipped_scope` | integer |  |  |

### Errors

| Status | Codes |
| --- | --- |
| `400` | `invalid_request`, `invalid_url`, `invalid_schema` or `invalid_image`. Not charged. |
| `401` | `invalid_token`. Not charged. |
| `403` | `pre_consume_token_quota_failed` (the key's own spending limit), `access_denied`, `web_not_allowed` or `model_not_in_plan` (customer keys while plans cannot include the web tools). Not charged. |
| `404` | `not_found` or `invalid_endpoint`. Not charged. |
| `409` | `idempotency_conflict` or `request_in_progress`. Not charged. |
| `413` | `read_request_body_failed`: the request body is over the limit. Not charged. |
| `422` | `fetch_failed`, `site_refused`, `page_too_large` or `extraction_failed`. Not charged. |
| `429` | `rate_limited`, `concurrency_limited`, `api_key_temporarily_frozen`, or the failure guard. Not charged. |
| `500` | `internal_error`. Not charged. |
| `501` | `api_not_implemented`: the endpoint, type or option has not shipped. Not charged. |
| `503` | `source_unavailable`, `web_api_disabled`, `token_cache_busy` or `billing_busy` (the charge could not be prepared in time; retry after Retry-After). Not charged. |
| `504` | timeout. Not charged. |

## Get a crawl job

```
GET https://api.websearch.fast/v1/web/crawl/{id}
```

Planned. Until it ships, calls return `501 api_not_implemented`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | Starts with `wc_`. |

### Example request

curl:

```bash
curl https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY"
```

Python:

```python
import os
import httpx

response = httpx.get(
    "https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

### Response fields

The job.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `web.crawl`. |
| `id` | string | yes | At most 64 characters. Starts with `wc_`. |
| `status` | string | yes | One of `queued`, `running`, `succeeded`, `failed`, `cancelled`. |
| `stop_reason` | string |  | One of `completed`, `budget`, `limit`, `cancelled`, `deadline`, `error`. |
| `created_at` | integer | yes |  |
| `started_at` | integer |  |  |
| `completed_at` | integer |  |  |
| `input` | object | yes |  |
| `usage` | object | yes |  |
| `usage.items` | array of object | yes |  |
| `usage.items.unit` | string | yes | Billable unit, for example search_web, content_page, fetch_page, geocode, autocomplete, knowledge. |
| `usage.items.count` | integer | yes |  |
| `error` | object |  |  |
| `error.code` | string | yes |  |
| `error.message` | string |  |  |
| `poll_after_ms` | integer |  |  |
| `webhook_secret` | string |  | Only in the create response, when webhook_url was set. |
| `metadata` | object |  |  |
| `expires_at` | integer |  |  |
| `progress` | object |  |  |
| `progress.discovered` | integer |  |  |
| `progress.queued` | integer |  |  |
| `progress.read` | integer |  |  |
| `progress.failed` | integer |  |  |
| `progress.skipped_robots` | integer |  |  |
| `progress.skipped_scope` | integer |  |  |

### Errors

| Status | Codes |
| --- | --- |
| `400` | `invalid_request`, `invalid_url`, `invalid_schema` or `invalid_image`. Not charged. |
| `401` | `invalid_token`. Not charged. |
| `403` | `pre_consume_token_quota_failed` (the key's own spending limit), `access_denied`, `web_not_allowed` or `model_not_in_plan` (customer keys while plans cannot include the web tools). Not charged. |
| `404` | `not_found` or `invalid_endpoint`. Not charged. |
| `413` | `read_request_body_failed`: the request body is over the limit. Not charged. |
| `429` | `rate_limited`, `concurrency_limited`, `api_key_temporarily_frozen`, or the failure guard. Not charged. |
| `500` | `internal_error`. Not charged. |
| `501` | `api_not_implemented`: the endpoint, type or option has not shipped. Not charged. |
| `503` | `source_unavailable`, `web_api_disabled`, `token_cache_busy` or `billing_busy` (the charge could not be prepared in time; retry after Retry-After). Not charged. |
| `504` | timeout. Not charged. |

## Pages of a crawl

```
GET https://api.websearch.fast/v1/web/crawl/{id}/pages
```

Planned. Until it ships, calls return `501 api_not_implemented`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | Starts with `wc_`. |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `starting_after` | string |  | next_cursor of the previous page. |
| `limit` | integer |  | 1 to 100. Default `20`. |
| `status` | string |  | One of `ok`, `failed`, `all`. Default `ok`. |

### Example request

curl:

```bash
curl "https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P/pages?limit=20" \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY"
```

Python:

```python
import os
import httpx

response = httpx.get(
    "https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P/pages",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    params={
        "limit": 20,
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P/pages?limit=20", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

### Response fields

A page of results, oldest first.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `list`. |
| `data` | array of object | yes |  |
| `data.requested_url` | string | yes |  |
| `data.url` | string |  | Final URL after redirects. For now the requested URL, because the reader does not report the final one yet. |
| `data.status` | string | yes | One of `ok`, `failed`. |
| `data.error` | object |  |  |
| `data.error.code` | string | yes |  |
| `data.error.message` | string | yes |  |
| `data.http_status` | integer |  |  |
| `data.content_type` | string |  |  |
| `data.title` | string |  |  |
| `data.content` | string |  |  |
| `data.format` | string |  | One of `markdown`, `text`, `html`. |
| `data.chars` | integer |  |  |
| `data.truncated` | boolean |  |  |
| `data.extraction` | string |  | Neutral label of how the text was taken. New values can appear. One of `article`, `full_page`, `document`, `feed`, `plain`, `structured`. |
| `data.language` | string |  |  |
| `data.published_at` | string |  |  |
| `data.metadata` | object |  |  |
| `data.metadata.description` | string |  |  |
| `data.metadata.author` | string |  |  |
| `data.metadata.site_name` | string |  |  |
| `data.metadata.canonical_url` | string |  |  |
| `data.metadata.image_url` | string |  |  |
| `data.metadata.keywords` | array of string |  |  |
| `data.metadata.meta` | object |  | Meta name and property tags, at most 100. |
| `data.metadata.json_ld` | array of object |  | At most 20 items. |
| `data.links` | array of object |  | At most 1000 items. |
| `data.links.url` | string | yes |  |
| `data.links.text` | string |  |  |
| `data.links.rel` | string |  |  |
| `data.images` | array of object |  | At most 200 items. |
| `data.images.url` | string | yes |  |
| `data.images.alt` | string |  |  |
| `data.images.width` | integer |  |  |
| `data.images.height` | integer |  |  |
| `data.pdf_pages` | integer |  |  |
| `data.relevant_passages` | array of string |  |  |
| `data.fetched_at` | integer |  |  |
| `data.depth` | integer |  |  |
| `has_more` | boolean | yes |  |
| `next_cursor` | string |  |  |

### Errors

| Status | Codes |
| --- | --- |
| `400` | `invalid_request`, `invalid_url`, `invalid_schema` or `invalid_image`. Not charged. |
| `401` | `invalid_token`. Not charged. |
| `403` | `pre_consume_token_quota_failed` (the key's own spending limit), `access_denied`, `web_not_allowed` or `model_not_in_plan` (customer keys while plans cannot include the web tools). Not charged. |
| `404` | `not_found` or `invalid_endpoint`. Not charged. |
| `413` | `read_request_body_failed`: the request body is over the limit. Not charged. |
| `429` | `rate_limited`, `concurrency_limited`, `api_key_temporarily_frozen`, or the failure guard. Not charged. |
| `500` | `internal_error`. Not charged. |
| `501` | `api_not_implemented`: the endpoint, type or option has not shipped. Not charged. |
| `503` | `source_unavailable`, `web_api_disabled`, `token_cache_busy` or `billing_busy` (the charge could not be prepared in time; retry after Retry-After). Not charged. |
| `504` | timeout. Not charged. |

## Cancel a crawl

```
POST https://api.websearch.fast/v1/web/crawl/{id}/cancel
```

Planned. Until it ships, calls return `501 api_not_implemented`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | Starts with `wc_`. |

### Example request

curl:

```bash
curl -X POST https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P/cancel \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY"
```

Python:

```python
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P/cancel",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/crawl/wc_01JD7R4K8P/cancel", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

### Response fields

The job.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `web.crawl`. |
| `id` | string | yes | At most 64 characters. Starts with `wc_`. |
| `status` | string | yes | One of `queued`, `running`, `succeeded`, `failed`, `cancelled`. |
| `stop_reason` | string |  | One of `completed`, `budget`, `limit`, `cancelled`, `deadline`, `error`. |
| `created_at` | integer | yes |  |
| `started_at` | integer |  |  |
| `completed_at` | integer |  |  |
| `input` | object | yes |  |
| `usage` | object | yes |  |
| `usage.items` | array of object | yes |  |
| `usage.items.unit` | string | yes | Billable unit, for example search_web, content_page, fetch_page, geocode, autocomplete, knowledge. |
| `usage.items.count` | integer | yes |  |
| `error` | object |  |  |
| `error.code` | string | yes |  |
| `error.message` | string |  |  |
| `poll_after_ms` | integer |  |  |
| `webhook_secret` | string |  | Only in the create response, when webhook_url was set. |
| `metadata` | object |  |  |
| `expires_at` | integer |  |  |
| `progress` | object |  |  |
| `progress.discovered` | integer |  |  |
| `progress.queued` | integer |  |  |
| `progress.read` | integer |  |  |
| `progress.failed` | integer |  |  |
| `progress.skipped_robots` | integer |  |  |
| `progress.skipped_scope` | integer |  |  |

### Errors

| Status | Codes |
| --- | --- |
| `400` | `invalid_request`, `invalid_url`, `invalid_schema` or `invalid_image`. Not charged. |
| `401` | `invalid_token`. Not charged. |
| `403` | `pre_consume_token_quota_failed` (the key's own spending limit), `access_denied`, `web_not_allowed` or `model_not_in_plan` (customer keys while plans cannot include the web tools). Not charged. |
| `404` | `not_found` or `invalid_endpoint`. Not charged. |
| `413` | `read_request_body_failed`: the request body is over the limit. Not charged. |
| `429` | `rate_limited`, `concurrency_limited`, `api_key_temporarily_frozen`, or the failure guard. Not charged. |
| `500` | `internal_error`. Not charged. |
| `501` | `api_not_implemented`: the endpoint, type or option has not shipped. Not charged. |
| `503` | `source_unavailable`, `web_api_disabled`, `token_cache_busy` or `billing_busy` (the charge could not be prepared in time; retry after Retry-After). Not charged. |
| `504` | timeout. Not charged. |
