FormaTeX

\begin{article}

draft — not published

FormaTeX LaTeX API Integration: Python, JS, Go and curl

Get working FormaTeX LaTeX API code in Python, JavaScript, TypeScript, Go, or curl — authenticated, with error handling, ready to paste into your project.

FormaTeX LaTeX API Integration: Python, JS, Go and curl

Every developer who has tried to integrate a LaTeX compilation API has hit the same wall: you know what you want (a PDF), you have the LaTeX source, but you spend 30 minutes hunting through docs, copying auth headers, figuring out why the response is binary, and debugging cryptic error codes — before you even write your first line of application logic. The formatex-api Claude Code skill eliminates that wall entirely. Tell Claude which language you are working in, and within seconds you have authenticated, production-ready integration code with error handling, engine selection, and binary response handling — ready to paste directly into your project.

What Is the formatex-api Skill?

The formatex-api skill is a Claude Code skill that teaches Claude exactly how the FormatEx LaTeX compilation API works: its endpoint structure, authentication model, request shape, binary PDF response, and every error code it can return. When you invoke /formatex-api inside Claude Code, Claude stops guessing and starts generating correct integration code on the first try.

This is not a code generator that wraps a template. It is a skill that gives Claude precise, up-to-date knowledge of the FormatEx API so it can answer questions, write integration code, explain error responses, and help you debug compilation failures — all within the context of your existing codebase.

If you are building a document generation pipeline, a research tool, an academic submission system, or any service that needs to render LaTeX to PDF, this skill is the fastest path from zero to working code. Pair it with the getting started guide if you are new to the API.

How to Install

The skill lives in the latex-skills GitHub repository. You have four install options depending on how much of the LaTeX skill suite you want.

Install just the formatex-api skill:

bash
cp -r skills/formatex-api ~/.claude/skills/

Install the full FormatEx meta-skill (includes formatex-api plus billing, usage, and key management skills):

bash
cp -r skills/formatex ~/.claude/skills/

Install the full LaTeX meta-skill (all LaTeX authoring and compilation skills):

bash
cp -r skills/latex ~/.claude/skills/

Install everything at once:

bash
cp -r skills/latex-full ~/.claude/skills/

After copying, no restart is required. The skill is available immediately in any Claude Code session. Invoke it with /formatex-api followed by your request.

What formatex-api Does

When you invoke the skill, Claude loads a detailed knowledge document covering:

  • Base URL and endpoint structurehttps://api.formatex.io/api/v1/ with the correct path for compilation requests
  • Authentication — how to pass your API key via the X-API-Key header (not a Bearer token — a common mistake)
  • Request format — multipart form data for single-file requests, how to pass the LaTeX source, engine selection, and optional compiler flags
  • Engine optionspdflatex, xelatex, lualatex, and latexmk, with guidance on when each is appropriate
  • Binary response handling — the response body is raw PDF bytes, not JSON; the skill shows exactly how to handle this in each language
  • Error codes — the full reference: 401 (bad key), 402 (plan limit hit), 413 (file too large), 422 (LaTeX compilation error with log), 429 (rate limited), 500 (server error)
  • Compilation logs — how to retrieve the TeX log from the response headers when a 422 is returned, which is essential for debugging LaTeX errors

The skill covers Python (using requests and httpx), JavaScript and TypeScript (fetch and axios), Go (net/http), and curl. Each example is complete: it authenticates, posts the source, checks the status, handles the binary response, and surfaces the error message when something goes wrong.

Before and After

Before: Without the Skill

You open the FormatEx docs. You copy an example curl command. You adapt it to Python. You get a 401 and realize you used Authorization: Bearer instead of X-API-Key. You fix that, get a 200, write the response body to a file, open it — and it is not a valid PDF because you decoded the bytes as UTF-8. You dig into the docs again to find the binary response note. You fix that. Now you need to add error handling. You search for the error code table. Thirty minutes later you have something that mostly works but has no engine selection and no log retrieval on failure.

After: With the formatex-api Skill

You type:

