# Follow a session live

`GET /o/{org}/sessions/{session}/events`

A server-sent event stream of the run as it happens. Before the sandbox
starts you get `status` events (`{status}`); then the harness's own
events (`message`, `tool_use`, `tool_result`, `thinking`, `result`,
`error`), each with an `id`. A session still `queued` gets one `status` event
and the stream closes, so reconnect until it has started. The stream ends with `done`, whose data is
`{status, output, result}`: `result` is the `SessionAnswer`, or null when
the run produced none. On a session that already finished the stream
sends only `status` and `done`, never the history: read that from
`GET …/messages` or `GET …/trajectory`. An `error` without a `type` (`{code, message}`,
`code` one of `NOT_FOUND` or `STREAM_ERROR`) ends it early. An API key
receives only these events. Reconnect with `Last-Event-ID` (or `?cursor=`)
to resume after the last event you saw. Comment lines (`: keepalive`) keep
idle connections open.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `org` | path | string | yes | The org's slug or id. A caller with no role in the org gets `404`. |
| `session` | path | string | yes | The session's full id (`execution_id`). |
| `cursor` | query | string | no | Same as `Last-Event-ID`, for clients that cannot set headers. |
| `last-event-id` | header | string | no | Resume after this event id. |

## Example request

```bash
curl -N "https://api.phoenix.so/o/$RUSH_ORG/sessions/$SESSION_ID/events" \
  -H "Authorization: Bearer $RUSH_API_KEY" \
  -H "Accept: text/event-stream"
```

```typescript
const org = process.env.RUSH_ORG;
const sessionId = process.env.SESSION_ID;

const res = await fetch(`https://api.phoenix.so/o/${org}/sessions/${sessionId}/events`, {
  headers: {
    Authorization: `Bearer ${process.env.RUSH_API_KEY}`,
    Accept: "text/event-stream",
  },
});

// Each frame is `event: <type>` and `data: <json>`, then a blank line.
const decoder = new TextDecoder();
for await (const chunk of res.body!) {
  process.stdout.write(decoder.decode(chunk, { stream: true }));
}
```

```python
import os

import requests

org = os.environ["RUSH_ORG"]
session_id = os.environ["SESSION_ID"]

res = requests.get(
    f"https://api.phoenix.so/o/{org}/sessions/{session_id}/events",
    headers={"Authorization": f"Bearer {os.environ['RUSH_API_KEY']}", "Accept": "text/event-stream"},
    stream=True,
)

for line in res.iter_lines(decode_unicode=True):
    print(line)
```

## Responses

### 200

The event stream.

### 401

No bearer, an unknown, revoked or expired one, or an API key on a route keys cannot call.

### 404

No such resource for the caller, including one in an org the caller is not in or a Project that is private to someone else.

### 429

The account is over its request budget, 1,800 a minute shared by the person's API keys and console on every API host (`RATE_LIMITED`). The error names the limit. Wait `Retry-After` seconds.

## Example response (200)

```http
event: status
data: {"status":"allocating","id":"7c1e9a4f-2b6d-4f83-a5c0-9e3d1b8f6a24"}

event: done
data: {"status":"completed","output":"runtime: guest harness completed","result":{"text":"Pinned the clock in checkout.spec.ts.","structured":null,"schema_valid":null}}
```
