Skip to main content

Batch Generation

POST https://api.getdocuforge.dev/v1/generate/batch Submit up to 100 PDF generation jobs at once. Jobs are processed asynchronously via a background queue. Returns 202 Accepted with a batch ID and individual generation IDs that you can poll for status.

Request Headers

HeaderRequiredDescription
AuthorizationYesBearer df_live_sk_...
Content-TypeYesapplication/json
Idempotency-KeyNoUnique key to prevent duplicate batch submissions. Cached for 24 hours.

Request Body

ParameterTypeRequiredDescription
itemsobject[]YesArray of generation jobs (1-100 items)
webhookstringNoURL to POST when the final job in the batch completes

Item Object

Each item accepts the same parameters as a single /v1/generate call:
ParameterTypeRequiredDescription
htmlstring*Raw HTML to convert to PDF
reactstring*JSX/TSX source code
templatestring*Template ID (tmpl_xxx)
dataobjectNoData to merge into template variables
stylesstringNoAdditional CSS styles
optionsobjectNoPDF rendering options (format, margin, orientation, header, footer, printBackground)
outputstringNo"url" (default) or "base64"
* Each item must include at least one of html, react, or template.

Options Object

ParameterTypeDefaultDescription
formatstring or object"A4""A4", "Letter", "Legal", or { width, height }
marginstring or objectUniform margin string or { top, right, bottom, left }
orientationstring"portrait""portrait" or "landscape"
headerstringHTML for page header
footerstringHTML for page footer
printBackgroundbooleanInclude background colors/images

Example

curl -X POST https://api.getdocuforge.dev/v1/generate/batch \
  -H "Authorization: Bearer df_live_sk_..." \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: batch-invoice-run-2026-03" \
  -d '{
    "items": [
      {
        "template": "tmpl_abc123",
        "data": { "company": "Acme Corp", "total": 1500 }
      },
      {
        "template": "tmpl_abc123",
        "data": { "company": "Globex Inc", "total": 2300 }
      },
      {
        "html": "<h1>Custom Report</h1><p>Summary data here.</p>",
        "options": { "format": "Letter", "orientation": "landscape" }
      }
    ],
    "webhook": "https://example.com/webhooks/batch-complete"
  }'

Response — 202 Accepted

{
  "batch_id": "batch_a1b2c3d4e5f6g7h8",
  "total": 3,
  "generations": [
    { "id": "gen_abc123", "index": 0 },
    { "id": "gen_def456", "index": 1 },
    { "id": "gen_ghi789", "index": 2 }
  ],
  "status": "queued"
}
Use the individual generation IDs with GET /v1/generations/:id to check the status of each job.

Idempotency

Pass an Idempotency-Key header with a unique string to safely retry failed requests. If a batch with the same key was already submitted within 24 hours, the original response is returned without creating duplicate jobs.

Errors

StatusCodeDescription
400VALIDATION_ERRORInvalid items array (empty, over 100, or missing input)
401UNAUTHORIZEDInvalid or missing API key
403USAGE_LIMIT_EXCEEDEDMonthly PDF limit reached
429RATE_LIMITEDToo many requests
500INTERNAL_ERRORServer error creating batch