When to use async
Sync (POST .../generate) returns the PDF in one response but ties up your HTTP connection for the whole render.
Async (POST .../generate-async) returns a jobId immediately. Your server can do other work while the PDF is built. Use async for batches, large documents, or when you want a webhook instead of polling.
Flow
- Create
POST /api/v1/templates/{id}/generate-asyncwith JSON data. - Wait poll
GET /api/v1/jobs/{jobId}or receive a webhook. - Download use
downloadUrlfrom the job, orGET /api/v1/jobs/{jobId}/download.
Step 1: Create the job
Idempotency
SetidempotencyKey to something unique per business object (invoice ID, order ID). If your client retries after a network error, you get the same job back with deduplicated: true instead of duplicate PDFs. In that case, status can be any existing job state (not always queued).
Step 2: Check status
Poll untilstatus is no longer queued or processing:
Suggested poll spacing
| Time since create | Interval |
|---|---|
| First 10 s | 2 s |
| 10 s to 60 s | 5 s |
| After 60 s | 15 s |
Step 3: Download
Full Node example
Webhooks
For production, addwebhookUrl and webhookSecret so you are notified when the job finishes. See Webhooks.