Compile API Overview
The compile API is the underlying transport the CLI uses. You interact with it directly when you need to:
- Embed compilation into your own tooling (CI scripts, build systems, editor plugins).
- Stream compile output into your own UI.
- List or subscribe to job status programmatically.
- Build on platforms where the CLI is not available.
The endpoint is a WebSocket connection. All control messages are JSON. Source code is sent as raw binary frames. The server streams progress back in real time and sends a final compile.done message with a presigned download URL when compilation finishes.
Base URL
Section titled “Base URL”wss://api.pure.dev/wsConnection lifecycle
Section titled “Connection lifecycle”- Open the WebSocket connection.
- Send a
compile.startJSON message (first message must be this type; it carries your API key). - Stream source tarball as one or more binary frames.
- Send
compile.upload.doneto signal the end of the tarball. - Receive server events:
compile.queued,compile.started,compile.log(repeated),compile.doneorcompile.error. - Close the connection — or send another
compile.startto start a new job on the same connection.
If authentication fails, the server sends auth.error and closes the connection.
Quick example
Section titled “Quick example”import { WebSocket } from 'ws';import { createReadStream } from 'node:fs';import { createGzip } from 'node:zlib';import { createHash } from 'node:crypto';
const ws = new WebSocket('wss://api.pure.dev/ws');
ws.on('open', () => { ws.send(JSON.stringify({ type: 'compile.start', api_key: process.env.PURE_API_KEY, entry: 'src/main.ts', release: true, }));
// send tarball binary frames ... const tarball = readTarball(); // Buffer ws.send(tarball);
ws.send(JSON.stringify({ type: 'compile.upload.done', total_bytes: tarball.byteLength, sha256: computeSha256(tarball), }));});
ws.on('message', (data) => { const msg = JSON.parse(data.toString()); if (msg.type === 'compile.done') { console.log('binary ready at', msg.download_url); ws.close(); } if (msg.type === 'compile.error') { console.error('failed:', msg.message); ws.close(); }});Sections
Section titled “Sections”- Authentication — first-message handshake, error codes
- Protocol reference — every message type, fields, and ordering rules
- Limits — tarball size, compile timeout, concurrency, rate limits
- Error reference — every error code and how to recover
- Downloading results — presigned URL expiry, checksum verification