Octree for agents

Compile LaTeX from any AI agent

The LaTeX MCP server and compile API

Give Claude, Claude Code, Cursor or any MCP client a compile_latex tool by signing in with your Octree account, or call one REST endpoint. Send LaTeX and get a PDF back in seconds, or errors with file and line, from the same TeX Live compiler that runs the Octree editor.

MCPhttps://app.useoctree.com/api/mcp
RESTPOST https://app.useoctree.com/api/v1/compile

OAuth sign-in, the device flow or an API key · Free: 30 compiles a day, Pro: 1,000 · In the MCP Registry as com.useoctree/octree

Connect your agent

Every client uses the same MCP server, https://app.useoctree.com/api/mcp. Sign in with your Octree account when the client asks, with no key to copy. The agent then has three tools: compile_latex, check_latex and get_quota.

Claude Code

Add the server, then run /mcp in Claude Code, pick octree and choose Authenticate to sign in in the browser.

bash
claude mcp add --transport http octree https://app.useoctree.com/api/mcp
Use an API key instead

Create one under Settings → API keys. It starts with oct_live_ and is shown once.

bash
claude mcp add --transport http octree https://app.useoctree.com/api/mcp --header "Authorization: Bearer YOUR_OCTREE_API_KEY"

Apps connected with sign-in can only compile and check LaTeX (scope compile). Disconnect them any time under Settings → Connected apps.

Headless agents: device flow

An agent, CLI or script with no browser can still get a key without anyone opening Settings, using the OAuth device authorization grant (RFC 8628). It shows the user a link such as https://app.useoctree.com/activate?code=WDJB-MJHT and receives an API key once they click Allow.

  1. Step 1: Request a code. POST https://app.useoctree.com/api/v1/device/code with JSON {"client_name":"my-cli"}. The answer has device_code, user_code, verification_uri_complete, expires_in (900 seconds) and interval (5 seconds).

  2. Step 2: Show the link. Ask the user to open verification_uri_complete, sign in and click Allow.

  3. Step 3: Poll for the key. Every interval seconds, POST https://app.useoctree.com/api/v1/device/token with the form fields grant_type=urn:ietf:params:oauth:grant-type:device_code and device_code. authorization_pending means keep polling, slow_down means poll less often (use the returned interval), access_denied and expired_token are final. On success it returns api_key (oct_live_…), token_type, mcp_url and rest_base, once: store the key, for example as OCTREE_API_KEY. It is an ordinary API key, listed and revocable under Settings → API keys.

Each step, with the responses shown as comments.

# 1. Start: returns a one-time link for the user
curl -s -X POST https://app.useoctree.com/api/v1/device/code \
  -H "Content-Type: application/json" -d '{"client_name":"my-cli"}'
# {"device_code":"…","user_code":"WDJB-MJHT",
#  "verification_uri":"https://app.useoctree.com/activate",
#  "verification_uri_complete":"https://app.useoctree.com/activate?code=WDJB-MJHT",
#  "expires_in":900,"interval":5}

# 2. Ask the user to open verification_uri_complete and click Allow.

# 3. Poll every 5 seconds with the device_code
curl -s -X POST https://app.useoctree.com/api/v1/device/token \
  -d grant_type=urn:ietf:params:oauth:grant-type:device_code \
  -d device_code=DEVICE_CODE
# {"error":"authorization_pending", …}   keep polling
# {"error":"slow_down","interval":10}    poll less often
# {"error":"access_denied"} / {"error":"expired_token"}   stop

# 4. Once allowed (returned once; store it):
# {"api_key":"oct_live_…","token_type":"bearer",
#  "mcp_url":"https://app.useoctree.com/api/mcp","rest_base":"https://app.useoctree.com/api/v1"}

Agents can find this on their own: a request without credentials gets HTTP 401 with device_authorization_endpoint and token_endpoint in the JSON body.

AGENTS.md / CLAUDE.md snippet

