> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.cloudraker.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.cloudraker.com/_mcp/server.

# Compose a document from a template and data

POST https://api.cloudraker.com/v1/compose
Content-Type: application/json

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/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/capabilities/compose)

Reference: https://docs.cloudraker.com/api/cloud-raker-api/compose

## Authentication

- `Authorization` header (bearer token, required)

## Request

### Body (application/json)

- `template` (string, required)
- `data` (map from string to any, required)
- `output` (enum, optional)
  - Allowed values: `file`, `raw`

## Response

### 200

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

- File download.

### 201

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

- `object` ("file", required)
- `id` (string, required)
- `name` (string, required)
- `mimeType` (string, required)
- `status` (enum, required)
  - Allowed values: `uploading`, `processing`, `ready`, `failed`
- `createdAt` (string, required)
- `error` (string, optional)
- `uploadUrl` (string, optional)
- `uploadExpiresAt` (string, optional)
- `urls` (object, optional)
  - `content` (string, optional)
  - `markdown` (string, optional)
  - `json` (string, optional)
- `composeTemplate` (string, optional)
- `templateHash` (string, optional)
- `composedAt` (string, optional)

## Examples

### Example 1

**Request**

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

**Response**

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

**SDK Code**

```typescript
import { CloudRakerClient } from "@cloudraker/api";

async function main() {
    const client = new CloudRakerClient({
        token: "YOUR_TOKEN_HERE",
    });
    await client.compose({
        template: "invoice",
        data: {
            total: 1240,
        },
    });
}
main();

```

```python
from cloudraker import CloudRaker

client = CloudRaker(
    token="YOUR_TOKEN_HERE",
)

client.compose(
    template="invoice",
    data={
        "total": 1240
    },
)

```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

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

	payload := strings.NewReader("{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

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

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.cloudraker.com/v1/compose")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.cloudraker.com/v1/compose', [
  'body' => '{
  "template": "invoice",
  "data": {
    "total": 1240
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.cloudraker.com/v1/compose");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "template": "invoice",
  "data": ["total": 1240]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.cloudraker.com/v1/compose")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Example 2

**Request**

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

**Response**

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

**SDK Code**

```typescript
import { CloudRakerClient } from "@cloudraker/api";

async function main() {
    const client = new CloudRakerClient({
        token: "YOUR_TOKEN_HERE",
    });
    await client.compose({
        template: "invoice",
        data: {
            total: 1240,
        },
    });
}
main();

```

```python
from cloudraker import CloudRaker

client = CloudRaker(
    token="YOUR_TOKEN_HERE",
)

client.compose(
    template="invoice",
    data={
        "total": 1240
    },
)

```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

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

	payload := strings.NewReader("{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

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

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.cloudraker.com/v1/compose")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.cloudraker.com/v1/compose', [
  'body' => '{
  "template": "invoice",
  "data": {
    "total": 1240
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.cloudraker.com/v1/compose");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"template\": \"invoice\",\n  \"data\": {\n    \"total\": 1240\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "template": "invoice",
  "data": ["total": 1240]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.cloudraker.com/v1/compose")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```