Skip to content

HTTP API

The platex service exposes a tiny HTTP API. You rarely call it directly — the client library and request handlers speak it for you — but here’s the wire format for building requests by hand, debugging, or writing a client in another language.

Method Path Description
POST /compile Compile LaTeX. Body: CompileRequest JSON. Response: CompileResponse JSON
GET /health Health check. Returns { "status": "ok" } (never requires auth)
interface CompileRequest {
source: string; // LaTeX source (main.tex content)
engine: 'pdflatex' | 'xelatex' | 'lualatex';
passes: 'auto' | 1 | 2 | 3;
bibliography: 'bibtex' | 'biber' | 'none';
files: Record<string, string>; // filename → base64-encoded content
timeout: number; // milliseconds, overall pipeline budget, capped at 120s
}

Only source is required in practice — the handler fills in defaults for the rest. files values are base64-encoded on the wire (unlike the library’s Buffer values, which are encoded for you).

interface CompileResponse {
pdf: string | null; // base64-encoded PDF, or null on fatal error
errors: LatexError[];
warnings: LatexWarning[];
logs: RawPassLog[];
}

See the API reference for LatexError, LatexWarning, and RawPassLog.

Status Meaning
200 Compiled (check pdf for null on fatal LaTeX errors)
400 Malformed request body
401 Missing/invalid bearer token (when PLATEX_API_KEY is set)
413 Request body exceeds maxRequestBodyBytes
503 Instance at maxConcurrentCompiles — retry shortly

If the service is started with PLATEX_API_KEY set, POST /compile requires:

Authorization: Bearer <key>

GET /health never requires auth. See Server configuration.

Compile and extract the PDF:

Terminal window
curl -X POST https://platex.example.com/compile \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PLATEX_API_KEY" \
-d '{"source": "\\documentclass{article}\\begin{document}Hi\\end{document}"}' \
| jq -r '.pdf' | base64 -d > output.pdf

Health check:

Terminal window
curl https://platex.example.com/health
# → {"status":"ok"}