Generate a document
Produce a finished document from structured input.
Goal. Turn structured data — borrower details, terms, schedules — into a finished, styled document your business can send.
This runs the pipeline in the opposite direction to extraction. You supply sections of data; the platform returns a rendered file and a download URL.
Generated endpoint reference
Use Generate a document asynchronously or generate a document synchronously for request schemas. Get generation details documents the retrieval endpoint.
Before you start
An API key, exported as
$DOCAI_API_KEY.Your content, organised into sections.
Step 1 — Structure the content
data is the one required property: an array of at least one section. Each section pairs a sectionKey with its sectionData.
{
"data": [
{
"sectionKey": "borrower",
"sectionData": {
"name": "Northwind Trading Co.",
"entityType": "Corporation",
"address": "44 Harbour Road, Portland, OR"
}
},
{
"sectionKey": "terms",
"sectionData": {
"principal": 250000,
"ratePct": 7.25,
"termMonths": 60
}
}
],
"format": "docx"
}sectionKey must be unique within the array. Order the array the way you want the document to read.
format currently supports docx only, and that is what it defaults to. Asking for "PDF" is not a supported request — if you need PDF, convert after generation.
Step 2 — Style it
style is optional and controls presentation:
fontSize accepts 8–72. Colours take hex with or without the leading #.
Keep a single style object in your configuration rather than repeating it per call — it is the part most likely to change when branding does.
Step 3 — Generate
Asynchronous, returning 201:
Note the field is generationId, not _id — generation names its identifier differently from extraction and classification.
Step 4 — Collect the document
GET /generate/{_id} does not currently work. Every call returns 500 with "Invalid generation ID format" — including when passed the exact generationId the API itself just issued. Tested against the returned UUID, a stripped form, a prefixed form and a nil UUID: all 500. There is no ID format that succeeds.
Until it is fixed, do not build on the async retrieval path. Use one of the two routes below instead.
Route A — POST /generate/sync. The simplest working option: it returns the finished file directly on the same connection.
This response is the binary document itself, not JSON. There is no envelope, no status field, and nothing to parse — write the body straight to a file. A client that calls .json() on it will throw.
Route B — the webhook. Set webhookUrl on the async request and take the download URL from the completion payload, which is covered in step 5.
Generation is fast enough that the synchronous route is reasonable for most cases — unlike extraction, where a ~90-second hold makes it impractical.
Step 5 — Or let the webhook bring it
If you set webhookUrl, the completion payload arrives with the download URL already in it:
Verify the signature before acting on it — see Webhook payloads.
When it goes wrong
400 on submit
data missing or empty
At least one section is required
400 mentioning sections
Duplicate sectionKey
Keys must be unique within data
500 "Invalid generation ID format" on retrieve
The endpoint is broken for all IDs — not your ID
Use /generate/sync or a webhook
JSON parse error on /generate/sync
The response is a binary DOCX
Write the body to a file; do not parse it
Download 403s
The signed webhook URL expired
Signed URLs are time-limited; fetch promptly
Unexpected file type
format only supports docx
Convert downstream
Webhook never arrives
webhookUrl was not HTTPS
HTTPS is required
Related pages
Generation API — all three endpoints and the full schema.
Document Generation — the same capability in the UI.
Webhook payloads — the generation completion payload.
Last updated
Was this helpful?

