> For the complete documentation index, see [llms.txt](https://docs.uptiq.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uptiq.ai/document-ai/api-reference/generation.md).

# Doc AI Generation

{% if false %}
Generation creates rendered files from structured data.

{% hint style="info" %}
You can set an HTTPS `webhookUrl` for each generation request.
{% endhint %}

For the templates, sections and styling options as they appear in the product, see [Document Generation](/document-ai/guides-1/document-generation.md).

### Generate document (Async)

`POST /generate`

Requires the `X-Api-Key` header.

**Request body** — `application/json`, required: `GenerateRequest`

| Property     | Type                 | Description                                     |
| ------------ | -------------------- | ----------------------------------------------- |
| `data`       | array<`SectionItem`> | Array of sections (minimum 1 required)          |
| `format`     | string               | Output format (currently only 'docx' supported) |
| `metadata`   | object               | Business context metadata                       |
| `style`      | `StyleConfig`        | Styling configuration                           |
| `webhookUrl` | string               | Completion webhook URL (must be HTTPS)          |

**Nested objects**

`SectionItem`

| Property      | Type   | Description                                               |
| ------------- | ------ | --------------------------------------------------------- |
| `sectionData` | object | Section-specific data                                     |
| `sectionKey`  | string | Section identifier (must be unique within the data array) |

`StyleConfig`

| Property          | Type    | Description                             |
| ----------------- | ------- | --------------------------------------- |
| `fontFamily`      | string  | Font family                             |
| `fontSize`        | integer | Font size (8-72)                        |
| `headerFooter`    | boolean | Include header and footer               |
| `lenderName`      | string  | Lender/company name                     |
| `pageNumbers`     | boolean | Include page numbers                    |
| `primaryColor`    | string  | Primary color (hex with or without #)   |
| `secondaryColor`  | string  | Secondary color (hex with or without #) |
| `tableOfContents` | boolean | Include table of contents               |

**Responses**

| Status | Description                                                             | Schema             |
| ------ | ----------------------------------------------------------------------- | ------------------ |
| `201`  | Created                                                                 | `GenerateResponse` |
| `400`  | Bad Request                                                             | `ValidationError`  |
| `401`  | Authentication required — the `X-Api-Key` header is missing or invalid. |                    |

**Example**

```bash
curl -X POST "https://<api-host>/generate" \
  -H "X-Api-Key: $DOCAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
         "data": [
           {
             "sectionKey": "borrower",
             "sectionData": {
               "name": "Northwind Trading Co.",
               "entityType": "Corporation"
             }
           },
           {
             "sectionKey": "terms",
             "sectionData": {
               "principal": 250000,
               "ratePct": 7.25,
               "termMonths": 60
             }
           }
         ],
         "format": "docx",
         "style": {
           "lenderName": "Example Bank",
           "tableOfContents": true
         },
         "webhookUrl": "https://example.com/hooks/docai"
       }'
```

### Synchronous document generation

`POST /generate/sync`

Requires the `X-Api-Key` header.

**Request body** — `application/json`, required: `GenerateRequest`

| Property     | Type                 | Description                                     |
| ------------ | -------------------- | ----------------------------------------------- |
| `data`       | array<`SectionItem`> | Array of sections (minimum 1 required)          |
| `format`     | string               | Output format (currently only 'docx' supported) |
| `metadata`   | object               | Business context metadata                       |
| `style`      | `StyleConfig`        | Styling configuration                           |
| `webhookUrl` | string               | Completion webhook URL (must be HTTPS)          |

**Nested objects**

`SectionItem`

| Property      | Type   | Description                                               |
| ------------- | ------ | --------------------------------------------------------- |
| `sectionData` | object | Section-specific data                                     |
| `sectionKey`  | string | Section identifier (must be unique within the data array) |

`StyleConfig`

| Property          | Type    | Description                             |
| ----------------- | ------- | --------------------------------------- |
| `fontFamily`      | string  | Font family                             |
| `fontSize`        | integer | Font size (8-72)                        |
| `headerFooter`    | boolean | Include header and footer               |
| `lenderName`      | string  | Lender/company name                     |
| `pageNumbers`     | boolean | Include page numbers                    |
| `primaryColor`    | string  | Primary color (hex with or without #)   |
| `secondaryColor`  | string  | Secondary color (hex with or without #) |
| `tableOfContents` | boolean | Include table of contents               |

**Responses**

| Status | Description                                                             | Schema |
| ------ | ----------------------------------------------------------------------- | ------ |
| `200`  | Returns a binary DOCX response, not JSON. Write the body to disk.       |        |
| `400`  | The request body is missing or invalid.                                 |        |
| `401`  | Authentication required — the `X-Api-Key` header is missing or invalid. |        |

**Example**

```bash
curl -X POST "https://<api-host>/generate/sync" \
  -H "X-Api-Key: $DOCAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
         "data": [
           {
             "sectionKey": "borrower",
             "sectionData": {
               "name": "Northwind Trading Co.",
               "entityType": "Corporation"
             }
           }
         ],
         "format": "docx"
       }'
```

### Get document generation details

`GET /generate/{_id}`

Requires the `X-Api-Key` header.

**Path and query parameters**

| Parameter | In   | Type   | Required | Description |
| --------- | ---- | ------ | -------- | ----------- |
| `_id`     | path | string | Yes      |             |

**Responses**

| Status | Description                                                             | Schema                  |
| ------ | ----------------------------------------------------------------------- | ----------------------- |
| `200`  | OK                                                                      | `GetGenerationResponse` |
| `400`  | Bad Request                                                             | `ValidationError`       |
| `401`  | Authentication required — the `X-Api-Key` header is missing or invalid. |                         |

**Example**

```bash
curl -X GET "https://<api-host>/generate/{_id}" \
  -H "X-Api-Key: $DOCAI_API_KEY"
```

### Related pages

* [Document Generation](/document-ai/guides-1/document-generation.md) — the same capability through the UI.
* [Generate a document](/document-ai/cookbooks/generate-a-document.md) — a working call, end to end.
  {% endif %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.uptiq.ai/document-ai/api-reference/generation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
