Docs / Async and batch

Rendering

Async and batch

A normal render holds the connection open until the file is ready. For slow pages, large jobs, or work you do not want to wait on, render in the background instead.

#Async renders

Add "async": true to any render request. You get 202 Accepted and a queued document straight away.

curl https://devilpdf.com/v1/render \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "invoice",
    "data": { "number": "INV-1001" },
    "async": true,
    "webhook_url": "https://example.com/hooks/devilpdf"
  }'
Response
{
  "object": "document",
  "id": "doc_GFGX0Hwx0ttTEJGh5AOP",
  "status": "queued",
  "format": "pdf",
  "url": null,
  "template": "invoice",
  "source": "template",
  "created_at": "2026-03-14T14:02:10.588Z",
  "completed_at": null
}

The response above is shortened; you get the full document object. The document stays queued until it finishes as succeeded or failed. Async documents are always stored, whatever output you pass, so there is a link to fetch when they finish.

#Find out when it is done

Webhooks (recommended). Add a webhook endpoint, or pass webhook_url on the request. You receive document.succeeded or document.failed with the full document, including its url.

Polling. Fetch the document until its status is final.

async function waitForDocument(id) {
  for (;;) {
    const res = await fetch(`https://devilpdf.com/v1/documents/${id}`, {
      headers: { Authorization: `Bearer ${process.env.DEVILPDF_API_KEY}` },
    });
    const doc = await res.json();
    if (doc.status === "succeeded") return doc;
    if (doc.status === "failed") throw new Error(doc.error.message);
    await new Promise((r) => setTimeout(r, 1000));
  }
}

#Batches

POST /v1/render/batch queues many documents in one request. Put what the documents share at the top level and what differs in items.

curl https://devilpdf.com/v1/render/batch \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "certificate",
    "options": { "page_size": "Letter" },
    "items": [
      { "data": { "recipient": { "name": "Amara Okonkwo" } }, "filename": "amara-okonkwo" },
      { "data": { "recipient": { "name": "Tomás Rivera" } }, "filename": "tomas-rivera" },
      { "data": { "recipient": { "name": "Helena Voss" } }, "filename": "helena-voss", "metadata": { "student_id": "4417" } }
    ]
  }'

Each item is merged over the shared fields, so an item can set or override anything a single render accepts: data, filename, metadata, options, even template. Batch documents are always stored and returned as links.

Response
{
  "object": "batch",
  "id": "batch_eKcpMkp96fGjxDtcjhdw",
  "status": "queued",
  "total": 3,
  "documents": [
    { "id": "doc_LQqwn9WE8y2E1oUjWDcw", "status": "queued" },
    { "id": "doc_df5gB79ogpL0bvGTdVQR", "status": "queued" },
    { "id": "doc_89yliGxc5eRBv4JTO9k6", "status": "queued" }
  ]
}

The documents array is in the same order as your items.

#Validation

The whole batch is checked before anything is queued. If one item is invalid, or a template does not exist, the request fails and nothing is rendered. Item errors are prefixed with their position, for example items[2]: "filename" must be a string.

#Quota

A batch takes its full size from your monthly allowance up front. If you have 40 documents left and send 50 items, the request fails with quota_exceeded and nothing is queued. Documents that fail to render are given back.

#Batch size

PlanDocuments per batch
Free25
Starter100
Growth500
Business1,000
Scale1,000

#Check a batch

curl https://devilpdf.com/v1/batches/batch_eKcpMkp96fGjxDtcjhdw \
  -H "Authorization: Bearer $DEVILPDF_API_KEY"
Response
{
  "object": "batch",
  "id": "batch_eKcpMkp96fGjxDtcjhdw",
  "status": "completed",
  "total": 3,
  "succeeded": 3,
  "failed": 0
}

status is processing until every document has succeeded or failed, then completed.

To list a batch's documents with their links, filter the documents list:

curl "https://devilpdf.com/v1/documents?batch=batch_eKcpMkp96fGjxDtcjhdw&limit=100" \
  -H "Authorization: Bearer $DEVILPDF_API_KEY"

#Batch webhooks

Each document in a batch fires its own document.succeeded or document.failed event. When the last one finishes, you also get one batch.completed event with the totals. See webhooks.

#Retries

If a background render fails for a reason that may pass, such as a timeout or a busy renderer, it is retried automatically, up to three attempts. Errors in your request or template are not retried.