> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pre.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Stream a Running Task

> GET /browser-agent/{id}/stream — Server-Sent Events for a task run that's already in progress.

Attach a live Server-Sent Events stream to an in-progress run. You get an
immediate snapshot, then per-step events as they happen. The stream closes
itself when the run completes or fails.

Use this when you submitted with `async: true` and want live progress without
polling. If you want streaming from the moment of submission, pass
`stream: true` on [`POST /browser-agent`](/browser-agents/api/run-task) instead.

## Endpoint

```
GET https://api.pre.dev/browser-agent/{id}/stream
```

## Auth

Standard header auth works, and because `EventSource` in browsers can't set
custom headers, an `apiKey` query param is also accepted:

```bash theme={null}
# Header auth
curl -N https://api.pre.dev/browser-agent/$BATCH_ID/stream \
  -H "Authorization: Bearer $PREDEV_API_KEY"

# Query-param auth (for EventSource)
curl -N "https://api.pre.dev/browser-agent/$BATCH_ID/stream?apiKey=$PREDEV_API_KEY"
```

## Events

| Event         | Payload                                             | When                                                |
| ------------- | --------------------------------------------------- | --------------------------------------------------- |
| `snapshot`    | Full result so far (with events)                    | Immediately on connect                              |
| `task_event`  | One execution step (navigation, action, extraction) | Live, per step                                      |
| `task_result` | A task's final result                               | As each task finishes                               |
| `done`        | Final state                                         | The run completed or failed, then the stream closes |

## Errors

| Status | Meaning                                                                                                    |
| ------ | ---------------------------------------------------------------------------------------------------------- |
| `404`  | Run not found (or not yours)                                                                               |
| `400`  | Invalid id                                                                                                 |
| `503`  | Server at SSE capacity — fall back to polling [`GET /browser-agent/{id}`](/browser-agents/api/task-status) |

## Example

```ts theme={null}
const res = await fetch(
  `https://api.pre.dev/browser-agent/${batchId}/stream`,
  { headers: { Authorization: `Bearer ${process.env.PREDEV_API_KEY}` } }
);

const reader = res.body!.getReader();
const decoder = new TextDecoder();
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  process.stdout.write(decoder.decode(value));
}
```

<Card title="Poll instead" icon="rotate" href="/browser-agents/api/task-status">
  GET /browser-agent/:id — simple polling with optional event timeline.
</Card>
