PDF4.dev
Render
POST
/api/v1/render

Authorization

AuthorizationRequiredBearer <token>

API key from Settings page. Keys start with p4_live_ prefix.

In: header

Request Body

application/jsonRequired
template_idstring

Template ID (tmpl_xxx) or slug. The template must belong to the authenticated user. null reads as omitted.

htmlstring

Raw HTML string. Supports Handlebars {{variables}} syntax. Use this for one-off renders without saving a template. null reads as omitted.

dataobject

Data to replace {{variables}} in the template. A JSON object: null, "", false and 0 read as omitted, anything else answers 400 invalid_data. Supports strings, numbers, booleans, nested objects, and arrays (for {{#each}} blocks).

formatobject

Page format for this render. It replaces the template's format as a whole: missing fields take the defaults (A4 portrait, 20mm top/bottom and 15mm left/right margins), they are not read from the template. It prints as renders always have: an unknown preset prints a4, an unknown alignment or footer position is ignored, and a margins object prints a side it leaves out at 0 (the default margins apply only when margins is left out). null, "", false and 0 read as omitted. Only a margin (or a custom width or height) that cannot be read answers 400 invalid_format.

deliverystring

How to return the PDF. Omit for a binary application/pdf body (the default). base64 returns JSON with the bytes inline. url stores the render and returns a signed URL valid for 24 hours, which is the recommended path for PDFs over 1 MB and for AI agents that cannot hold binary in context. An organization keeps at most 200 stored renders (500 MiB) by default; past that its oldest are deleted first, so a URL can stop working sooner. After expiry the URL answers 404 render_expired.

Value in: "base64" | "url"
curl -X POST "https://docs.pdf4.dev/api/proxy/api/v1/render" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "invoice",
    "data": {
      "company_name": "Acme Corp",
      "invoice_number": "INV-2025-001",
      "total": "$4,500.00"
    }
  }'

PDF generated successfully. The body depends on delivery: a binary PDF when it is omitted, JSON when it is base64 or url.

{
  "url": "https://pdf4.dev/api/v1/renders/render_a1b2c3d4e5f6a7b8?token=1758531600000.AbCdEf",
  "expires_at": "2026-09-24T09:00:00.000Z",
  "size_bytes": 48213,
  "duration_ms": 287
}