Skip to content
Menu · Batches

API reference

Batches

Print up to 50,000 documents of one template in one call, then read the links or be told by webhook.

A batch prints many documents of one template in the background. You send it in one call, at any size up to 50,000 documents, and Composa answers 202 at once. Every file comes back as a link.

EndpointWhat it does
POST /v1/run/batchesStart a batch.
GET /v1/run/batches/{batch_id}Read its progress and its files.
POST /v1/run/batches/{batch_id}/cancelStop it.

Start a batch

curl -X POST https://api.composa.ai/v1/run/batches \  -H "Authorization: Bearer $COMPOSA_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "template_id": "85416813-8d99-46e8-be2b-1d61cee5db38",    "format": "pdf",    "items": [      { "name": "ada", "data": { "full_name": "Ada Lovelace" } },      { "name": "grace", "data": { "full_name": "Grace Hopper" } }    ]  }'

The body takes template_id and exactly one of:

  • items: up to 50,000 objects, each with its data and an optional name. The file downloads under the item's name.
  • data alone: a batch of one. Use it for a document too heavy to print within a request.
  • items_upload: the id of an uploaded file of items. See Large batches over HTTP.

It also takes the options of POST /v1/run: format, quality, scale, width, pages, language and version. It does not take "output": "bytes".

The answer:

json
{  "batch_id": "bat_0k2x9d1qa3f9c04be71",  "status": "queued",  "template_id": "85416813-8d99-46e8-be2b-1d61cee5db38",  "format": "pdf",  "item_count": 2,  "done_count": 0,  "success_count": 0,  "error_count": 0,  "refused_count": 0,  "created_at": "2026-11-08T15:02:11.410Z",  "started_at": null,  "finished_at": null,  "status_url": "https://api.composa.ai/v1/run/batches/bat_0k2x9d1qa3f9c04be71",  "output": "url"}

refused_count counts the items refused because a field had no usable value. They are part of error_count.

What could never print is refused before the 202, as for a single document: an unknown template (404), one with no published version (409), a body the API cannot read (400).

Pictures in a batch

Send each picture as an https:// address in data. Composa fetches it: https only, a public address, up to 5 MB, a JPG, PNG, WebP, GIF or SVG. Do not send base64 data URLs in a batch; they make the body huge.

Read a batch

curl https://api.composa.ai/v1/run/batches/bat_0k2x9d1qa3f9c04be71 \  -H "Authorization: Bearer $COMPOSA_API_KEY"

The answer is the same object with the counts so far. Its status is one of:

StatusMeaning
queuedAccepted, not started.
runningPrinting.
pausedYour Team ran out of pages for the month. It keeps what it printed and goes on when pages come back.
cancelingA cancel was asked; the part already printing finishes.
completedEvery item is done. Some may have failed: check error_count.
failedThe batch stopped before its end. What it printed is kept.
canceledStopped by a cancel.
expiredIt stayed paused for 72 hours in all and gave up.

Once a batch has ended or paused, its answer also lists items, up to 1,000 at a time. Read more with ?offset=1000&limit=1000; next_offset is there while more remain. Each item is one of:

json
{ "index": 0, "name": "ada", "output_url": "https://…/ada.pdf?X-Amz-…", "content_type": "application/pdf" }{ "index": 1, "name": "grace", "error": "1 field has no usable value, so nothing was printed: full_name (not sent).", "code": "no_usable_value" }

An item may also carry language and fallbacks (the fields printed with their fallback). A refused item carries code and problems. An item that fails does not stop the others. The SDKs' waitFor and wait_for poll every 2 seconds until the batch ends or pauses. Instead of polling, you can wait for a batch.completed webhook.

Cancel a batch

curl -X POST https://api.composa.ai/v1/run/batches/bat_0k2x9d1qa3f9c04be71/cancel \  -H "Authorization: Bearer $COMPOSA_API_KEY"

A queued or running batch answers canceling, then becomes canceled. A paused batch is canceled at once. Items never printed are not charged, and come back with "code": "canceled". A batch that has already ended answers 409 with code: "batch_ended".

How long things last

  • A batch's links work for 24 hours. Download the files you need.
  • The batch's record, with its list of links, is kept 24 hours after it ends. After that, reading it answers 404. Save the links you need.
  • The data you sent is deleted the moment the batch ends.

Large batches over HTTP

The SDKs send a large batch as a file by themselves: you call batches.create with your items, at any size. If you call the HTTP API directly and your items come to more than a few MB of JSON, upload them first, in three steps.

  1. Ask for an upload link, with the file's exact size in bytes:
bash
curl -X POST https://api.composa.ai/v1/uploads \  -H "Authorization: Bearer $COMPOSA_API_KEY" \  -H "Content-Type: application/json" \  -d '{ "size": 48213, "content_type": "application/x-ndjson" }'

The answer (201) has an upload_id and an upload_url that takes the file for an hour.

  1. Upload the file, one item per line (NDJSON) or a JSON array, up to 64 MB:
bash
curl -X PUT "<upload_url>" \  -H "content-type: application/x-ndjson" \  --data-binary @items.ndjson
  1. Start the batch with the upload's id in place of items:
bash
curl -X POST https://api.composa.ai/v1/run/batches \  -H "Authorization: Bearer $COMPOSA_API_KEY" \  -H "Content-Type: application/json" \  -d '{ "template_id": "85416813-8d99-46e8-be2b-1d61cee5db38", "items_upload": "upl_…" }'