Skip to content

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.

wss://api.pure.dev/ws
  1. Open the WebSocket connection.
  2. Send a compile.start JSON message (first message must be this type; it carries your API key).
  3. Stream source tarball as one or more binary frames.
  4. Send compile.upload.done to signal the end of the tarball.
  5. Receive server events: compile.queued, compile.started, compile.log (repeated), compile.done or compile.error.
  6. Close the connection — or send another compile.start to start a new job on the same connection.

If authentication fails, the server sends auth.error and closes the connection.

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();
}
});