API Reference
Complete reference for the FormaTeX REST API. Compile LaTeX documents to PDF with a single HTTP call.
Quick Example
curl -X POST https://api.formatex.io/api/v1/compile \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"latex": "\\documentclass{article}\\begin{document}Hello!\\end{document}"}' \
--output document.pdfAuthentication
Two auth methods: JWT tokens for account management, API keys for compilation.
| Method | Header | Used For |
|---|---|---|
| JWT Token | Authorization: Bearer <token> | User management, billing, admin |
| API Key | X-API-Key: <key> | Compilation endpoints |
Users
Manage your profile and view usage statistics. All endpoints require JWT.
API Keys
Create and manage API keys for compilation. All endpoints require JWT.
Compilation
Compile LaTeX to PDF. All compilation endpoints require an API Key.
Companion File Uploads
All compile endpoints accept a files field for bundling images, bibliography files, custom classes, and other assets alongside the main document.
JSON + Base64 Mode
{
"latex": "\\documentclass{article}\\begin{document}\\includegraphics{logo}\\end{document}",
"engine": "pdflatex",
"files": [
{ "path": "logo.png", "data": "<base64-encoded-content>" },
{ "path": "refs.bib", "data": "<base64-encoded-content>" }
]
}Multipart mode also supported: Content-Type: multipart/form-data with each file as a files field and path set via the filename attribute.
| Plan | Max Files | Max File Size | Max Total |
|---|---|---|---|
| Free | 5 | 2 MB | 5 MB |
| Pro | 30 | 15 MB | 100 MB |
| Max | 100 | 30 MB | 300 MB |
| Enterprise | 300 | 50 MB | 1 GB |
Templates
Parameterized LaTeX documents with <<variable>> placeholders. Send data, get PDF — no LaTeX knowledge required for your API consumers.
How it works
- Browse the template library or create your own
- Send a compile request with variable values
- Receive a compiled PDF with all placeholders substituted
Variable schema
| Field | Type | Description |
|---|---|---|
key | string | Variable name used in placeholders |
type | string | number | date | Type validation applied to the value |
required | boolean | Whether the variable must be provided |
default | string | Default value if not provided |
description | string | Human-readable description |
Quick example
curl -X POST https://api.formatex.io/api/v1/templates/cover-letter/compile \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"variables": {"name": "Alice Martin", "company": "Acme Corp"}}' \
--output cover-letter.pdfWithout the Accept: application/json header, the response is a raw PDF binary.
Public Templates
Curated templates available to all users. No authentication required to list or view. Compilation requires an API key.
User Templates
Create and manage your own parameterized templates. Requires JWT authentication. Available on Pro plan and above.
Webhooks
Register HTTP callbacks to receive real-time notifications on compilation, quota, and plan events. Requires JWT. Failed deliveries are automatically retried up to 5 times with exponential backoff.
| Event | Trigger |
|---|---|
compilation.success | Compilation completed successfully |
compilation.failed | Compilation failed (LaTeX error or timeout) |
quota.warning | Usage reached 80% of monthly quota |
quota.exceeded | Usage reached 100% — compilations are blocked |
plan.changed | Plan upgraded, downgraded, or revoked |
Event Payload
{
"event": "compilation.success",
"data": {
"compilationId": "uuid",
"engine": "pdflatex",
"durationMs": 1240,
"inputSizeBytes": 2048,
"apiKeyPrefix": "a2e67d28...",
"timestamp": "2026-02-20T14:30:00Z"
}
}If a secret is set, the payload is signed with HMAC-SHA256 delivered in the X-FormaTeX-Signature header.
Billing
Subscription management via Polar.sh. Requires JWT authentication.
Plans
View available plans and their limits. Public endpoint.
Plan Comparison
| Feature | Free | Pro | Max | Enterprise |
|---|---|---|---|---|
| Compilations/mo | 15 | 500 | 2,000 | 15,000 |
| Timeout | 30s | 120s | 300s | 300s |
| Max Size | 1 MB | 10 MB | 25 MB | 50 MB |
| Compilation Runs | 1 | 3 | 5 | 10 |
| API Keys | 2 | 5 | 15 | 50 |
| Engines | All 2 | All 4 | All 4 | All 4 |
| At Limit | Hard block | Soft limit | Soft limit | Soft limit |
MCP Server
Compile LaTeX directly from AI agents — Claude Desktop, Cursor, Claude Code, n8n, and more — with zero local TeX Live installation. Uses your FormaTeX API key for authentication.
Available Tools
fix_latexPromptAnalyzes compilation errors, finds root causes, and returns corrected LaTeX source. Pass it your LaTeX source and error log.
“Use the fix_latex prompt to help me fix this error: [paste error log]”
Setup
How it works
Connect via URL to the hosted MCP server — no binary download. Ideal for teams sharing one MCP server, no-code platforms (n8n, Make.com), and cloud-based AI agents.
Hosted server
https://mcp.formatex.io/mcpConfigure your AI client
No binary needed — just add the URL and your API key:
{
"mcpServers": {
"formatex": {
"url": "https://mcp.formatex.io/mcp",
"headers": {
"Authorization": "Bearer fex_your_api_key_here"
}
}
}
}Health check
curl https://mcp.formatex.io/health
# → {"status":"ok","service":"formatex-mcp","version":"1.0.0"}Troubleshooting
Errors
All errors return a consistent JSON format with an error message and optional context.
{
"error": "human-readable error message",
"plan": "free",
"limit": 100,
"used": 100
}Status Codes
| Code | Meaning |
|---|---|
400 | Invalid request body |
401 | Missing or invalid authentication |
403 | Plan limit violated or account deactivated |
404 | Resource not found |
409 | Conflict (e.g., email already registered) |
422 | Compilation failed |
429 | Rate limit exceeded |
503 | Billing not configured |
Rate Limits
| Endpoint Group | Limit |
|---|---|
| Auth | 20 req/min |
| User management | 60 req/min |
| Billing | 20 req/min |
| Admin | 60 req/min |
| Compilation | 100 req/min |
