API Reference
Base URL: https://latexlite.com
All requests require Authorization: Bearer <API_KEY>. Get a key at latexlite.com/get-demo-key.
POST
/v1/renders-sync
Render a LaTeX template to PDF. Returns application/pdf by default. Set Accept: application/json to receive a base64-encoded PDF instead.
Request (JSON)
{
"template": "\\documentclass{article}\n\\begin{document}\nHello [[.Name]]!\n\\end{document}",
"data": {
"Name": "World"
}
}
Response (application/pdf)
PDF binary bytes. Use -o output.pdf with curl.
Response (application/json)
{
"success": true,
"data": {
"content_type": "application/pdf",
"pdf_base64": "JVBERi0xLjQKJeLjz9MK..."
}
}
POST
/v1/math-sync
Render a LaTeX math expression to PNG. The math string must start and end with $ or $$. Returns image/png by default.
Request (JSON)
{
"math": "$\\int_0^1 x^2 \\, dx = \\frac{1}{3}$"
}
Response (image/png)
PNG binary bytes. Use -o equation.png with curl.
Response (application/json)
{
"success": true,
"data": {
"content_type": "image/png",
"png_base64": "iVBORw0KGgoAAAANSUhEUgAA..."
}
}
Supported Content Types
For /v1/renders-sync:
| Content-Type | Use case | Data injection |
|---|---|---|
| application/json | Inline template string | Via data field |
| text/plain text/x-tex application/x-tex |
Raw .tex file upload | None (self-contained) |
| multipart/form-data | .tex file with placeholders | Via data form field (JSON string) |
Template Syntax
Templates use Go's text/template syntax with [[ ]] delimiters.
Simple field
[[.FieldName]]
Loop over a list
[[range .Items]][[.Description]] & [[.Qty]] & [[.Total]] \\
[[end]]
Corresponding data
{
"Items": [
{ "Description": "Web Design", "Qty": "1", "Total": "£2,500" }
]
}
Note: When writing JSON inline in curl, backslashes must be doubled:
\int becomes \\int. However \n and \t are JSON escape sequences and remain single backslash.
HTTP Status Codes
| Status | Meaning |
|---|---|
| 200 | OK — request successful |
| 400 | Bad Request — invalid template or data |
| 401 | Unauthorized — missing or invalid API key |
| 408 | Request Timeout — render timed out |
| 422 | Unprocessable Entity — LaTeX compilation failed |
| 429 | Too Many Requests — rate limit exceeded |
| 502 | Bad Gateway — renderer service error |
| 503 | Service Unavailable — renderer not configured |
Request Limits
/v1/renders-sync
- Max body size: 1 MiB
- Max template size: 200 KB
- Timeout: 8 seconds
- Max PDF size: 20 MB
/v1/math-sync
- Max body size: 64 KiB
- Max math input: 32 KB
- Timeout: 8 seconds
Error Handling
All error responses follow this structure:
{
"success": false,
"error": {
"message": "LaTeX compilation failed: ! Undefined control sequence.",
"line": 0
}
}
Common Error Messages
Missing or invalid Authorization header— 401Invalid API key— 401API key rate limit exceeded. Try again in 1 minute.— 429IP rate limit exceeded. Maximum 50 requests per minute per IP.— 429missing required field: template— 400template too large (max 200KB)— 400LaTeX compilation failed: ...— 422render timed out. Try optimizing your template.— 408math must start and end with $ (or $$)— 400
Rate Limits
Rate limit state is communicated via response headers:
| Header | Description |
|---|---|
| X-RateLimit-Limit | Maximum requests allowed per minute |
| X-RateLimit-Remaining | Requests remaining in current window |
| X-RateLimit-Reset | Unix timestamp when the limit resets |