Skip to content
Menu · Render a document

API reference

Render a document

POST /v1/run prints one document from a published template and answers with the file or a link.

POST https://api.composa.ai/v1/run

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.pdf

Body fields

FieldTypeDescription
template_idstringRequired. The id of a published template.
dataobjectThe template's variables by name. See Variables.
formatstringpdf (default), png, jpg, webp or svg.
qualitystringlow, medium (default) or high. For jpg and webp, a whole number from 1 to 100 also works.
scalenumberFor pictures: a size relative to the page, from 0.25 to 4. Default 1.
widthintegerFor pictures: an exact width in pixels, from 100 to 4000. Wins over scale.
pagesstring or array"all" (default), or pages counted from 1: "1", "1,3", "2-4", [1, 3].
languagestringFor a template in several languages: one of its languages, like "pt-BR". Default: the template's default language.
versionintegerA published version to print. Default: the active version.
outputstringbytes (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:

HeaderMeaning
Content-LanguageThe language printed.
composa-fallbacksJSON of fields printed with their fallback, and why: {"total":"not_a_number"}. Absent when none.
x-request-idQuote it to support.

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" }  }'
json
{  "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.

StatusCodeWhen
400A field the API cannot read, like an unknown format. The error sentence says which.
404The template or version does not exist.
409The template has no published version.
413too_largeTwo or more documents sent to /v1/run. Send them as a batch.
422no_usable_valueA field with the stop setting had no usable value.