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.
https://app.useoctree.com/api/mcpPOST https://app.useoctree.com/api/v1/compileOAuth 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.
claude mcp add --transport http octree https://app.useoctree.com/api/mcpUse an API key instead
Create one under Settings → API keys. It starts with oct_live_ and is shown once.
claude mcp add --transport http octree https://app.useoctree.com/api/mcp --header "Authorization: Bearer YOUR_OCTREE_API_KEY"Cursor
One click opens Cursor’s install prompt with the server filled in. Cursor then shows Needs login next to Octree: click it to sign in in the browser.
Use an API key instead
Create one under Settings → API keys. It starts with oct_live_ and is shown once.
Paste a key above for an install link with the key filled in, or add this to ~/.cursor/mcp.json:
{
"mcpServers": {
"octree": {
"url": "https://app.useoctree.com/api/mcp",
"headers": {
"Authorization": "Bearer YOUR_OCTREE_API_KEY"
}
}
}
}Claude (claude.ai and Claude Desktop)
- Open Customize → Connectors, click + Add, then Add custom connector.
- Name it
Octreeand enter the URLhttps://app.useoctree.com/api/mcp. Leave the OAuth client ID and secret empty: Claude registers itself. - Click Add, then Connect. Sign in to Octree and click Allow.
- Turn it on in a chat from + → Connectors.
On Team and Enterprise plans an owner adds the connector under Organization settings → Connectors; each member then connects their own Octree account.
Use an API key instead
Create one under Settings → API keys. It starts with oct_live_ and is shown once.
Choose No sign in instead, and under Request headers add Authorization with the value Bearer YOUR_OCTREE_API_KEY.
VS Code (GitHub Copilot)
Add it to your VS Code profile from a terminal. When the server first starts, VS Code asks you to sign in and opens the browser.
code --add-mcp '{"name":"octree","type":"http","url":"https://app.useoctree.com/api/mcp"}'Or, per workspace, in .vscode/mcp.json (no secret, safe to commit):
{
"servers": {
"octree": {
"type": "http",
"url": "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.
code --add-mcp '{"name":"octree","type":"http","url":"https://app.useoctree.com/api/mcp","headers":{"Authorization":"Bearer YOUR_OCTREE_API_KEY"}}'Or in .vscode/mcp.json: VS Code asks for the key the first time the server starts and stores it as a secret, so this file is safe to commit too.
{
"inputs": [
{
"type": "promptString",
"id": "octree-api-key",
"description": "Octree API key (oct_live_...)",
"password": true
}
],
"servers": {
"octree": {
"type": "http",
"url": "https://app.useoctree.com/api/mcp",
"headers": {
"Authorization": "Bearer ${input:octree-api-key}"
}
}
}
}Codex CLI
Codex reads an API key from the OCTREE_API_KEY environment variable. Create one under Settings → API keys, or get one from a terminal with the device flow.
# ~/.codex/config.toml (then: export OCTREE_API_KEY=oct_live_...)
[mcp_servers.octree]
url = "https://app.useoctree.com/api/mcp"
bearer_token_env_var = "OCTREE_API_KEY"Windsurf, Cline and other MCP clients
Clients that support MCP sign-in (OAuth) only need the URL (some call the field serverUrl):
{
"mcpServers": {
"octree": {
"url": "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.
For clients without OAuth, add the key as a header. Keep it in your user-level config, not a shared repository.
{
"mcpServers": {
"octree": {
"url": "https://app.useoctree.com/api/mcp",
"headers": {
"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.
Step 1: Request a code.
POST https://app.useoctree.com/api/v1/device/codewith JSON{"client_name":"my-cli"}. The answer hasdevice_code,user_code,verification_uri_complete,expires_in(900 seconds) andinterval(5 seconds).Step 2: Show the link. Ask the user to open
verification_uri_complete, sign in and click Allow.Step 3: Poll for the key. Every
intervalseconds,POST https://app.useoctree.com/api/v1/device/tokenwith the form fieldsgrant_type=urn:ietf:params:oauth:grant-type:device_codeanddevice_code.authorization_pendingmeans keep polling,slow_downmeans poll less often (use the returnedinterval),access_deniedandexpired_tokenare final. On success it returnsapi_key(oct_live_…),token_type,mcp_urlandrest_base, once: store the key, for example asOCTREE_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"}Prints the link, polls, and ends with api_key.
import time, requests
start = requests.post("https://app.useoctree.com/api/v1/device/code",
json={"client_name": "my-cli"}, timeout=30).json()
print("Open this link to connect Octree:", start["verification_uri_complete"])
interval, deadline = start["interval"], time.time() + start["expires_in"]
while time.time() < deadline:
time.sleep(interval)
r = requests.post("https://app.useoctree.com/api/v1/device/token", data={
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
"device_code": start["device_code"],
}, timeout=30)
body = r.json()
if r.ok:
api_key = body["api_key"] # shown once: save it, e.g. as OCTREE_API_KEY
break
if body["error"] == "slow_down":
interval = body.get("interval", interval + 5)
elif body["error"] != "authorization_pending":
raise SystemExit(body["error"]) # access_denied or expired_token
else:
raise SystemExit("expired_token")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.
## 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}"}'Set "response": "pdf" (or send Accept: application/pdf) to get the PDF bytes directly.
curl https://app.useoctree.com/api/v1/compile \
-H "Authorization: Bearer $OCTREE_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/pdf" \
-d '{"latex":"\\documentclass{article}\\begin{document}Hello\\end{document}","response":"pdf"}' \
-o out.pdfCompiles main.tex and saves out.pdf.
import base64, os, requests
resp = requests.post(
"https://app.useoctree.com/api/v1/compile",
headers={"Authorization": f"Bearer {os.environ['OCTREE_API_KEY']}"},
json={"latex": open("main.tex").read()},
timeout=120,
)
resp.raise_for_status()
data = resp.json()
if data["ok"]:
open("out.pdf", "wb").write(base64.b64decode(data["pdf_base64"]))
else:
for e in data["errors"]:
print(f'{e["file"]}:{e["line"]}: {e["message"]}')Node 18+ (built-in fetch), as an ES module.
import { readFile, writeFile } from "node:fs/promises";
const res = await fetch("https://app.useoctree.com/api/v1/compile", {
method: "POST",
headers: {
Authorization: "Bearer " + process.env.OCTREE_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({ latex: await readFile("main.tex", "utf8") }),
});
if (!res.ok) throw new Error("HTTP " + res.status + ": " + (await res.text()));
const data = await res.json();
if (data.ok) await writeFile("out.pdf", Buffer.from(data.pdf_base64, "base64"));
else console.error(data.errors);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 asmain.tex. Use this orfiles. 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
filesonly: the.texfile to compile. Defaults tomain.texif present, else the first.texfile containing\documentclass. The main file must contain\documentclass, or the request is rejected with 400. response"json"|"pdf"json(default) returns the object below;pdfreturns the raw PDF.Accept: application/pdfdoes the same aspdf; an explicitresponsefield wins over the header. Failures are JSON either way.
{
"latex": "\\documentclass{article}\\begin{document}Hello\\end{document}",
"response": "json"
}{
"files": [
{ "path": "main.tex", "content": "\\documentclass{article}\n\\begin{document}\n\\input{sections/intro}\n\\cite{knuth84}\n\\bibliographystyle{plain}\n\\bibliography{refs}\n\\end{document}" },
{ "path": "sections/intro.tex", "content": "\\section{Introduction}\nHello." },
{ "path": "refs.bib", "content": "@book{knuth84, author={Knuth, Donald E.}, title={The TeXbook}, year={1984}, publisher={Addison-Wesley}}" }
],
"main": "main.tex"
}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": false,
"errors": [
{
"file": "main.tex",
"line": 7,
"message": "Undefined control sequence.",
"kind": "undefined_control_sequence"
}
],
"log_tail": "…\n./main.tex:7: Undefined control sequence.\nl.7 \\foo\n…",
"suggestion": "A command is not defined. Check its spelling, or add the \\usepackage that provides it.",
"duration_ms": 960
}{
"error": "quota_exceeded",
"message": "Daily API compile limit of 30 reached on the free plan. Upgrade to Pro for 1000 compiles a day.",
"limit": 30,
"used": 30,
"resets_at": "2026-11-09T00:00:00.000Z",
"upgrade_url": "https://app.useoctree.com/pricing?from=api"
}oktrueif 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 }[]whenokis false.kindis one ofmissing_package,undefined_control_sequence,missing_dollar,missing_braceorlatex_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"{
"user_id": "3f6c…",
"plan": "free",
"daily_limit": 30,
"used_today": 4,
"resets_at": "2026-11-09T00:00:00.000Z"
}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 inerrors. - 400
invalid_request - Malformed body, e.g. invalid JSON, neither
latexnorfiles, more than 50 files, a bad or duplicate path, or a main file without\documentclass. - 401
unauthorized - Missing, invalid, expired or revoked credentials. The body includes
device_authorization_endpointandtoken_endpointso an agent can start the device flow. - 413
payload_too_large - Source over 2 MB, or a request body over 4 MB.
- 429
quota_exceeded - Daily quota used up. Also returns
limit,used,resets_atandupgrade_url. - 429
rate_limited - Too many failed key attempts from your IP address (10 a minute). Check the key and wait for
Retry-Afterseconds. - 503
service_unavailable - The API key check is temporarily unavailable. Retry with backoff.
- 503
compile_unavailable - The compiler is busy or temporarily unavailable. Retry after
Retry-Afterseconds. - 504
compile_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_latexcounts 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-resourceandhttps://app.useoctree.com/.well-known/oauth-authorization-server, registers itself (dynamic client registration or a client ID metadata document), and signs in with PKCE. Scopecompile. - 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, orfiles+main- A short summary (pages and time, or the errors) and the PDF as a resource.
check_latexInput:latex, orfiles+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
.bibfile infilesand 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 →