# Extract batch

Up to 1,000 URLs as one job, with results you poll for or a webhook when it ends.

```text
POST   https://api.millionshort.com/v1/extract/batch
GET    https://api.millionshort.com/v1/extract/batch/{id}
DELETE https://api.millionshort.com/v1/extract/batch/{id}
```

The same extraction as [`POST /v1/extract`](https://millionshort.com/docs/extract/parameters), for up to 1,000 URLs, run as a job.

## Submit

The body is the Extract request, with two differences: `urls` takes 1 to 1,000 entries, and there is one more field.

| Field | Type | Default | Notes |
|---|---|---|---|
| `urls` | array of strings, 1 to 1,000, distinct | | Required |
| `mode` | `auto`, `cached`, `live`, `rendered`, `unblock`, `stealth` | `"auto"` | As for Extract |
| `max_age_hours` | integer, 0 to 8,760 | `168` | As for Extract |
| `formats` | array of `markdown`, `text`, `links`, `metadata` | `["markdown","metadata"]` | As for Extract |
| `max_chars` | integer, 1 to 500,000 | `50000` | As for Extract |
| `webhook_id` | string | | An active [webhook endpoint](https://millionshort.com/docs/webhooks) of your team. Optional |
| `topics`, `page_types`, `source_hints` | arrays of slugs | | Keep only the pages with these [labels](https://millionshort.com/docs/extract/parameters#labels). Optional |

```bash
curl https://api.millionshort.com/v1/extract/batch \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: nightly-2026-11-18" \
  -d '{
    "urls": ["https://example.com/a", "https://example.com/b"],
    "mode": "live"
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/extract/batch",
    headers={
        "Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"],
        "Idempotency-Key": "nightly-2026-11-18",
    },
    json={
        "urls": [
            "https://example.com/a",
            "https://example.com/b"
        ],
        "mode": "live"
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/extract/batch', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': 'nightly-2026-11-18',
  },
  body: JSON.stringify({
    "urls": [
      "https://example.com/a",
      "https://example.com/b"
    ],
    "mode": "live"
  }),
});
if (!res.ok) throw new Error(`POST /v1/extract/batch failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

- An `Idempotency-Key` header is honoured for 24 hours: sending the same submit twice starts one batch.
- Submit holds the price of the whole batch at the mode asked for. A team that cannot cover it gets `429 INSUFFICIENT_CREDITS` and nothing starts.
- A team may have 5 batches open at once.

The answer is the job, with `status: "queued"`.

## Poll

```bash
curl https://api.millionshort.com/v1/extract/batch/$BATCH_ID \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY"
```

```python
import os

import requests

r = requests.get(
    f"https://api.millionshort.com/v1/extract/batch/{os.environ['BATCH_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/extract/batch/${process.env.BATCH_ID}`, {
  headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
});
if (!res.ok) throw new Error(`GET /v1/extract/batch/… failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

| Field | Type | Notes |
|---|---|---|
| `id` | string | |
| `status` | `queued`, `running`, `completed`, `cancelled`, `failed` | |
| `total` | integer | URLs in the batch |
| `completed` | integer | URLs done so far, succeeded or failed |
| `failed` | integer | URLs that failed |
| `results` | array | Extract results, up to 50 at a time |
| `next` | string or null | Pass as `?cursor=` to get the next page of results; `null` at the end |

Polling is free and does not count against the plan's requests a minute. It has its own limit of 120 a minute per team. Results are kept for 7 days.

## Cancel

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

```python
import os

import requests

r = requests.delete(
    f"https://api.millionshort.com/v1/extract/batch/{os.environ['BATCH_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/extract/batch/${process.env.BATCH_ID}`, {
  method: 'DELETE',
  headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
});
if (!res.ok) throw new Error(`DELETE /v1/extract/batch/… failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

Work that has finished is charged; what is left of the hold is handed back.

## How a batch runs

- Every result carries its `topic`, `page_type`, `source_hint` and `label_confidence`, as for [Extract](https://millionshort.com/docs/extract/parameters#labels). With `topics`, `page_types` or `source_hints`, a page that does not pass counts as `completed`, has `filtered: true` and no content, and is charged for its fetch. A batch has no `summary` and no warnings: count the entries with `filtered: true`. A page whose labels could not be made is kept, with `null` labels. For a large crawl list this is how to keep, say, only the articles about health and skip reading the rest.

- Finished pages are charged as they finish, at the price of the mode actually used. The rest of the hold is handed back when the batch ends.
- Batch work waits for a busy site; it does not fail with `HOST_BUSY` at once. A page whose site is busy for us waits its turn, at no cost to it, for as long as the batch has been running for less than 60 minutes. After that, a page that meets the busy site five more times fails as `HOST_BUSY`, free. A batch on one site is slow on purpose: one page a second for all customers together, and at most half of that for one team, so 1,000 pages of one site take about 35 minutes. Several batches of the same site share that pace, so run them one after the other. Batch work also gives way to synchronous Extract calls.
- A `cached` batch never fails a page because of the pace of our own lookups: stored copies are looked up at about 60 a minute per team, and the batch waits for them. A batch of 500 takes about eight minutes.
- A page that cannot be fetched yet for another reason (a `robots.txt` that could not be read, for example) is tried again later in the batch, five times in all.
- The [daily limit per site](https://millionshort.com/docs/extract/parameters#the-daily-limit-per-site) holds for batches as for single calls.
- A batch that has not ended 24 hours after submit becomes `failed`, and what is left of its hold is handed back.
- With `webhook_id`, an `extract_batch.completed` event is delivered when the batch ends, carrying `id`, `status`, `total`, `completed` and `failed`.

## Errors

`400 INVALID_PARAM` (also for a `webhook_id` that is not an active endpoint of the team), `400 UNSUPPORTED_OPTION`, `401` for a missing or refused key, `404 JOB_NOT_FOUND` for a batch that does not exist or is not yours, `429 INSUFFICIENT_CREDITS` and `429 RATE_LIMITED`. Per-URL errors are the ones on the [Extract](https://millionshort.com/docs/extract/parameters#per-url-errors) page.
