For the complete documentation index, see llms.txt. This page is also available as Markdown.
Generation

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.

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.

Generation is the only capability whose request takes its own webhookUrl (HTTPS required). You can direct an individual job to an endpoint without touching account settings — extraction and classification cannot do this.

Step 4 — Collect the document

Route A — POST /generate/sync. The simplest working option: it returns the finished file directly on the same connection.

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

Symptom
Cause
Fix

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

Last updated