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.dev/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 | 0 (not supported) | — | — |
| developer | 2 | 5 MB | 5 MB |
| pro | 5 | 10 MB | 10 MB |
| scale | 10 | 10 MB | 10 MB |
Webhooks
Register HTTP callbacks to receive real-time notifications on compilation events. Requires JWT.
| Event | Trigger |
|---|---|
compile.success | Compilation completed successfully |
compile.failed | Compilation failed |
Event Payload
{
"event": "compile.success",
"jobId": "uuid",
"engine": "pdflatex",
"durationMs": 1240,
"timestamp": "2026-02-20T14:30:00Z"
}If a secret is set, the payload is signed with HMAC-SHA256 delivered in the X-Signature header.
Billing
Subscription management via Polar.sh. Requires JWT authentication.
Plans
View available plans and their limits. Public endpoint.
Plan Comparison
| Feature | Free | Developer | Pro | Scale |
|---|---|---|---|---|
| Compilations/mo | 100 | 2,000 | 15,000 | 100,000 |
| Timeout | 30s | 120s | 300s | 300s |
| Max Size | 1 MB | 5 MB | 10 MB | 10 MB |
| Compilation Runs | 1 | 3 | 5 | 5 |
| API Keys | 2 | 5 | 10 | 25 |
| Engines | pdflatex | 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
Download a small binary (~12 MB). Your AI client spawns it as a background process on startup and communicates via stdin/stdout. No server setup, no open ports.
Step 1 — Build from source
# macOS / Linux
go build -o formatex-mcp ./cmd/mcp
sudo mv formatex-mcp /usr/local/bin/
# Windows
go build -o formatex-mcp.exe ./cmd/mcpPre-built binaries coming soon at dl.formatex.zedmed.online.
Step 2 — Configure your AI client
Edit %APPDATA%\Claude\claude_desktop_config.json (Windows) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS). Restart Claude Desktop after saving.
Windows
{
"mcpServers": {
"formatex": {
"command": "C:\\path\\to\\formatex-mcp.exe",
"env": {
"FORMATEX_API_KEY": "fex_your_api_key_here"
}
}
}
}macOS / Linux
{
"mcpServers": {
"formatex": {
"command": "/usr/local/bin/formatex-mcp",
"env": {
"FORMATEX_API_KEY": "fex_your_api_key_here"
}
}
}
}list_engines automatically. If it responds with engine descriptions, you're set.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 |