Compilation

GETPOST/builds/sync

Compile a LaTeX document and get back the generated PDF, waiting for the end of the build (synchronous).

The request carries a compilation specification: the LaTeX compiler to use, the resources (the LaTeX sources and their dependencies — images, bibliographies, included files…) and build options. Three input modes are supported, all served by the same endpoint:

On success the response body is the generated PDF (HTTP 201). On failure the response is a JSON payload with the error and the compiler logs (see the response reference).

Available compilers

CompilerDescription
pdflatex Default. Classic pdfTeX, ASCII-oriented, widely compatible.
xelatex Unicode-native engine, uses system fonts (fontspec).
lualatex Unicode-native engine with embedded Lua scripting.
platex Japanese pTeX engine (DVI output, converted with dvipdfmx).
uplatex Unicode Japanese upTeX engine (DVI output, converted with dvipdfmx).
context ConTeXt standalone typesetting system.

The compiler property defaults to pdflatex.

GET querystring mode

Pass the main document and annex resources as GET parameters. Handy for quick one-liners and ?compiler=…&url=… bookmarklets; better suited to small documents, as everything travels in the URL.

Name Type Default Description
content
one of content / url / file
string — Main document, as a (URL-encoded) LaTeX string. Values starting with http given without a resource-type[] are guessed as URLs.
url
one of content / url / file
string (URL) — Main document, fetched by the server from this URL.
file
one of content / url / file
string (base64) — Main document, base64-encoded.
compiler string pdflatex One of pdflatex, xelatex, lualatex, platex, uplatex, context.
resource-path[] string (repeatable) — Path of an annex resource, relative to the main document (eg. logo.png, chapters/intro.tex).
resource-type[] string (repeatable) guessed Type of the matching resource-value[]: url, file (base64) or content (plain string). base64 and string are accepted aliases.
resource-value[] string (repeatable) — Content (URL, base64 data or string) of the matching resource.
options.* string — Dotted build options, eg. options.compiler.shell_escape=true. See the options reference.
# Compile a document passed inline as the main resource:
curl -G https://latex.ytotech.com/builds/sync \
    --data-urlencode 'content=\documentclass{article} \begin{document} Hello World LaTeX-On-HTTP \end{document}' \
    --output hello_world.pdf

# Compile a document fetched from an URL, with the XeLaTeX compiler,
# plus an annex resource (an image downloaded from an URL):
curl -G https://latex.ytotech.com/builds/sync \
    --data-urlencode 'compiler=xelatex' \
    --data-urlencode 'url=https://raw.githubusercontent.com/YtoTech/latex-on-http/master/examples/templates/moderncv.tex' \
    --data-urlencode 'resource-type[]=url' \
    --data-urlencode 'resource-path[]=logo.png' \
    --data-urlencode 'resource-value[]=https://www.ytotech.com/images/ytotech_logo.png' \
    --output resume.pdf

POST JSON mode

The richest input mode: a JSON payload describing the compiler, the resources (inline content, base64 files, remote URLs or cache hits) and the build options.

Name Type Default Description
compiler string pdflatex One of pdflatex, xelatex, lualatex, platex, uplatex, context.
resources
required
list of objects — The files uploaded and compiled. See the resource fields: each entry takes a main flag, a path and exactly one source field (content, file, url or cache).
options object — Build options, nested (options.compiler.…, options.response.…). Top-level dotted keys ("options.compiler.silent": true) are also accepted and merged.

Resource entries

The resources list describes the files uploaded and compiled server-side. The file arborescence is reconstructed from the path properties, so relative references (\include{chapters/intro}, \includegraphics{logo.png}…) work as in a local compilation. Each entry takes:

