# Batch renders

- **URL**: /documentation/api-reference/batches

A batch renders one template once per row of values — product cards from a catalogue, certificates from a class list, listings from a spreadsheet — in one call. You send the template, the options every row shares and up to 1,000 rows; the call answers at once with a `batchId` and the rows render in the background. Each row becomes an ordinary [render request](https://buildonce.app/documentation/api-reference/renders) (`rnd_…`): it shows in render history (where `GET /v1/renders` marks it with `"batch": { "batchId": "bat_…", "row": 3 }`), fires the usual render webhooks and is charged like a single render — only if it succeeds.

- A failed row keeps its error and the other rows carry on.
- Too many rows, or not enough credits for every row, is refused before anything runs.
- When the last row ends, one `batch.completed` webhook is sent.
- A finished batch downloads as one ZIP of every file plus `results.csv`.

> No code? The dashboard’s **Bulk generate** page does all of this from a CSV or a paste from Excel or Google Sheets, with column matching, live progress and the ZIP.

## POST /v1/renders/batch

### `POST /v1/renders/batch`

Start a batch: one template, the options every row shares, and one entry per row. Answers 202 with the batch.

Scope: `render:write`

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `templateId` | `tpl_…` | yes | The template's public id. |
| `items` | `array (1–1,000)` | yes | One entry per render: { modifications, fileName? }. modifications works exactly like a single render’s, page-scoped keys (page2@headline) included; an empty value keeps the template’s own. |
| `items[].fileName` | `string` | no | Names this row’s file(s) in the ZIP. Defaults to row-<n>. |
| `format` | `"png" \| "jpeg" \| "pdf" \| "mp4" \| "webm" \| "gif"` | no | Defaults to png. Applies to every row. |
| `allPages` | `boolean` | no | Render every page per row (one file per page; a PDF is one file). |
| `pageId` | `string` | no | Which page to render when allPages is off. |
| `video` | `object` | no | fps, scale, quality — as on a single render. Video formats only. |
| `animation` | `object` | no | Per-render timing, as on a single render. |
| `idempotencyKey` | `string` | no | Send the same key again and you get the same batch back — nothing runs twice. |

**cURL**

```bash
curl -X POST https://buildonce.app/v1/renders/batch \
  -H "Authorization: Bearer fl_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d ''
```

**Node**

```js
const res = await fetch("https://buildonce.app/v1/renders/batch", {
  method: "POST",
  headers: {
    Authorization: "Bearer fl_live_YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    templateId: "tpl_123",
    items: rows.map((row) => ({
      modifications: { headline: row.title, photo: row.image },
      fileName: row.sku,
    })),
  }),
});
const { data } = await res.json(); // 202: data.batchId
```

**Python**

```python
import requests

res = requests.post(
    "https://buildonce.app/v1/renders/batch",
    headers={"Authorization": "Bearer fl_live_YOUR_API_KEY"},
    json={
        "templateId": "tpl_123",
        "items": [
            {"modifications": {"headline": r["title"]}, "fileName": r["sku"]}
            for r in rows
        ],
    },
)
batch_id = res.json()["data"]["batchId"]
```

**Request body**

```json
{
  "templateId": "tpl_123",
  "format": "png",
  "idempotencyKey": "spring-sale-2026",
  "items": [
    { "modifications": { "headline": "Summer sale", "photo": "https://…/a.jpg" }, "fileName": "summer-sale" },
    { "modifications": { "headline": "Autumn deals", "page2@price": "$19" }, "fileName": "autumn" },
    { "modifications": { "headline": "Winter warmers" } }
  ]
}
```

The 202 response is the batch with `status: "queued"` and every row waiting — the same shape as [GET /v1/batches/:batchId](#get). A `publish` block is not accepted on a batch (400).

## GET /v1/batches/:batchId

### `GET /v1/batches/:batchId`

A batch's progress and every row: its status, its renderId and files once it succeeded, or its error. Poll it while the batch runs — it is exempt from the plan's per-minute limit.

Scope: `render:write`

| Name | Type | Description |
| --- | --- | --- |
| `status` | `"queued" \| "processing" \| "succeeded" \| "partial" \| "failed" \| "canceled"` | partial: some rows failed. canceled: it was stopped. finishedAt is set once every row has ended. |
| `items[].status` | `"queued" \| "processing" \| "succeeded" \| "failed" \| "canceled"` | Each row on its own. |
| `remaining` | `number` | Rows not ended yet. |
| `options` | `object` | The shared options the batch ran with — send failed rows again with the same settings. |

**cURL**

```bash
curl https://buildonce.app/v1/batches/bat_89acrvdg3k4y \
  -H "Authorization: Bearer fl_live_YOUR_API_KEY"
```

**Node**

```js
async function waitForBatch(batchId) {
  for (;;) {
    const res = await fetch(`https://buildonce.app/v1/batches/${batchId}`, {
      headers: { Authorization: "Bearer fl_live_YOUR_API_KEY" },
    });
    const { data } = await res.json();
    if (data.finishedAt) return data;
    await new Promise((r) => setTimeout(r, 5000));
  }
}
```

**Response**

```json
{
  "batchId": "bat_89acrvdg3k4y",
  "templateId": "tpl_123",
  "templateName": "Spring sale · Square",
  "templateThumbnailUrl": "https://…/thumbnail/p1.png",
  "format": "png",
  "options": { "allPages": false },
  "status": "partial",
  "total": 3,
  "succeeded": 2,
  "failed": 1,
  "canceled": 0,
  "remaining": 0,
  "creditsCharged": 2,
  "createdAt": "2026-11-24T09:15:00.000Z",
  "finishedAt": "2026-11-24T09:15:42.000Z",
  "items": [
    {
      "row": 1,
      "status": "succeeded",
      "fileName": "summer-sale",
      "modifications": { "headline": "Summer sale", "photo": "https://…/a.jpg" },
      "renderId": "rnd_wdbw5wrmp2wg",
      "files": [{ "url": "https://…/renders/45ae….png", "pageId": "s1", "width": 1080, "height": 1080, "byteSize": 482113 }],
      "creditsCharged": 1,
      "error": null
    },
    {
      "row": 2,
      "status": "failed",
      "fileName": "autumn",
      "modifications": { "headline": "Autumn deals", "page2@price": "$19" },
      "renderId": null,
      "files": [],
      "creditsCharged": 0,
      "error": { "status": 400, "code": "IMAGE_FETCH_FAILED", "message": "Image from \"example.com\" could not be loaded: HTTP 404" }
    }
    /* … one entry per row */
  ]
}
```

## GET /v1/batches

### `GET /v1/batches`

The workspace's batches, newest first, without their rows.

Scope: `render:write`

| Name | Type | Description |
| --- | --- | --- |
| `page` | `number` | Defaults to 1. |
| `limit` | `number` | Defaults to 25, max 100. |
| `status` | `"running" \| "done" \| "errors" \| "stopped"` | running: not finished. done: every row succeeded. errors: partial or failed. stopped: canceled. |
| `search` | `string` | Part of the template's name. |

**cURL**

```bash
curl "https://buildonce.app/v1/batches?status=errors&limit=10" \
  -H "Authorization: Bearer fl_live_YOUR_API_KEY"
