Skip to content

Preview ​

POST /api/preview

Compile inline Typst markup with JSON data and return a PDF preview.

Request Body ​

json
{
  "templateContent": "#let data = json.decode(sys.inputs.at(\"data\"))\n= Hello, #data.name",
  "data": {
    "name": "World"
  }
}
FieldTypeRequiredDescription
templateContentstringYesTypst markup content
dataobjectYesJSON data to inject as Typst variables
variableNamestringNoCustom variable name (default: data)

Example ​

bash
curl -X POST http://localhost:3000/api/preview \
  -H "Content-Type: application/json" \
  -d '\''{
    "templateContent": "#let data = json.decode(sys.inputs.at(\"data\"))\n= Hello, #data.name",
    "data": { "name": "World" }
  }'\'' \
  -o preview.pdf

Response ​

Returns application/pdf with the compiled PDF content.

Error Codes ​

CodeDescription
400Missing or invalid templateContent or data fields
413Payload too large (max 10 MB)
429Rate limit exceeded for compilation
500Typst compilation error

Rate Limiting ​

This endpoint uses the stricter compilation rate limit: 1/4 of the general REPORTS_RATE_LIMIT.

Design and Dev by David Lam