Name Type Default Description
main boolean — Mark the entry as the main LaTeX document. With several entries exactly one must be flagged; with a single entry it is the main document automatically.
path string — File path, relative to the main document, under which the resource is written server-side before the compilation. Mandatory for non-main entries so they can be referred to from the LaTeX sources.
content string — Resource source: plain text content, as a valid JSON string (UTF-8). Use this mode for LaTeX sources.
file string (base64) — Resource source: file content, base64-encoded.
url string (URL) — Resource source: the file is downloaded by the server from this URL before the compilation.
cache string (hash) — Resource source: retrieve the content from the server input cache, identified by its sha256:… hash. Only useful to smart clients that precomputed resource hashes (caches API).
multipart string — Multipart API only: name of the multipart/form-data part holding the resource content. The part is read as binary data (base64-encoded server-side).
curl -X POST https://latex.ytotech.com/builds/sync \
    -H "Content-Type: application/json" \
    -d '{
    "compiler": "lualatex",
    "resources": [
        {
            "main": true,
            "content": "\\documentclass{article}\n\\usepackage{graphicx}\n\\begin{document}\n Hello World\\\\\n \\includegraphics[height=2cm,width=7cm,keepaspectratio=true]{logo.png}\n \\include{page2}\n\\end{document}"
        },
        {
            "path": "logo.png",
            "url": "https://www.ytotech.com/images/ytotech_logo.png"
        },
        {
            "path": "page2.tex",
            "file": "VGhpcyBpcyB0aGUgc2Vjb25kIHBhZ2UsIHdoaWNoIHdhcyBwYXNzZWQgYXMgYSBiYXNlNjQgZW5jb2RlZCBmaWxl"
        }
    ]
}' \
    --output hello_world.pdf

POST multipart/form-data mode

Send the resources as multipart/form-data parts: the natural choice to upload local/binary files (images, bibliographies, class files…), with no base64 encoding step.

Name Type Default Description
compiler string (form field) pdflatex LaTeX compiler to use.
options.* string (form fields) — Dotted build options as form fields, eg. options.compiler.halt_on_error=true.
resources string (form field, JSON) — JSON list of resource entries. Each entry maps to an uploaded file part with the multipart field (naming the form part), plus main and path; entries without multipart may still use inline content/file/url sources. The file content is transferred as binary data.
(file parts) binary — The uploaded files referenced by the multipart entries. If no resources form field is given, the resources are reconstructed from the uploaded parts: the first .tex part is the main document, each part is stored under its file name.
# Declare the resources with a JSON form entry, and reference the
# uploaded multipart file parts by name (binary transfer, no base64):
curl -X POST https://latex.ytotech.com/builds/sync \
    -F 'compiler=pdflatex' \
    -F 'resources=[{"main": true, "multipart": "main"}, {"path": "logo.png", "multipart": "logo"}]' \
    -F 'main=@main.tex' \
    -F 'logo=@logo.png' \
    --output document.pdf

# Or simply upload the files: the first .tex part is taken as the
# main document, and every part is stored under its file name.
curl -X POST https://latex.ytotech.com/builds/sync \
    -F 'file=@main.tex' \
    --output document.pdf

Build options

The options object tunes the compilation and the response contents. Boolean values may be given as JSON booleans, or as strings ("true", "1", "t") in querystring and multipart modes.

Name Type Default Description
options.compiler.bibliography boolean true Run bibtex/biber as needed to regenerate .bbl files (LaTeXmk -bibtex option).
options.compiler.halt_on_error boolean false Stop on the first error, even if non-fatal (-halt-on-error option).
options.compiler.silent boolean false Non-verbose mode: -interaction=batchmode and LaTeXmk -silent. By default -interaction=nonstopmode is used.
options.compiler.force boolean true Force LaTeXmk to process the document even if errors occur (-f flag).
options.compiler.shell_escape boolean false Enable TeX -shell-escape inside the isolated compilation sandbox, for packages such as minted that run pygmentize. The engine otherwise receives an explicit -no-shell-escape option. See the sandboxing model.
options.response.log_files_on_failure boolean true Return the full LaTeX log files (log_files property) in the JSON payload on compilation error.
options.response.commands boolean false Return the details of the commands run during the compilation (commands property) in the JSON payload on compilation error.

Response

On success

201 Created with the generated PDF as body (Content-Type: application/pdf, Content-Disposition: inline, so browsers display it instead of downloading it). The response carries an X-Job-ID header identifying the compilation job.

