API Documentation

Step 1: Generate an API Key

To use the compile API, you'll need to generate an API key first.

  1. Navigate to the API Keys page
  2. Click the "Create Api Key" button
  3. Enter a name for your API key (minimum 5 characters)
  4. Click "Submit" to generate the key
  5. Copy the generated API key and store it securely - it won't be shown again

Security Note: Treat your API key like a password. Never commit it to version control or share it publicly.

Step 2: Using the Compile API

The API provides two endpoints for compiling LaTeX documents to PDF.

Option 1: Compile from JSON

Send LaTeX content directly as JSON.

POST /api/latex/compile
curl -X POST https://your-domain.com/api/latex/compile \
  -H "Content-Type: application/json" \
  -H "X-API-KEY: your-api-key-here" \
  -d '{
    "content": "\\documentclass{article}\n\\begin{document}\nHello World!\n\\end{document}"
  }' \
  --output document.pdf

Option 2: Compile from File

Upload a .tex file directly.

POST /api/latex/compile/file
curl -X POST https://your-domain.com/api/latex/compile/file \
  -H "X-API-KEY: your-api-key-here" \
  -F "file=@document.tex" \
  --output document.pdf

Authentication

All API requests must include your API key in the request headers.

HeaderValueRequired
X-API-KEYYour API keyYes
Content-Typeapplication/json (for JSON endpoint)Yes (for JSON)

Response

On success, the API returns the compiled PDF file with appropriate headers.

Status: 200 OK
Content-Type: application/pdf
Body: PDF binary data

Error Handling

If compilation fails or authentication is invalid, you'll receive an error response.

Status CodeDescription
401Unauthorized - Invalid or missing API key
400Bad Request - Invalid LaTeX syntax or missing content
429Too Many Requests - Rate limit exceeded (20 requests per minute)
500Internal Server Error - Compilation failed

Code Examples

Python

import requests

api_key = "your-api-key-here"
base_url = "https://your-domain.com"

# Option 1: Compile from JSON
latex_content = r"""
\documentclass{article}
\begin{document}
Hello World!
\end{document}
"""

response = requests.post(
    f"{base_url}/api/latex/compile",
    headers={
        "X-API-KEY": api_key,
        "Content-Type": "application/json"
    },
    json={
        "content": latex_content
    }
)

if response.status_code == 200:
    with open("output.pdf", "wb") as f:
        f.write(response.content)
    print("PDF compiled successfully!")
else:
    print(f"Error: {response.status_code} - {response.text}")

# Option 2: Compile from file
with open("document.tex", "rb") as f:
    files = {
        "file": ("document.tex", f, "text/x-tex")
    }
    response = requests.post(
        f"{base_url}/api/latex/compile/file",
        headers={
            "X-API-KEY": api_key
        },
        files=files
    )

if response.status_code == 200:
    with open("output.pdf", "wb") as f:
        f.write(response.content)
    print("PDF compiled successfully!")
else:
    print(f"Error: {response.status_code} - {response.text}")

JavaScript (Node.js)

const fs = require('fs');
const FormData = require('form-data');
const axios = require('axios');

const apiKey = 'your-api-key-here';
const baseUrl = 'https://your-domain.com';

// Option 1: Compile from JSON
const latexContent = `\\documentclass{article}
\\begin{document}
Hello World!
\\end{document}`;

axios.post(`${baseUrl}/api/latex/compile`, {
    content: latexContent
}, {
    headers: {
        'X-API-KEY': apiKey,
        'Content-Type': 'application/json'
    },
    responseType: 'arraybuffer'
})
.then(response => {
    fs.writeFileSync('output.pdf', response.data);
    console.log('PDF compiled successfully!');
})
.catch(error => {
    console.error('Error:', error.response?.status, error.message);
});

// Option 2: Compile from file
const formData = new FormData();
formData.append('file', fs.createReadStream('document.tex'));

axios.post(`${baseUrl}/api/latex/compile/file`, formData, {
    headers: {
        'X-API-KEY': apiKey,
        ...formData.getHeaders()
    },
    responseType: 'arraybuffer'
})
.then(response => {
    fs.writeFileSync('output.pdf', response.data);
    console.log('PDF compiled successfully!');
})
.catch(error => {
    console.error('Error:', error.response?.status, error.message);
});