text
/formatex-api Write a Python function that compiles a LaTeX string with xelatex and saves the PDF to disk. Return the compilation log if it fails.

Claude returns a complete, correct function in one shot:

python
import requests

def compile_latex(source: str, output_path: str, api_key: str) -> None:
    response = requests.post(
        "https://api.formatex.io/api/v1/compile",
        headers={"X-API-Key": api_key},
        data={"engine": "xelatex"},
        files={"file": ("document.tex", source.encode(), "application/x-tex")},
        timeout=120,
    )

    if response.status_code == 422:
        log = response.headers.get("X-Compilation-Log", "")
        raise ValueError(f"LaTeX compilation failed:\n{log}")

    if response.status_code == 402:
        raise RuntimeError("Monthly compilation limit reached. Upgrade your FormatEx plan.")

    response.raise_for_status()

    with open(output_path, "wb") as f:
        f.write(response.content)

Correct auth header. Correct multipart encoding. Binary response written as bytes. 422 handled with log extraction. Plan limit surfaced with a useful message. Ready to use.

Common Use Cases

1. Adding PDF export to a web app

You have a Next.js or Django app and want to let users download a PDF rendered from a LaTeX template. The skill generates the server-side integration — Node.js fetch or Python requests — including how to stream the binary response through to the client. See also the PHP/Laravel integration guide and the Ruby on Rails guide for framework-specific patterns.

2. Building a serverless PDF pipeline

You are running a Lambda or Cloud Function that receives LaTeX source and must return a PDF. The skill generates Go or TypeScript code with correct timeout handling for async compilation jobs. The serverless AWS Lambda guide covers the infrastructure side; the formatex-api skill handles the API client code.

3. Automating academic document generation

You generate reports, papers, or certificates from data. The skill helps you wire the compilation call into your pipeline, select the right engine (xelatex for Unicode, pdflatex for speed), and handle partial failures without crashing the batch.

4. Debugging a failing compilation

You are getting a 422 from the API and need to read the TeX log. Ask Claude with the skill active: "I'm getting a 422 from the FormatEx API — how do I extract and read the compilation log?" Claude explains exactly which header to read and how to parse the log. You can then hand the log to the latex-skill-fix-errors skill to get the fix.

5. Switching engines on existing code

You built your integration using pdflatex but now need xelatex for a Unicode-heavy document. The skill knows the exact parameter name and valid values, so Claude can update your integration in seconds without you re-reading the docs.

6. Go CLI tooling

If you are building a command-line tool in Go that wraps LaTeX compilation — similar to the patterns in the Go client guide — the skill generates idiomatic Go with proper io.ReadAll, error wrapping, and os.WriteFile for the binary response.

Engine Selection Guide

The skill includes guidance on engine selection, which is one of the most common sources of confusion:

  • pdflatex — fastest, works for most documents, limited to Latin scripts and pre-installed fonts
  • xelatex — use when you need Unicode, system fonts, or right-to-left text
  • lualatex — use when you need Lua scripting or advanced font features; slower than xelatex
  • latexmk — use for multi-pass documents (bibliographies, cross-references) where you need automatic reruns

If you are working with citations and bibliographies, the latex-skill-citations-bibliography skill pairs well here — it handles the BibTeX/BibLaTeX authoring side while formatex-api handles the compilation call.

Combining Skills for a Full Workflow

The formatex-api skill is most powerful when combined with other skills from the latex-skills suite:

A realistic session might look like: write the document structure with one skill, add math with another, compile via formatex-api, get a 422, fix the error with the fix-errors skill, compile again, done. All within Claude Code, without leaving your editor.

Get Started

Install the skill, open Claude Code in your project directory, and type /formatex-api compile this LaTeX string to PDF in TypeScript. You will have production-ready code in under 30 seconds.

To create a FormatEx account and get your API key, visit formatex.io. The free plan includes 15 compilations per month — enough to test your integration without a credit card.

The full skill library, including formatex-api and every LaTeX authoring skill, is at github.com/formatex/latex-skills.

\end{article}

Back to blog

\related{posts}

One quick thing

We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.

Cookie policy