# Batch

Up to 100 calls in one request.

Runs many calls in one request. Each item names an `endpoint` and carries that endpoint's request body. Items for `search`, `fetch`, `autocomplete`, `knowledge`, `geocode` and `reverse-geocode` run. Items for `places/details` and `extract` answer `501 api_not_implemented` each. An item for `research`, `crawl`, `map`, `lens` or `batch` refuses the whole batch with `400 invalid_request`.

The sync mode takes 1 to 100 items with at most 100 URLs in total and answers within 60 seconds; items not finished by then come back as `504 timeout` and are free. `custom_id` is optional, at most 64 bytes and unique within the batch. `webhook_url` and `metadata` are refused with `400` in sync mode.

The sync response lists `results` in request order, each with the HTTP status the call would have had alone and its response or error body. The batch itself is `200` whenever the outer body was valid. The async mode (up to 20,000 items as a [job](https://websearch.fast/docs/concepts/jobs)) is planned and answers `501 api_not_implemented`.

### What is charged

Each item is charged by the rule of its own endpoint. Items that failed are free.

## Many calls in one request

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

`mode: sync` is available; `mode: async` is planned.

### 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 |
| --- | --- | --- | --- |
| `requests` | array of object | yes | sync: 1 to 100 items; async: 1 to 20000. The fetch items of a sync batch name at most 100 URLs in total, otherwise 400. Items for endpoints that have not shipped answer 501 in their own result; mode async answers 501 until S3. 1 to 20,000 items. |
| `requests.custom_id` | string |  | Your id, at most 64 bytes and unique in the batch, otherwise 400. Defaults to the index as a string. At most 64 characters. |
| `requests.endpoint` | string | yes | One of `search`, `fetch`, `autocomplete`, `knowledge`, `geocode`, `reverse-geocode`, `places/details`, `extract`. |
| `requests.body` | object | yes | The request body of that endpoint. |
| `mode` | string |  | One of `sync`, `async`. Default `sync`. |
| `webhook_url` | string |  | Async only; refused with 400 in sync mode. Public https URL that receives the final job object, signed with webhook_secret. At most 500 characters. |
| `metadata` | object |  | Async only; refused with 400 in sync mode. Your own string values, echoed on the job; at most 4 KB. |

### Example request

curl:

```bash
curl https://api.websearch.fast/v1/web/batch \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {
        "custom_id": "q1",
        "endpoint": "search",
        "body": {"q": "postgres 18 release notes", "num": 3}
      },
      {
        "custom_id": "q2",
        "endpoint": "fetch",
        "body": {"url": "https://www.example.org/changelog"}
      }
    ]
  }'
```

Python:

```python
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/batch",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    json={
        "requests": [
            {
                "custom_id": "q1",
                "endpoint": "search",
                "body": {"q": "postgres 18 release notes", "num": 3},
            },
            {
                "custom_id": "q2",
                "endpoint": "fetch",
                "body": {"url": "https://www.example.org/changelog"},
            },
        ],
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/batch", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    requests: [
      {
        custom_id: "q1",
        endpoint: "search",
        body: { q: "postgres 18 release notes", num: 3 },
      },
      {
        custom_id: "q2",
        endpoint: "fetch",
        body: { url: "https://www.example.org/changelog" },
      },
    ],
  }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

### Example response

```json
{
  "object": "web.batch",
  "request_id": "20261128120006123456789a1b2c3d4Kx7Qm2Pf",
  "created": 1795867206,
  "results": [
    {
      "index": 0,
      "custom_id": "q1",
      "status": 200,
      "body": {
        "object": "web.search",
        "results": [],
        "warnings": [{"code": "no_results"}]
      }
    },
    {
      "index": 1,
      "custom_id": "q2",
      "status": 422,
      "body": {
        "error": {
          "code": "fetch_failed",
          "message": "The page could not be read.",
          "type": "invalid_request_error",
          "param": "url"
        }
      }
    }
  ],
  "usage": {"charged": false, "items": []}
}
```

### Response fields (200)

Sync batch (mode sync, S2): per-item status and body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `web.batch`. |
| `request_id` | string | yes | Same as the X-Request-Id header. |
| `created` | integer | yes | Unix seconds (UTC). |
| `usage` | object | yes |  |
| `usage.charged` | boolean | 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 |  |
| `warnings` | array of object |  |  |
| `warnings.code` | string | yes | For example no_results, content_partial, answer_unavailable, partial, all_failed, reach_reduced. |
| `warnings.message` | string |  |  |
| `warnings.param` | string |  |  |
| `results` | array of object | yes |  |
| `results.index` | integer | yes |  |
| `results.custom_id` | string |  |  |
| `results.status` | integer | yes | HTTP status the call would have had alone. |
| `results.body` | object | yes | Response or error body of the item. |

### Response fields (202)

Async batch job created (mode async, S3).

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `web.batch_job`. |
| `id` | string | yes | At most 64 characters. Starts with `wb_`. |
| `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.total` | integer |  |  |
| `progress.done` | integer |  |  |
| `progress.ok` | integer |  |  |
| `progress.failed` | 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. |
| `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 an async batch

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

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

### Path parameters

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

### Example request

curl:

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

Python:

```python
import os
import httpx

response = httpx.get(
    "https://api.websearch.fast/v1/web/batch/wb_01JD7S2N5T",
    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/batch/wb_01JD7S2N5T", {
  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.batch_job`. |
| `id` | string | yes | At most 64 characters. Starts with `wb_`. |
| `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.total` | integer |  |  |
| `progress.done` | integer |  |  |
| `progress.ok` | integer |  |  |
| `progress.failed` | 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. |

## Results of an async batch

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

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

### Path parameters

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

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `starting_after` | string |  | next_cursor of the previous page. |
| `limit` | integer |  | 1 to 1000. Default `100`. |

### Example request

curl:

```bash
curl "https://api.websearch.fast/v1/web/batch/wb_01JD7S2N5T/results?limit=100" \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY"
```

Python:

```python
import os
import httpx

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

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/batch/wb_01JD7S2N5T/results?limit=100", {
  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

Finished items in request order.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `list`. |
| `data` | array of object | yes |  |
| `data.index` | integer | yes |  |
| `data.custom_id` | string |  |  |
| `data.status` | integer | yes | HTTP status the call would have had alone. |
| `data.body` | object | yes | Response or error body of the item. |
| `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 an async batch

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

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

### Path parameters

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

### Example request

curl:

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

Python:

```python
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/batch/wb_01JD7S2N5T/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/batch/wb_01JD7S2N5T/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.batch_job`. |
| `id` | string | yes | At most 64 characters. Starts with `wb_`. |
| `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.total` | integer |  |  |
| `progress.done` | integer |  |  |
| `progress.ok` | integer |  |  |
| `progress.failed` | 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. |
