API reference
Render a document
POST /v1/run prints one document from a published template and answers with the file or a link.
Prints one document and answers in the same request. For several documents, send a batch.
Request
curl -X POST https://api.composa.ai/v1/run \ -H "Authorization: Bearer $COMPOSA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "template_id": "85416813-8d99-46e8-be2b-1d61cee5db38", "format": "pdf", "data": { "full_name": "Ada Lovelace", "course": "Engineering" } }' \ --output document.pdfBody fields
| Field | Type | Description |
|---|---|---|
template_id | string | Required. The id of a published template. |
data | object | The template's variables by name. See Variables. |
format | string | pdf (default), png, jpg, webp or svg. |
quality | string | low, medium (default) or high. For jpg and webp, a whole number from 1 to 100 also works. |
scale | number | For pictures: a size relative to the page, from 0.25 to 4. Default 1. |
width | integer | For pictures: an exact width in pixels, from 100 to 4000. Wins over scale. |
pages | string or array | "all" (default), or pages counted from 1: "1", "1,3", "2-4", [1, 3]. |
language | string | For a template in several languages: one of its languages, like "pt-BR". Default: the template's default language. |
version | integer | A published version to print. Default: the active version. |
output | string | bytes (default): the file is the answer. url: a link to the file. |
Response: the file
With the default "output": "bytes", a 200 answer's body is the file. Its Content-Type is the format's: application/pdf, image/png, image/jpeg, image/webp or image/svg+xml. Two or more pages as a picture or SVG come back as application/zip.
Useful headers on the answer:
| Header | Meaning |
|---|---|
Content-Language | The language printed. |
composa-fallbacks | JSON of fields printed with their fallback, and why: {"total":"not_a_number"}. Absent when none. |
x-request-id | Quote it to support. |
Response: a link
Send "output": "url" to get JSON instead of the file:
curl -X POST https://api.composa.ai/v1/run \ -H "Authorization: Bearer $COMPOSA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "template_id": "85416813-8d99-46e8-be2b-1d61cee5db38", "output": "url", "data": { "full_name": "Ada Lovelace" } }'{ "output": "url", "url": "https://…/document.pdf?X-Amz-…", "url_expires_in": 3600, "content_type": "application/pdf", "filename": "document.pdf", "pages": 1, "bytes": 48213}A link works for one hour (url_expires_in, in seconds), and the file is kept for a day, so download it. Fetch the link as it is, without an Authorization header. To keep a file at a permanent address, store it in your own storage.
Heavy documents
A call to /v1/run must finish within 50 seconds. A document that takes longer answers 422 with code: "deadline_exceeded" and nothing is charged. Send it to POST /v1/run/batches with data alone instead: a batch of one has more time.
As a rule of thumb, a PDF of hundreds of pages prints within a request. Dozens of pages as pictures belong in a batch.
Errors
The most common answers are below. See Errors for the full list.
| Status | Code | When |
|---|---|---|
400 | A field the API cannot read, like an unknown format. The error sentence says which. | |
404 | The template or version does not exist. | |
409 | The template has no published version. | |
413 | too_large | Two or more documents sent to /v1/run. Send them as a batch. |
422 | no_usable_value | A field with the stop setting had no usable value. |