```

## POST /v1/batches/:batchId/cancel

### `POST /v1/batches/:batchId/cancel`

Stop a batch. Rows not started yet become canceled and are never charged; rows already rendering finish. Returns the batch.

Scope: `render:write`

**cURL**

```bash
curl -X POST https://buildonce.app/v1/batches/bat_89acrvdg3k4y/cancel \
  -H "Authorization: Bearer fl_live_YOUR_API_KEY"
```

To carry on later, send the canceled rows (their `modifications` and `fileName` are in the batch) as a new batch. Canceling a finished batch changes nothing.

## GET /v1/batches/:batchId/zip

### `GET /v1/batches/:batchId/zip`

Every file of a finished batch as one ZIP, plus results.csv. Streamed as it is written, so even a very large batch starts downloading at once.

Scope: `render:write`

| Name | Type | Description |
| --- | --- | --- |
| `from` | `number` | First row to include (1-based). |
| `to` | `number` | Last row to include. |

**cURL**

```bash
curl -L https://buildonce.app/v1/batches/bat_89acrvdg3k4y/zip \
  -H "Authorization: Bearer fl_live_YOUR_API_KEY" \
  -o batch.zip
```

- Files are named by the row’s `fileName`, else `row-<n>`; a multi-page row adds `-p1`, `-p2`…; duplicate names get `-2`.
- `results.csv` lists every row — row, status, file_name, render_id, urls, error_code, error_message — so you can bring the links back into your own sheet.
- 409 `BATCH_NOT_FINISHED` while it runs. Over 4 GB is 413 `BATCH_ZIP_TOO_LARGE`: download it in parts with `from` and `to`. A range that selects no rows (`from` after `to`, or past the last row) is 400 `BATCH_ZIP_RANGE_INVALID`; a `to` past the end just stops at the last row.

## Limits & credits

| Name | Type | Description |
| --- | --- | --- |
| `Rows per batch` | `Free: 50 · paid: 1,000` | Over it is 400 BATCH_TOO_LARGE, before anything runs. |
| `Video rows` | `100` | mp4, webm or gif: one row can take minutes to render. |
| `Credits` | `as a single render` | 1 per image or PDF page, 1 per started video second — charged per row, only when it succeeds. Not enough credits for every row is 402 before anything runs. |
| `Speed` | `background` | Rows render one after another on their own lane, so a big batch never holds up your single renders. 500 images take about 8 minutes. |

## batch.completed webhook

Subscribe a [workspace webhook](https://buildonce.app/documentation/webhooks) to `batch.completed` to hear once when the last row ends — instead of polling. Each row still sends its own `render.completed` or `render.failed`.

**Payload**

```json
{
  "type": "batch.completed",
  "data": {
    "batchId": "bat_89acrvdg3k4y",
    "status": "partial",
    "total": 500,
    "succeeded": 498,
    "failed": 2,
    "canceled": 0,
    "creditsCharged": 498
  }
}
```

## Errors

| Name | Type | Description |
| --- | --- | --- |
| `400 BATCH_TOO_LARGE` | `create` | More rows than the plan or format allows. Split the rows into smaller batches. |
| `402 INSUFFICIENT_CREDITS` | `create` | The workspace can’t pay for every row. Nothing was queued or charged. |
| `503 BATCH_UNAVAILABLE / QUEUE_UNAVAILABLE` | `create` | Batches can’t be queued right now. Try again; nothing was charged. |
| `404 BATCH_NOT_FOUND` | `get, cancel, zip` | No batch with that id in this workspace. |
| `409 BATCH_NOT_FINISHED` | `zip` | The batch is still rendering. |
| `400 BATCH_ZIP_RANGE_INVALID` | `zip` | from is after to, or past the batch’s last row. |
| `413 BATCH_ZIP_TOO_LARGE` | `zip` | Over 4 GB — use from / to. |

A row’s own failure (a broken image link, an unknown page…) is not an HTTP error: it is that row’s `error`, with the same code a single render would return.