On failure

400 with a JSON payload describing the failure: error (error code), duration, logs (compiler output) and, unless disabled, log_files (full LaTeX log files). Add options.response.commands to get the commands run. 429 when the fair-use quota is exceeded (rate limiting & quotas). 503 if the compilation sandbox is unavailable; 500 on unexpected server errors.

Example error payload (with options.response.log_files_on_failure enabled, the default):

{
    "error": "COMPILATION_ERROR",
    "duration": 0.68,
    "logs": "This is pdfTeX, Version ...\n! LaTeX Error: File `graphix.sty' not found.\n...",
    "log_files": {
        "__main_document__.log": "... full LaTeX log ..."
    }
}

Error codes

Error code HTTP Meaning
INVALID_PAYLOAD_SHAPE 400 The payload does not match the input specification (shape_errors details the schema violations).
MISSING_COMPILATION_SPECIFICATION 400 No compilation specification could be parsed from the request.
MISSING_RESOURCES 400 The resources list is missing.
RESOURCES_SPEC_MUST_BE_A_LIST 400 resources is not a list.
MULTIPLE_RESOURCE_SOURCES 400 A resource entry specifies several source fields at once (url, file, git, tar, cache, content): use exactly one.
MUST_SPECIFY_MAIN_DOCUMENT 400 No resource is flagged as the main document (main: true), while the compilation has several entries.
MORE_THAN_ONE_MAIN_DOCUMENT 400 Several resources are flagged as the main document.
MISSING_PATH_ON_RESOURCE 400 A non-main resource entry is missing its path.
INVALID_COMPILER 400 Unknown compiler value. available_compilers lists the supported engines.
INVALID_RESOURCE_TYPE 400 Querystring mode: resource-type[] is not one of url, file (or base64), content (or string).
RESOURCES_SPEC_MUST_BE_OF_SAME_LENGTH 400 Querystring mode: resource-path[], resource-type[] and resource-value[] have different lengths.
INVALID_STRING_CONTENT 400 A content resource is not a JSON string.
INVALID_BASE64_CONTENT 400 A file resource is not valid base64 content. path is the resource's path in the build filesystem.
RESOURCE_FETCH_FAILURE 400 A resource could not be fetched. fetch_error carries a machine-readable type: http_error (a non-2xx status), connection_error, request_timeout, invalid_url (missing or unsupported scheme, no host, or an invalid port — allowed_schemes lists the accepted schemes), ssrf_blocked (the URL would reach a private, loopback or link-local address), resource_too_large (the resource exceeds the instance MAX_RESOURCE_SIZE limit — size and max_size are in bytes) or total_too_large (the combined size of the build's fetched resources exceeds the instance MAX_TOTAL_RESOURCE_SIZE limit — total_size and max_total_size are in bytes). The size limits apply to every resource type, including inline content and cache hits.
FETCH_METHOD_NOT_SUPPORTED 400 The resource source is not implemented server-side (eg. git/tar are accepted by the schema but not yet supported).
COMPILATION_ERROR 400 The LaTeX compilation failed. logs (and, by default, log_files) detail the LaTeX errors.
COMPILATION_TIMEOUT 400 The compilation exceeded the server timeout (DEFAULT_COMPILE_TIMEOUT, 100 s by default).
SANDBOX_UNAVAILABLE 503 The compilation sandbox could not be set up; the server refuses to compile without isolation. See the sandboxing documentation.
QUOTA_EXCEEDED 429 Fair-use quota exceeded for your client IP. Honor Retry-After and back off: continuing to retry escalates into a temporary ban. See the rate limiting documentation.
QUOTA_STORE_UNAVAILABLE 503 The quota store (Valkey) is unreachable on an instance configured with QUOTA_FAIL_MODE=closed; most instances fail open and keep serving instead.
REQUEST_TOO_LARGE 413 The request body exceeds the instance limit (MAX_REQUEST_BODY_BYTES, 40 MiB by default). Reduce the size of the uploaded resources; the body is rejected before it is read.
SERVER_ERROR 500 An unexpected error occurred server-side.