Engineering

Stream Live Agent Progress with SSE and Last-Event-ID

Rachel Kim||6 min
Ctrl+P

You start an agent run and then you need to know exactly where it stands. Polling GET /v1/runs/{id} works but it costs extra requests and introduces lag. Server-Sent Events (SSE) give you a single open connection that pushes state updates from the server as they happen. The Coasty Computer Use API streams run events, including queued, running, awaiting_human, succeeded, failed, cancelled, and timed_out, and supports Last-Event-ID for resuming after a disconnect.

How it works

POST /v1/runs creates the agent run and returns an id. Then use GET /v1/runs/{id}/events with a Last-Event-ID header to recover from a drop. The stream returns Server-Sent Events with text/event-stream content, each line prefixed by data: and containing a JSON event object. You parse each event to update a dashboard or log the progress. The agent state flows in real time, so you can react instantly to failures or human approval requests without extra round trips.

bash
#!/bin/bash
COASTY_API_KEY="${COASTY_API_KEY}"
RUN_ID="your-run-id-here"

# Start the run (once)
curl -s -X POST https://coasty.ai/v1/runs \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "your-machine-id",
    "task": "Open Chrome and navigate to https://example.com",
    "cua_version": "v3"
  }'

# Stream live events with Last-Event-ID for recovery
curl -s -N \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Accept: text/event-stream" \
  "https://coasty.ai/v1/runs/${RUN_ID}/events"

Key SSE patterns and fields

  • The endpoint returns text/event-stream and each event line is prefixed with data: .
  • The event JSON includes fields like id, type, timestamp, and state from the run.
  • Use the Last-Event-ID header when reconnecting to resume from the last processed event.
  • State values include queued, running, awaiting_human, succeeded, failed, cancelled, timed_out.
  • The stream stays open for the duration of the run until the agent completes or the connection closes.

Use Last-Event-ID on reconnect to pick up exactly where the stream left off.

Where this beats brittle automation

Traditional automation relies on fragile selectors that break when pages change layout. A computer use agent sees the screen, interprets visual context, and acts like a human. Streaming events lets you observe the agent in action, detect failures early, and even pause for human approval. This visibility is impossible with headless API calls alone.

Start streaming live agent progress today by creating a key at https://coasty.ai/developers . Use Server-Sent Events to build dashboards, debug workflows, or integrate human approval flows directly into your CI/CD pipelines.

Want to see this in action?

View Case Studies
Try Coasty Free