Skip to content
SnapHTML
Esc
↑↓navigate↵open⌘Jpreview
On this page

Batch rendering

One request, many renders. Queue up to 500 captures or template fills and collect them as they finish.

A batch turns one request into many renders. It exists mostly for templates: five hundred invoices from one saved document is a single call rather than five hundred, and the template is read once instead of five hundred times.

Batches do not answer the way /v1/render does. Five hundred captures take minutes, and a binary response body can only carry one file, so a batch returns an id immediately and the work happens behind it.

curl -X POST https://api.snhtml.com/v1/batch/template \
  -H "authorization: Bearer snhtml_..." \
  -H "content-type: application/json" \
  -d '{
    "templateId": "jh7...",
    "defaults": { "format": "pdf", "pdfFormat": "A4" },
    "items": [
      { "variables": { "invoice": "1842", "total": "£240.00" }, "fileName": "invoice-1842" },
      { "variables": { "invoice": "1843", "total": "£880.50" }, "fileName": "invoice-1843" }
    ]
  }'
{ "batchId": "k57...", "total": 2, "status": "queued" }

Naming a batch

name is optional and is what the batch is called in the dashboard’s batch list:

{ "name": "October invoices", "templateId": "jh7...", "items": [] }

Leave it out and the batch is named after what it renders — the template, or URL batch and HTML batch for the two raw kinds. Thirty jobs with the same derived name is a list nobody can read, so name anything you will come back to. Up to 80 characters.

Reading the batch back echoes the name you gave it, and omits the field if you gave none. The MCP render_batch tool takes it too.

defaults and items

Every render option can be set twice: in defaults, where it applies to every item, and on an item, where it overrides the default. Without that split a five-hundred-invoice body repeats the same nine options five hundred times.

An item in a template batch carries its variables and usually a fileName. An item in a url batch carries a url or html. Anything from render options is accepted in either place.

Every item is resolved against the defaults when the batch is submitted, not when it runs. A bad option on item 400 is a 400 on submission, rather than a surprise four minutes into a job you have already been charged for.

Reading a batch

curl https://api.snhtml.com/v1/batch/k57... \
  -H "authorization: Bearer snhtml_..."
{
  "id": "k57...",
  "status": "partial",
  "total": 2,
  "completed": 1,
  "failed": 1,
  "expiresInSeconds": 604800,
  "items": [
    { "index": 0, "status": "succeeded", "fileName": "invoice-1842.pdf", "url": "https://..." },
    { "index": 1, "status": "failed", "error": "Navigation timeout of 30000 ms exceeded" }
  ]
}

Statuses are queued, running, succeeded, partial, failed and cancelled.

partial is the one worth handling. Three bad items in five hundred is an ordinary outcome, and it stays distinct from failed, which means the batch produced nothing at all. Item URLs appear as soon as that item finishes, so a long batch can be collected while the rest is still running.

How long results last

Results are kept for 7 days from the moment each item renders, then storage deletes them. expiresInSeconds counts down to the earliest of those deadlines — the point at which this batch starts losing files — so it shrinks as the batch ages rather than reporting a fixed window.

Individual url values are signed for 24 hours from the moment you read them, and never for longer than the file itself has left. Reading the batch again mints fresh links.

Once an item expires its url is gone while its status stays succeeded: it did render, and it did count against your quota. Expired results are not refunded, so collect anything you need to keep inside the week.

Quota

A batch reserves its whole quota when it is submitted. A batch that would exceed your monthly limit is refused outright, with the shortfall named:

{ "error": "Monthly render limit reached. This batch needs 500 renders and 112 remain." }

That is deliberate. Reserving per item would let a five-hundred-item batch run four hundred renders, spend them, and then stop at the ceiling.

Items that fail are refunded. A flaky target site should not cost you renders, so the quota is returned for anything that produced no file, and cancelling a batch returns everything not yet rendered. An item that rendered and then expired uncollected is not refunded — it produced a file, and you had a week to fetch it.

