Batch Document Generation
High-throughput asynchronous document rendering and webhook notifications for high-volume workflows.
Generate dozens or thousands of documents in parallel using the ComposeIt Batch API. Batch processing is designed for high-throughput workflows such as monthly billing runs, bulk certificate generation, or mass mailing campaigns.
Plan Availability
Batch document generation is exclusively available on Premium and Enterprise plans. Overages are permitted, so batch requests are not blocked by merge balances.
How Batch Generation Works
Batch document generation follows an asynchronous, queue-driven pipeline and you listen to webhooks for results
Document States
Each document created via batch moves through the following state machine:
| Status | Description |
|---|---|
queued | The document has been created and enqueued for background processing. |
rendering | The document is currently actively being compiled and rendered by the engine. |
succeeded | Generation completed successfully. Output files (PDF, HTML, images) are ready. |
failed | Generation failed after all retries (default 3 retries) were exhausted. |
expired | The document surpassed its expiresAt timestamp before completion. |
Endpoints
1. Standard Batch Export
Generate multiple documents from a template using an array of data payloads.
- Endpoint:
POST /api/export/batch - Authentication:
x-api-keyheader (requiresdocuments:writepermission) - Status Code:
202 Accepted
Request Body Schema
| Field | Type | Required | Description |
|---|---|---|---|
templateId | String | Yes | ID of the template to generate documents from. |
templateVersion | Number | No | Specific version snapshot number (defaults to latest active). |
formats | Array | Yes | Output formats to generate: ["pdf"], ["html"], ["image"], ["mjml"]. |
items | Array | Yes | Array of items to generate (minimum 1 item). Alias: documents. |
items[].data | Object | No | Dynamic JSON data mapped to template variables for this document. |
items[].metadata | Object | No | Custom key-value pairs stored on the document record. |
items[].expiresAt | String / Date | No | Custom ISO timestamp when this specific document expires. |
items[].formats | Array | No | Override output formats for this specific item. |
imageType | String | No | Image format if image format requested: "png" or "jpg". |
renderOptions | Object | No | Optional rendering settings (margins, scale, paper size, etc.). |
expiresAt | String / Date | No | Default expiration timestamp for all documents in this batch. |
sendForSignature | Boolean | No | Send generated PDF to DocuSeal for e-signature. |
docusealConnection | String | No | Saved DocuSeal integration connection ID. |
Test Documents Not Allowed
Batch document generation cannot be run in test mode (isTest: true). Batch
requests containing isTest: true will be rejected with 400 Bad Request.
Request Example
curl -X POST "https://app.composeit.app/api/export/batch" \
-H "Content-Type: application/json" \
-H "x-api-key: your_api_key_here" \
-d '{
"templateId": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"formats": ["pdf"],
"items": [
{
"data": {
"invoiceNumber": "INV-2026-001",
"customerName": "Acme Corp",
"total": 1250.00
},
"metadata": { "orderId": "ord_101" }
},
{
"data": {
"invoiceNumber": "INV-2026-002",
"customerName": "Globex Inc",
"total": 3400.50
},
"metadata": { "orderId": "ord_102" }
}
]
}'Response Format (202 Accepted)
Documents are returned immediately in queued status:
{
"batchId": "batch_91a0b3f81e3a47",
"totalCount": 2,
"status": "queued",
"documents": [
{
"id": "doc_a1b2c3d4",
"organizationId": "org_123456789",
"templateId": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"createdById": "user_123456789",
"status": "queued",
"outputs": [],
"metadata": {
"batchId": "batch_91a0b3f81e3a47",
"batchIndex": 0,
"totalCount": 2,
"orderId": "ord_101"
},
"expiresAt": "2026-10-08T12:00:00.000Z",
"createdAt": "2026-10-07T12:00:00.000Z"
},
{
"id": "doc_e5f6g7h8",
"organizationId": "org_123456789",
"templateId": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"createdById": "user_123456789",
"status": "queued",
"outputs": [],
"metadata": {
"batchId": "batch_91a0b3f81e3a47",
"batchIndex": 1,
"totalCount": 2,
"orderId": "ord_102"
},
"expiresAt": "2026-10-08T12:00:00.000Z",
"createdAt": "2026-10-07T12:00:00.000Z"
}
]
}2. Platform Batch Export
Batch generate documents directly from external datasources (Airtable, Notion, Baserow, Fibery, NocoDB, etc.) across multiple records.
- Endpoint:
POST /api/export/batch/:platform(e.g./api/export/batch/airtable) - Authentication:
x-api-keyheader or encrypted linktoken - Status Code:
202 Accepted
Request Body Schema
| Field | Type | Required | Description |
|---|---|---|---|
templateId | String | Yes | ID of the template connected to the platform data source. |
recordIds | Array | Yes | List of record IDs in the platform table to merge into documents. |
baseId | String | No | Platform base or database identifier (if applicable). |
tableId | String | No | Platform table identifier. |
formats | Array | No | Output formats (defaults to ["pdf"]). |
attachmentField | String | No | Field name in the platform where the generated file should be saved. |
overwriteExisting | Boolean | No | Whether to overwrite existing files in the attachment field. |
Request Example
curl -X POST "https://app.composeit.app/api/export/batch/airtable" \
-H "Content-Type: application/json" \
-H "x-api-key: your_api_key_here" \
-d '{
"templateId": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"recordIds": ["rec_111111", "rec_222222", "rec_333333"],
"formats": ["pdf"]
}'Webhooks
ComposeIt delivers secure, signed, and reliable webhook notifications directly to your application endpoints as batch documents progress through the rendering pipeline.
Supported Events
| Event Type | Trigger Description |
|---|---|
document.succeeded | Fired each time an individual document finishes rendering successfully. |
document.failed | Fired when a document rendering permanently fails after all retries. |
document.expired | Fired if a document expires before completion. |
documents.completed | Fired once all documents in a batch have reached a terminal state and no documents are retrying. |
Event Payloads
document.succeeded
{
"event": "document.succeeded",
"documentId": "doc_a1b2c3d4",
"batchId": "batch_91a0b3f81e3a47",
"organizationId": "org_123456789",
"status": "succeeded",
"outputs": [
{
"label": "pdf",
"storageKey": "exports/doc_a1b2c3d4.pdf",
"url": "https://storage.composeit.website/outputs/doc_a1b2c3d4.pdf",
"mimeType": "application/pdf",
"sizeBytes": 145020,
"checksum": "8f14e45fceea167a5a36dedd4bea2543"
}
],
"metadata": {
"documentName": "Invoice INV-2026-001",
"orderId": "ord_101"
},
"completedAt": "2026-10-07T12:00:03.142Z"
}document.failed
{
"event": "document.failed",
"documentId": "doc_e5f6g7h8",
"batchId": "batch_91a0b3f81e3a47",
"organizationId": "org_123456789",
"status": "failed",
"error": "Image asset URL timed out after 30000ms",
"metadata": {
"orderId": "ord_102"
},
"completedAt": "2026-10-07T12:00:35.890Z"
}document.expired
{
"event": "document.expired",
"documentId": "doc_e5f6g7h8",
"batchId": "batch_91a0b3f81e3a47",
"organizationId": "org_123456789",
"status": "expired",
"metadata": {
"orderId": "ord_102"
},
"completedAt": "2026-10-07T12:00:35.890Z"
}documents.completed
Sent when all documents in the batch have reached a final status (succeeded, failed, or expired) and no documents are in retry:
{
"event": "documents.completed",
"batchId": "batch_91a0b3f81e3a47",
"organizationId": "org_123456789",
"totalDocuments": 100,
"succeededCount": 98,
"failedCount": 2,
"expiredCount": 0,
"completedAt": "2026-10-07T12:01:15.512Z"
}Consuming Webhooks
Your webhook endpoint should accept POST requests with a JSON body, inspect the event property, and return a 2xx status code quickly to acknowledge receipt.
Basic Webhook Consumer
// app/api/webhooks/composeit/route.ts (Next.js App Router example)
import { NextResponse } from "next/server";
export async function POST(req: Request) {
const payload = await req.json();
switch (payload.event) {
case "document.succeeded":
console.log(`Document ${payload.documentId} succeeded:`, payload.outputs);
break;
case "document.failed":
console.error(`Document ${payload.documentId} failed:`, payload.error);
break;
case "document.expired":
console.warn(`Document ${payload.documentId} expired before rendering.`);
break;
case "documents.completed":
console.log(
`Batch ${payload.batchId} finished: ${payload.succeededCount}/${payload.totalDocuments} succeeded.`,
);
break;
default:
console.log("Unhandled webhook event:", payload.event);
}
return NextResponse.json({ received: true }, { status: 200 });
}Verifying Webhook Signatures with Svix
ComposeIt uses Svix to sign every webhook request. To ensure that incoming webhook requests originate from ComposeIt and have not been tampered with, verify the svix-id, svix-timestamp, and svix-signature headers against the raw request body using your endpoint's signing secret (whsec_...) from the Webhook Portal.
1. Install the Svix SDK
npm install svix2. Verify and Handle the Signed Payload
// app/api/webhooks/composeit/route.ts
import { Webhook } from "svix";
import { NextResponse } from "next/server";
const webhookSecret = process.env.COMPOSEIT_WEBHOOK_SECRET!; // e.g. "whsec_..."
export async function POST(req: Request) {
const svixId = req.headers.get("svix-id");
const svixTimestamp = req.headers.get("svix-timestamp");
const svixSignature = req.headers.get("svix-signature");
if (!svixId || !svixTimestamp || !svixSignature) {
return NextResponse.json(
{ error: "Missing Svix signature headers" },
{ status: 400 },
);
}
// IMPORTANT: Use the raw text body for signature verification
const rawBody = await req.text();
const wh = new Webhook(webhookSecret);
let payload: Record<string, any>;
try {
payload = wh.verify(rawBody, {
"svix-id": svixId,
"svix-timestamp": svixTimestamp,
"svix-signature": svixSignature,
}) as Record<string, any>;
} catch (err) {
console.error("Webhook signature verification failed:", err);
return NextResponse.json({ error: "Invalid signature" }, { status: 400 });
}
switch (payload.event) {
case "document.succeeded":
// Handle generated outputs (e.g. payload.outputs)
break;
case "document.failed":
// Handle permanent failure (e.g. payload.error)
break;
case "document.expired":
// Handle document expiration
break;
case "documents.completed":
// Handle full batch completion summary
break;
}
return NextResponse.json({ received: true }, { status: 200 });
}API Reference
Integrate ComposeIt document generation and template management into your workflows.
Model Context Protocol (MCP) Server
Connect AI assistants (Claude, Cursor, Antigravity, Windsurf) directly to ComposeIt for autonomous template creation, editing, document compilation, and asset management.