Stream Live Agent Progress with SSE and Last-Event-ID
You started a Task Run to automate a user journey. Now you need the UI to show each step as it happens. The /v1/runs/{id}/events endpoint streams Server-Sent Events. Adding Last-Event-ID lets you reconnect without missing progress. That is the only way to build dashboards with accurate, up-to-date agent state.
How it works
The agent runs on a machine in the cloud. Your client opens the events stream and fetches events one by one. Each event contains type and data fields. When the stream disconnects, send the Last-Event-ID header with the last event ID you received. The server resumes from that ID. When status becomes succeeded, failed, timed_out, or cancelled, the stream ends. You can poll GET /v1/runs/{id} for the final state if needed.
#!/usr/bin/env bash
# stream_events.sh
# Stream a Task Run's events using Last-Event-ID
COASTY_API_KEY=${COASTY_API_KEY?"Please set COASTY_API_KEY"}
RUN_ID="demo-run-123"
# Initial request without Last-Event-ID
echo "Opening stream for run $RUN_ID"
while true; do
# We use curl -N for unbuffered output and -H to pass the header
# Last-Event-ID is empty on the first request
response=$(curl -sS --no-buffer \
-H "Authorization: Bearer $COASTY_API_KEY" \
-H "Accept: text/event-stream" \
"https://coasty.ai/v1/runs/$RUN_ID/events" 2>&1)
# If curl exits with 0 and we got data, we process the events
if [ $? -eq 0 ] && [ -n "$response" ]; then
echo "$response"
else
# curl failed or returned empty; check if the stream ended
if echo "$response" | grep -q "data: done"; then
echo "Run finished."
break
fi
# If the server closed the connection, we exit the loop
echo "Connection closed by server."
break
fi
doneHandling disconnection and reconnect
- ●The server closes the SSE connection when status changes to succeeded, failed, timed_out, or cancelled.
- ●Reconnect with the same URL and include the Last-Event-ID header set to the last event ID you saw.
- ●If the server does not honor Last-Event-ID, it may return events from the beginning; discard any you have already seen.
- ●Use curl -N or an HTTP client that supports Server-Sent Events to avoid buffering.
- ●The final state is also available via GET /v1/runs/{id}, useful for offline querying.
Use Last-Event-ID to reconnect without gaps when streaming events.
Where this beats brittle automation
Selectors and hard-coded selectors break when UI changes. The agent sees the screen just like a human. It follows buttons, forms, and layout shifts. By streaming events, you know what the agent is doing at each step. You can show a progress bar, log each action, and alert users only when the run completes. This visibility is impossible with API-only tools that only return a final result.
Build dashboards that show live agent progress. Stream events from /v1/runs/{id}/events and reconnect with Last-Event-ID. Start building with the Coasty Computer Use API. Get your key at https://coasty.ai/developers.