Each finished item is one row in your usage log, the same as a single render.

Limits

Free Paid plans
Items per batch 10 500
Batches in progress at once 1 3

The second limit is the one you are most likely to meet. It keeps a single account from occupying the whole render pool, and a batch stops counting against it as soon as it finishes.

Renders inside a batch count against your monthly allowance exactly like any other render — see plans and limits.

Webhooks

Pass webhookUrl and SnapHTML will POST to it once the batch finishes:

{
  "event": "batch.finished",
  "batchId": "k57...",
  "status": "partial",
  "total": 500,
  "completed": 497,
  "failed": 3,
  "finishedAt": 1763212800000
}

The request carries x-snhtml-event: batch.finished and x-snhtml-signature: sha256=<hex>, the HMAC-SHA256 of the raw request body keyed with your webhook signing secret. The secret is shown in the dashboard under Batches, and is created the first time you submit a batch with a webhookUrl.

Verify it before trusting the callback — the URL alone proves nothing:

import { createHmac, timingSafeEqual } from "node:crypto";

function verify(rawBody, header, secret) {
  const expected = createHmac("sha256", secret).update(rawBody).digest("hex");
  const sent = (header ?? "").replace(/^sha256=/, "");
  const a = Buffer.from(expected, "hex");
  const b = Buffer.from(sent, "hex");
  return a.length === b.length && timingSafeEqual(a, b);
}

Compare the digests, not the strings, and verify against the raw body rather than a re-serialised object.

The webhook is a convenience, not a guarantee: it is attempted once, and its outcome is shown on the batch in the dashboard. Polling GET /v1/batch/{id} remains the reliable path.

In the dashboard

You do not need the API for this. Batches → New batch takes a template and a block of rows, so ten invoices is a paste rather than a script, and no API key is involved — you are already signed in.

Pick a template and the first line names the columns, prefilled with the placeholders that template expects. Each line after it is one render:

invoice	total	fileName
1842	£240.00	invoice-1842
1843	£880.50	invoice-1843

Paste it straight out of a spreadsheet. Columns are matched by name, so their order is yours to choose, and a fileName column names the results. Values are tab-separated when you paste from a spreadsheet; typed commas work too, and a comma inside a value is safe if you quote it — "1,200.00".

A column name that matches no placeholder is an error naming the column, rather than a batch of invoices with a silently empty total. A placeholder with no column is a warning, since leaving one blank is sometimes deliberate. Either way the preview shows the first rows as they will be rendered, and the footer shows how many renders the batch will reserve against what is left this month — a batch that would exceed your plan is refused while it is still a form.

The Name field above the source is optional and names the batch in the list; blank, it falls back to the template’s name, or to URL batch or HTML batch.

Without a template, two other sources are there: URL list takes one URL per line, and HTML documents takes one editor per render, each with an optional file name. Empty documents are skipped, so an editor you added and did not fill in costs nothing.

Starting a batch opens over the list rather than replacing it, so the batches already running stay in view.

The list itself shows live progress, since the page updates as items land rather than polling. Every finished batch carries a download button in the list, and opening one shows every item, the error for anything that failed, and a download per render.

Download all gives you one .zip of the whole batch, built once and kept, so asking again is immediate. A batch of a single render is handed over as that render rather than as an archive of one, and a batch too heavy to archive — a few hundred full-page screenshots at 2x, say — falls back to saving its renders one at a time, which is when the browser asks whether the site may download several files.

Renders inside their last day carry an expiry tag, and a batch whose results have been deleted offers no download at all rather than a link that 404s. The batch itself stays in the list, marked: it is the record of a job that ran and was charged for. Running batches can be cancelled there, which returns the unused quota.

From an agent

The MCP server exposes render_batch and get_batch. render_batch takes the same shape as the HTTP endpoints — with templateId for a template batch, without it for URLs and HTML — and returns the id to poll. See MCP server.

Was this page helpful?