---
title: "Compose a document from a template and data"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cloudraker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Compose a document from a template and data

Path: CloudRaker Paperwork API › Capabilities

`POST /v1/compose`

Renders one of your saved compose templates with the data you pass, and gives you back a PDF.

`template` is the config id or slug from [POST /v1/compose/configs](https://docs.cloudraker.com/paperwork/capabilities/compose). `data` is validated against that template's JSON Schema BEFORE anything renders, so a missing field costs you a `422` with the exact instance paths, not a broken document.

```json
{ "template": "invoice", "data": { "customer": "Acme", "total": 1240 } }
```

`output` decides what comes back:

- `file` (the default) stores the PDF in your corpus and returns the file object, with the `templateHash` of the exact bundle that produced it.
- `raw` streams the PDF bytes straight back and stores nothing.

**Learn more:** [Compose](https://docs.cloudraker.com/paperwork/capabilities/compose)

## Authentication

- `bearerAuth`, http, header `Authorization`

## Request body

_Required._

- `template` (`compose.template`; string, required)
  - minLength 1; example `"invoice"`
- `data` (`compose.data`; map<unknown>, required)
  - example `{"total":1240}`
- `output` (`compose.output`; string, optional)
  - one of `"file"`, `"raw"`

## Example request

```json
{
  "template": "invoice",
  "data": {
    "total": 1240
  },
  "output": "file"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://api.cloudraker.com/v1/compose \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "template": "invoice",
  "data": {
    "total": 1240
  },
  "output": "file"
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/v1/compose';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({template: 'invoice', data: {total: 1240}, output: 'file'})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.cloudraker.com/v1/compose"

payload = {
    "template": "invoice",
    "data": { "total": 1240 },
    "output": "file"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

The PDF bytes (`output: "raw"` only — nothing was stored).

#### Example

```text
string
```

### 201

The composed file (`output: "file"`, the default).

#### Example

```json
{
  "object": "file",
  "id": "string",
  "name": "string",
  "mimeType": "string",
  "status": "uploading",
  "createdAt": "string",
  "parentFileId": "string",
  "metadata": {
    "property1": "string",
    "property2": "string"
  },
  "error": "string",
  "uploadUrl": "string",
  "uploadExpiresAt": "string",
  "urls": {
    "content": "string",
    "markdown": "string",
    "json": "string"
  },
  "composeTemplate": "string",
  "templateHash": "string",
  "composedAt": "string"
}
```

- `object` (`compose.response.201.object`; string, required)
- `id` (`compose.response.201.id`; string, required)
- `name` (`compose.response.201.name`; string, required)
- `mimeType` (`compose.response.201.mimeType`; string, required)
- `status` (`compose.response.201.status`; string, required)
  - one of `"uploading"`, `"processing"`, `"ready"`, `"failed"`
- `createdAt` (`compose.response.201.createdAt`; string, required)
- `parentFileId` (`compose.response.201.parentFileId`; string, optional)
- `metadata` (`compose.response.201.metadata`; map<string>, optional)
- `error` (`compose.response.201.error`; string, optional)
- `uploadUrl` (`compose.response.201.uploadUrl`; string, optional)
- `uploadExpiresAt` (`compose.response.201.uploadExpiresAt`; string, optional)
- `urls` (`compose.response.201.urls`; object, optional)
  - `content` (`compose.response.201.urls.content`; string, optional)
  - `markdown` (`compose.response.201.urls.markdown`; string, optional)
  - `json` (`compose.response.201.urls.json`; string, optional)
- `composeTemplate` (`compose.response.201.composeTemplate`; string, optional)
- `templateHash` (`compose.response.201.templateHash`; string, optional)
- `composedAt` (`compose.response.201.composedAt`; string, optional)

### 400

The reference is not a compose template (`capability_mismatch`).

### 404

Unknown template.

### 422

The data does not satisfy the template schema (`invalid_data`, with `errors[]`), the template has no `main`/files (`config_incomplete`), or it failed to compile (`template_render_failed`).

### 429

Rate limited. The `/v1` API allows at least **67 requests per minute per organization** (about 1,000 requests per 15 minutes) — a guaranteed floor, enforced per edge location, so a geographically spread caller may get more. Wait for the `Retry-After` interval and retry — the error is `retryable`.

#### Example

```json
{
  "code": "rate_limited",
  "message": "string",
  "retryable": true,
  "requestId": "string",
  "docUrl": "string"
}
```

- `code` (`compose.response.429.code`; string, required)
  - one of `"rate_limited"`
- `message` (`compose.response.429.message`; string, required)
- `retryable` (`compose.response.429.retryable`; boolean, required)
  - one of `true`
- `requestId` (`compose.response.429.requestId`; string, required)
- `docUrl` (`compose.response.429.docUrl`; string, optional)


Source: https://docs.cloudraker.com/paperwork/api/capabilities/compose/index.md
