Streaming (SSE)
By default, Wrapd streams command output in real-time using Server-Sent Events.
Consuming the stream
Section titled “Consuming the stream”curl -N https://api.wrapd.sh/v1/alice/deploy \ -H "X-API-Key: wrapd_sk_your_key"The -N flag disables output buffering in curl.
Event types
Section titled “Event types”output
Section titled “output”Emitted for each line of stdout/stderr (when no transformer is configured):
data: {"type":"output","data":"Building project..."}
data: {"type":"output","data":"Compiling 42 files..."}transformed_output
Section titled “transformed_output”Emitted once with the full transformed result (when a transformer is configured):
data: {"type":"transformed_output","data":{"cpu":45,"mem":72}}Emitted when the command completes:
data: {"type":"done","exit_code":0,"duration_ms":1234}Emitted if the execution fails:
data: {"type":"error","error":"Command timed out after 60s"}JavaScript example
Section titled “JavaScript example”const evtSource = new EventSource( 'https://api.wrapd.sh/v1/alice/deploy', // Note: EventSource doesn't support custom headers. // Use fetch() with ReadableStream for API key auth.);Using fetch for SSE with auth
Section titled “Using fetch for SSE with auth”const response = await fetch('https://api.wrapd.sh/v1/alice/deploy', { method: 'POST', headers: { 'X-API-Key': 'wrapd_sk_your_key', 'Content-Type': 'application/json', }, body: JSON.stringify({ branch: 'main' }),});
const reader = response.body.getReader();const decoder = new TextDecoder();
while (true) { const { done, value } = await reader.read(); if (done) break;
const text = decoder.decode(value, { stream: true }); // Parse SSE events from text for (const line of text.split('\n')) { if (line.startsWith('data: ')) { const event = JSON.parse(line.slice(6)); console.log(event.type, event.data || event.exit_code); } }}Timeout
Section titled “Timeout”Commands have a configurable timeout (default 60 seconds). If exceeded, the process is killed and an error event is sent. The forwarding layer has a hard cap of 120 seconds.