POST returns immediately with a batch_id while the job queue runs items in parallel. Detect completion via polling or the batch.completed webhook event. Ideal for monthly invoice runs, ticket issuance, and bulk reports.
POST returns 201 with a batch_id right away. Clients don't wait around or risk request timeouts and can move on to other work.
Either poll GET /api/pdf/batch/ or subscribe to the batch.completed webhook event — pick whichever fits your architecture.
Each item runs with tries=2. Failed items are returned with error_message so you can selectively re-submit just those.
| Use the batch API | Call one at a time | |
|---|---|---|
| 100-item wall time | 1 API call, 201 instantly | 100 sync calls, several minutes total |
| Client-side control | Hold a batch_id, check later | Manage parallelism, ordering, retries yourself |
| On error | Re-run only the failed items | Plan for partial-failure recovery yourself |
| Best fit | 10+ items, especially nightly runs | 1–few real-time generations |
// Submit up to 100 PDFs in one call → 201 Created with batch_id
const res = await fetch("/api/pdf/batch", {
method: "POST",
headers: { "Authorization": `Bearer ${API_KEY}` },
body: JSON.stringify({
items: orders.map(o => ({
type: "html",
html: renderInvoice(o),
expiration_hours: 72,
})),
}),
});
const { data: { batch_id } } = await res.json();
// Either poll for status...
const status = await fetch(`/api/pdf/batch/${batch_id}`, {
headers: { "Authorization": `Bearer ${API_KEY}` },
}).then(r => r.json());
// ...or subscribe to the batch.completed webhook event.