You are building a dashboard or CLI that watches a computer use agent as it moves a mouse, clicks, and types. You need live updates, not just an async webhook callback that may be throttled or hidden behind an external service. The Coasty Computer Use API gives you direct access to the run stream with Server-Sent Events (SSE). Use GET /v1/runs/{id}/events and Last-Event-ID to reconnect after network interruptions without losing progress.
How it works
When you POST /v1/runs to start a task, the server returns a run object with an id and initial state (queued, running, etc.). To get live updates, open an SSE stream to GET /v1/runs/{id}/events. The server pushes Server-Sent Events with a data field containing a JSON object describing the run state. The stream may be long-lived, so you need to handle reconnection. Include the Last-Event-ID header on the next request with the last event ID you received. The server then sends events from that point forward. States are queued, running, awaiting_human, succeeded, failed, cancelled, timed_out.
import os
import json
import requests
COASTY_API_KEY = os.environ.get('COASTY_API_KEY')
BASE_URL = "https://coasty.ai/v1"
def stream_run_events(run_id, max_retries=5):
url = f"{BASE_URL}/runs/{run_id}/events"
headers = {
"Authorization": f"Bearer {COASTY_API_KEY}",
"Accept": "text/event-stream",
}
last_event_id = None
for attempt in range(max_retries):
req_headers = headers.copy()
if last_event_id:
req_headers["Last-Event-ID"] = last_event_id
try:
with requests.get(url, headers=req_headers, stream=True, timeout=30) as r:
r.raise_for_status()
for line in r.iter_lines(decode_unicode=True):
if not line:
continue
if line.startswith("data: "):
data = line[6:]
payload = json.loads(data)
last_event_id = payload.get("id") or last_event_id
print(json.dumps(payload))
if payload.get("status") in ("succeeded", "failed", "cancelled", "timed_out"):
break
except requests.exceptions.RequestException as exc:
print(f"Network error: {exc}. Retry {attempt + 1}/{max_retries}")
continue
else:
break
if __name__ == "__main__":
run_id = "<run-id-from-create-run-response>"
stream_run_events(run_id)Request and response fields
- Endpoint: GET /v1/runs/{id}/events
- Header: Authorization Bearer <key>
- Header: Accept text/event-stream
- Header: Last-Event-ID (optional, string)
- Response body: Server-Sent Events with data: { JSON }
- Event object fields: id, status (queued, running, awaiting_human, succeeded, failed, cancelled, timed_out), timestamp, and run-level details
- Rate limit: 429 error if you exceed allowed events per second
- Billing: $0.05 per agent step, not per SSE event
Include Last-Event-ID on reconnection to resume SSE from the last event without losing progress.
Where this beats brittle automation
API-only automation relies on static selectors and brittle selectors that break when UI changes. Computer use agents act like humans, see the screen, reason, and move the mouse and type. Streaming events lets you show live progress, handle human approval states, and react to failures in real time. Use SSE and Last-Event-ID for dashboards, CLI tools, or internal monitoring systems that need uninterrupted visibility into agent steps.
Add live dashboards to your computer use agents by streaming /v1/runs/{id}/events and using Last-Event-ID to reconnect. Get your API key at https://coasty.ai/developers.
Want to see this in action?
View Case Studies