API Documentation
Compile LaTeX documents to PDF via a simple HTTP API.
Introduction
The LaTeX Compiler API lets you compile LaTeX source code into PDF documents programmatically.
Send your .tex files, get back a base64-encoded PDF. Supports single-file
and multi-file projects with images, bibliographies, and custom packages.
Use it to build CI/CD pipelines for academic papers, generate PDFs from templates in your app, or integrate LaTeX compilation into any workflow.
Authentication
All API requests require an API key passed in the x-api-key header.
Keys are prefixed with lx_ and can be created from your
account dashboard.
# Include your API key in every request
curl -H "x-api-key: lx_your_key_here" ...
Base URL
All API endpoints are relative to:
https://latex.spicychai.com
Compile LaTeX
Compile LaTeX source into a PDF document. Supports two modes: single-file (pass raw LaTeX) or multi-file (pass a file map).
Request Body
| Field | Type | Description | |
|---|---|---|---|
latex |
string |
required* | Raw LaTeX source code. Use this for single-file documents. |
files |
object |
required* | Map of filename → content. Use this for multi-file projects. Keys are file paths (e.g. "main.tex", "figures/diagram.png"). |
mainFile |
string |
optional | Entry point filename when using files. Defaults to "main.tex". |
latex or files, not both.
Use latex for simple single-file documents and files for
multi-file projects with images or includes.
Response
Success (200):
{
"success": true,
"pdf": "JVBERi0xLjQK..." // base64-encoded PDF
}
Failure (200):
{
"success": false,
"error": "Compilation failed",
"log": "! Undefined control sequence..." // last 2000 chars of pdflatex log
}
Examples
Single file (curl):
bashcurl -X POST https://latex.spicychai.com/api/v1/compile \
-H "Content-Type: application/json" \
-H "x-api-key: lx_your_key_here" \
-d '{
"latex": "\\documentclass{article}\n\\begin{document}\nHello, world!\n\\end{document}"
}' \
| jq -r '.pdf' | base64 -d > output.pdf
Multi-file project (curl):
bashcurl -X POST https://latex.spicychai.com/api/v1/compile \
-H "Content-Type: application/json" \
-H "x-api-key: lx_your_key_here" \
-d '{
"files": {
"main.tex": "\\documentclass{article}\n\\input{chapters/intro}\n\\begin{document}\n\\maketitle\n\\intro\n\\end{document}",
"chapters/intro.tex": "\\newcommand{\\intro}{\\section{Introduction}\nThis is the intro.}"
},
"mainFile": "main.tex"
}'
JavaScript (Node.js):
javascriptconst response = await fetch('https://latex.spicychai.com/api/v1/compile', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.LATEX_API_KEY
},
body: JSON.stringify({
latex: '\\documentclass{article}\n\\begin{document}\nHello!\n\\end{document}'
})
});
const { success, pdf, error } = await response.json();
if (success) {
// pdf is a base64 string — write to file or send to client
fs.writeFileSync('output.pdf', Buffer.from(pdf, 'base64'));
} else {
console.error('Compilation failed:', error);
}
Python:
pythonimport requests, base64
response = requests.post(
"https://latex.spicychai.com/api/v1/compile",
headers={"x-api-key": "lx_your_key_here"},
json={"latex": r"\documentclass{article}\begin{document}Hello!\end{document}"}
)
data = response.json()
if data["success"]:
with open("output.pdf", "wb") as f:
f.write(base64.b64decode(data["pdf"]))
else:
print("Error:", data["error"])
Binary Files (Images)
When using the files field, PNG images can be included as base64-encoded strings.
Files ending in .png with valid base64 content are automatically decoded to binary.
json{
"files": {
"main.tex": "\\documentclass{article}\n\\usepackage{graphicx}\n\\begin{document}\n\\includegraphics{logo.png}\n\\end{document}",
"logo.png": "iVBORw0KGgoAAAANSUhEUg..."
}
}
Create API Key
Create a new API key. Requires authentication via Firebase Bearer token (i.e., you must be signed in). The full key is returned once in the response and is never stored in plain text.
Request
| Field | Type | Description | |
|---|---|---|---|
name |
string |
required | A label for this key (e.g. "CI Pipeline", "My App"). |
Headers
| Header | Value |
|---|---|
Authorization |
Bearer <firebase_id_token> |
Response
{
"id": "abc123",
"key": "lx_a1b2c3d4e5f6...", // save this — shown only once
"name": "CI Pipeline",
"prefix": "lx_a1b2",
"createdAt": "2026-02-17T12:00:00.000Z"
}
List API Keys
List all API keys for the authenticated user. Key secrets are never included — only the prefix, name, and usage stats.
Response
{
"keys": [
{
"id": "abc123",
"name": "CI Pipeline",
"prefix": "lx_a1b2",
"createdAt": "2026-02-17T12:00:00.000Z",
"lastUsedAt": "2026-02-17T14:30:00.000Z",
"requestCount": 42
}
]
}
Revoke API Key
Permanently revoke an API key. Any requests using this key will immediately
start returning 401. This action cannot be undone.
Response
{
"success": true
}
Error Codes
| Status | Error | Description |
|---|---|---|
400 |
Missing fields | Request body is missing latex or files. |
401 |
Invalid API key | The x-api-key header is missing, malformed, or revoked. |
200 |
Compilation failed | LaTeX compiled but produced errors. Check the log field for pdflatex output. The success field will be false. |
500 |
Server error | Internal error during compilation. Retry or contact support. |
200 with
"success": false. Always check the success field in
the response body, not just the HTTP status code.
Rate Limits & Credits
API requests consume credits from your account balance. Each compiled PDF page costs 1 credit.
- 100 free credits per month (granted every 30 days)
- Additional credits available via the dashboard:
- Starter: 500 credits / $4.99
- Standard: 1,500 credits / $9.99
- Pro: 5,000 credits / $24.99
If your account has insufficient credits, compilation will still succeed but credit deduction will fail and the request may be rejected. Monitor your balance via the dashboard.