Paste this into AGENTS.md, CLAUDE.md or your Cursor rules so coding agents compile LaTeX through Octree instead of looking for a local TeX install. Without a key, it tells the agent to start the device flow and ask you to open the link.

AGENTS.md
## LaTeX

Compile LaTeX with the Octree MCP server (`octree`, https://app.useoctree.com/api/mcp); do not install TeX locally.

- Keep \documentclass in the main .tex file; pass every project file (.tex, .bib, .cls) as files + main.
- Run `check_latex` and fix every reported error (file, line, kind) before checking again.
- When it comes back clean, call `compile_latex` once and save the PDF.
- Each call counts toward the daily quota (free 30, Pro 1,000); `get_quota` shows what is left.
- No MCP client? POST the same JSON to https://app.useoctree.com/api/v1/compile with
  `Authorization: Bearer $OCTREE_API_KEY` (docs: https://www.useoctree.com/developers).
- No OCTREE_API_KEY and the MCP server is not connected? Get a key with the device flow:
  POST https://app.useoctree.com/api/v1/device/code, ask the user to open the returned
  verification_uri_complete link, then poll https://app.useoctree.com/api/v1/device/token every 5 s until it
  returns api_key. Keep it in OCTREE_API_KEY, never in a committed file.

Call the REST API

From scripts, CI jobs and backends, use an API key from Settings or the device flow, stored in OCTREE_API_KEY:

Returns JSON with the PDF base64-encoded, or a list of errors.

export OCTREE_API_KEY=oct_live_…

curl https://app.useoctree.com/api/v1/compile \
  -H "Authorization: Bearer $OCTREE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"latex":"\\documentclass{article}\\begin{document}Hello\\end{document}"}'

REST API reference

Base URL https://app.useoctree.com. Every request needs Authorization: Bearer oct_live_… (an API key, or an OAuth access token). Request bodies are JSON.

POST /api/v1/compile

Compile LaTeX to PDF from a single document or a set of files. There is no engine option: documents compile with pdfLaTeX, and the compiler switches to XeLaTeX or LuaLaTeX automatically when the document needs it (for example when it loads fontspec).

latexstring
A complete single-file document (it must contain \documentclass), compiled as main.tex. Use this or files.
files{ path, content }[]
Project files with relative, forward-slash paths, e.g. sections/intro.tex, refs.bib. Up to 50 files, text only in v1.
mainstring, optional
With files only: the .tex file to compile. Defaults to main.tex if present, else the first .tex file containing \documentclass. The main file must contain \documentclass, or the request is rejected with 400.
response"json" | "pdf"
json (default) returns the object below; pdf returns the raw PDF. Accept: application/pdf does the same as pdf; an explicit response field wins over the header. Failures are JSON either way.
{
  "latex": "\\documentclass{article}\\begin{document}Hello\\end{document}",
  "response": "json"
}

A document that compiles returns ok: true with the PDF base64-encoded. A document with LaTeX errors is still a successful request: HTTP 200 with ok: false and the errors.

{
  "ok": true,
  "pdf_base64": "JVBERi0xLjUKJcfsj6IK…",
  "pages": 1,
  "duration_ms": 1840,
  "warnings": [],
  "log_tail": ""
}
ok
true if a PDF was produced.
pdf_base64
The PDF, base64-encoded (success only).
pages
Page count, when known.
duration_ms
Compile time in milliseconds.
warnings
Always [] on success in v1; warnings show up only in the log of a failed compile.
errors
{ file, line, message, kind }[] when ok is false. kind is one of missing_package, undefined_control_sequence, missing_dollar, missing_brace or latex_error, so an agent can branch on the error type without parsing the log.
log_tail
The last lines of the LaTeX log when the compile fails; '' on success.
suggestion
Optional hint for fixing the first error.

GET /api/v1/me

Your plan, today’s usage and resets_at, the next reset (midnight UTC, ISO 8601). Useful as a key check before a batch job.

curl https://app.useoctree.com/api/v1/me \
  -H "Authorization: Bearer $OCTREE_API_KEY"

GET /api/v1/openapi.json

The OpenAPI description of the API, at https://app.useoctree.com/api/v1/openapi.json. Load it into Postman or an agent framework that builds tools from OpenAPI.

Errors and status codes

Every error response is JSON with an error code and a human-readable message.

200no error
Request handled. Check ok: the document compiled, or it has LaTeX errors listed in errors.
400invalid_request
Malformed body, e.g. invalid JSON, neither latex nor files, more than 50 files, a bad or duplicate path, or a main file without \documentclass.
401unauthorized
Missing, invalid, expired or revoked credentials. The body includes device_authorization_endpoint and token_endpoint so an agent can start the device flow.
413payload_too_large
Source over 2 MB, or a request body over 4 MB.
429quota_exceeded
Daily quota used up. Also returns limit, used, resets_at and upgrade_url.
429rate_limited
Too many failed key attempts from your IP address (10 a minute). Check the key and wait for Retry-After seconds.
503service_unavailable
The API key check is temporarily unavailable. Retry with backoff.
503compile_unavailable
The compiler is busy or temporarily unavailable. Retry after Retry-After seconds.
504compile_timeout
The compile took too long. Simplify the document or split the work. A timeout is not a LaTeX error.

Limits and keys

Daily compiles
Free: 30 a day. Pro: 1,000 a day. Reset at midnight UTC. REST and MCP share the same count, and check_latex counts like a compile.
Request size
Up to 2 MB of source and 50 files.
API keys
oct_live_…, up to 5 per account, shown once, stored hashed, revocable at any time in Settings. Keys from the device flow count toward the 5.
Connected apps
Apps signed in with OAuth use short-lived tokens limited to compiling, do not count toward the key limit, and can be disconnected under Settings → Connected apps.

Authentication

OAuth 2.1 sign-inClaude, Claude Code, Cursor, VS Code and other MCP clients with sign-in
Add the MCP URL with no headers; the client follows the 401 to https://app.useoctree.com/.well-known/oauth-protected-resource and https://app.useoctree.com/.well-known/oauth-authorization-server, registers itself (dynamic client registration or a client ID metadata document), and signs in with PKCE. Scope compile.
Device flow (RFC 8628)Headless agents, CLIs, scripts
Request a code, show the link, poll; ends with an API key.
API keyCI, backends, clients without OAuth
Create one under Settings → API keys, send Authorization: Bearer oct_live_….

MCP server reference

The Octree LaTeX MCP server lives at https://app.useoctree.com/api/mcp. It speaks the Streamable HTTP transport and is stateless, so there is no session to set up or keep alive. Sign in with OAuth (the MCP authorization spec) or send an API key in an Authorization: Bearer oct_live_… header; see Authentication.

compile_latexInput: latex, or files + main
A short summary (pages and time, or the errors) and the PDF as a resource.
check_latexInput: latex, or files + main
Errors only, with file, line and kind. The fast loop for an agent fixing a document. Counts toward the daily quota.
get_quotaNo input
Plan, daily limit, compiles used today and resets_at.

How an agent should use it

Write the .tex files first, with \documentclass in the main file. Call check_latex and fix every reported error, using its file, line and kind, until it comes back clean; then call compile_latex once for the PDF. Each check counts toward the daily quota and returns only errors, never a raw LaTeX log, so the fix loop stays small. To tell coding agents in a repository to work this way, use the AGENTS.md / CLAUDE.md snippet.

Frequently asked questions

How do I compile LaTeX from Claude Code?

Run claude mcp add --transport http octree https://app.useoctree.com/api/mcp, then type /mcp in Claude Code, pick octree and choose Authenticate to sign in to Octree in the browser. No API key is needed; if you prefer one, add --header "Authorization: Bearer YOUR_OCTREE_API_KEY" to the command instead. Claude Code then has the compile_latex, check_latex and get_quota tools: ask it to write your document and compile it with Octree, and it checks the source, fixes the reported errors and returns the PDF.

How do I add the Octree MCP server to Cursor or VS Code?

In Cursor, press Add to Cursor on this page, then click Needs login next to Octree in Cursor's MCP settings to sign in in the browser. In VS Code, run the code --add-mcp command shown above or add the .vscode/mcp.json snippet; VS Code asks you to sign in the first time the server starts. Both also accept an API key in an Authorization header if you prefer.

Do I need an API key?

No. MCP clients that support sign-in (Claude, Claude Code, Cursor, VS Code) connect with OAuth: add https://app.useoctree.com/api/mcp with no headers, sign in to Octree in the browser and click Allow. Headless agents, CLIs and scripts can get a key without opening Settings through the device flow: POST https://app.useoctree.com/api/v1/device/code, show the user the activation link, and poll /api/v1/device/token until it returns a key. You can still create API keys yourself under Settings → API keys and send them as Authorization: Bearer oct_live_….

Is Octree listed in the MCP Registry?

Yes. Octree is in the official MCP Registry as com.useoctree/octree, a remote Streamable HTTP server at https://app.useoctree.com/api/mcp that accepts OAuth sign-in or an API key in the Authorization header.

Is the Octree LaTeX compile API free?

Yes. Every Octree account can connect agents with OAuth or create API keys, and the free plan includes 30 compiles per day through the REST API and the MCP server. Octree Pro raises the limit to 1,000 compiles per day.

Which LaTeX packages are installed?

The API runs the same compiler as the Octree editor at app.useoctree.com: a full TeX Live installation driven by latexmk, so packages such as amsmath, TikZ, pgfplots, biblatex, beamer and the common thesis and resume classes are already there. Documents compile with pdfLaTeX by default; when a document needs XeLaTeX or LuaLaTeX (for example it loads fontspec), the compiler switches automatically. Shell escape is disabled, so packages that need it, such as minted, do not run.

Can I compile multi-file projects and images?

Multi-file projects, yes: send a files array of { path, content } objects plus the name of the main file, and \input, \include and .bib files resolve as they would on disk. In v1 every file is text; binary assets such as PNG or PDF images are coming. A request can carry up to 50 files and 2 MB of source.

What are the rate limits?

Limits are per account per day: 30 compiles on the free plan and 1,000 on Pro. When you run out, the API answers HTTP 429 with error quota_exceeded, the limit, how many you have used, when the count resets and a link to upgrade. GET /api/v1/me and the get_quota MCP tool show your current usage and when it resets (midnight UTC). check_latex counts toward the same limit.

Do you store the documents I compile through the API?

No. On the API and MCP path the LaTeX source and the PDF are not stored after the response is sent. Projects you create in the Octree editor are saved to your account as usual; that is separate from the API.

How are API keys and connected apps secured?

Keys start with oct_live_ and are shown once, when you create them (or once to the agent, in the device flow). Octree keeps only a hash of each key, so a key cannot be read back, only revoked. You can have up to 5 keys per account and revoke any of them in Settings. Apps connected with OAuth get short-lived tokens that can only compile and check LaTeX (scope compile), never read your projects, and you can disconnect them under Settings → Connected apps.

Should my agent use the REST API or the MCP server?

Use the MCP server when the agent is an MCP client (Claude Code, Cursor, Windsurf and others): it gets compile_latex, check_latex and get_quota as tools with no glue code. Use the REST API from scripts, CI jobs, backends and agent frameworks that call HTTP directly. Both accept the same credentials and share the same daily limit.

Learn more

  • Learn LaTeX: the basics your agent’s documents are built on
  • TikZ and PGFPlots: diagrams and plots that compile through the API like any other package
  • Bibliography examples: send a .bib file in files and cite as usual
  • Octree editor: the same compiler with an AI editor, PDF preview and saved projects

Give your agent a LaTeX compiler

Add one URL to Claude, Claude Code or Cursor, sign in with your free Octree account, and your agent can turn LaTeX into a PDF: 30 compiles a day free, 1,000 on Pro.

Connect your agent →