Engineering

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

Priya Patel||6 min
Ctrl+Z

When you spin up a computer use agent in the cloud, you need more than just a final status. You want to see what the agent sees, know when it pauses for human approval, and automatically reconnect if the network drops. The GET /v1/runs/{id}/events endpoint streams Server-Sent Events (SSE) for exactly this use case. It gives you a live view of task runs from queued to succeeded, failed, or cancelled with the ability to resume from any event.

How it works

A task run executes an agent on a provisioned machine. The server emits an event for each major state change and for every agent step. Events include fields like type (queued, running, awaiting_human, succeeded, failed, cancelled, timed_out), step_id, timestamp, and optional payload. You connect once, read the stream, and handle each event. If the connection closes, include the Last-Event-ID header when reconnecting so the server resumes from that exact event instead of sending everything again.

python
import os import requests import json

COASTY_API_KEY = os.getenv("COASTY_API_KEY")
BASE_URL = "https://coasty.ai/v1"

def stream_run_events(run_id):
    url = f"{BASE_URL}/runs/{run_id}/events"
    headers = {
        "Authorization": f"Bearer {COASTY_API_KEY}",
        "Accept": "text/event-stream",
    }
    last_event_id = None

    resp = requests.get(url, headers=headers, stream=True)
    resp.raise_for_status()

    for line in resp.iter_lines(decode_unicode=True):
        if not line:
            continue

        # SSE format is "data: {...}"
        if line.startswith("data: "):
            data = json.loads(line[6:])
            event_type = data.get("type")
            print(f"Event: {event_type}", data)
            last_event_id = data.get("id")

            if event_type in ("succeeded", "failed", "cancelled", "timed_out"):
                print("Run finished")
                break

    return last_event_id

if __name__ == "__main__":
    # Replace with an actual run_id from a POST /v1/runs call
    run_id = "your-run-id"
    stream_run_events(run_id)

Key event types and fields

  • queued: run accepted and placed in the queue
  • running: agent started on a machine
  • awaiting_human: server paused for human approval (on_awaiting_human: pause)
  • step: each billed agent step with step_id, timestamp, and action details
  • succeeded: run completed successfully (status succeeded)
  • failed: run aborted due to error (status failed)
  • cancelled: run terminated by client (status cancelled)
  • timed_out: run exceeded deadline_seconds
  • Each event carries an id field for Last-Event-ID reconnection.

Include the Last-Event-ID header on every reconnect to resume streaming from that exact event.

Where this beats brittle automation

Traditional automation relies on stable selectors and API-only tools that break when UI changes or when you need to click, drag, or fill forms. With a computer use agent, you stream live events and see every step the agent takes on a real desktop. You know when it pauses for human approval and can integrate that pause into your workflow. If the stream drops, Last-Event-ID lets you reconnect without losing progress. You can also hook into webhooks for external notifications, handling state changes asynchronously and reacting to failures or interruptions in real time.

Track live agent progress with SSE, reconnect with Last-Event-ID, and build resilient computer use workflows. Start building with a key at https://coasty.ai/developers .

Want to see this in action?

View Case Studies
Try Coasty Free