# Read a session's transcript

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

The captured transcript as the events the live stream carries (`message`,
`tool_use`, `tool_result`, `thinking`, `error`, `result`), filtered and sliced
on the server. A turn starts at each user message; `first`/`last` keep that
many turns, then `include`/`exclude` filter by role. Available once the run
has captured its transcript; before that the answer is `404 SESSION_NOT_CAPTURED`.

## 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`). |
| `include` | query | string | no | Comma-separated roles to keep. |
| `exclude` | query | string | no | Comma-separated roles to drop. Not with `include`. |
| `first` | query | integer | no | Keep the first N turns. Not with `last`. |
| `last` | query | integer | no | Keep the last N turns. Not with `first`. |

## Example request

```bash
curl "https://api.phoenix.so/o/$RUSH_ORG/sessions/$SESSION_ID/messages" \
  -H "Authorization: Bearer $RUSH_API_KEY"
```

```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}/messages`, {
  headers: {
    Authorization: `Bearer ${process.env.RUSH_API_KEY}`,
  },
});

console.log(res.status, await res.json());
```

```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}/messages",
    headers={"Authorization": f"Bearer {os.environ['RUSH_API_KEY']}"},
)

print(res.status_code, res.json())
```

## Responses

### 200

The transcript slice.

- `execution_id` (string, required)
- `events` (array of SessionEvent, optional): Absent when the slice holds none.
  - `type` (string, required, one of `message`, `tool_use`, `tool_result`, `thinking`, `error`, `result`)
  - `role` (string, optional, one of `user`, `assistant`)
  - `content` (string, optional)
  - `tool` (string, optional)
  - `call_id` (string, optional): Links a tool_use to its tool_result.
  - `args` (object, optional): A tool_use's input as the agent wrote it, e.g. `command` or `file_path`.
  - `success` (boolean, optional)
  - `output` (string, optional)

### 400

A bad filter (`INVALID_FILTER`): an unknown role, `include` with `exclude`, or `first` with `last`.

### 401

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

### 404

No such session of yours (`NOT_FOUND`), or no transcript captured yet (`SESSION_NOT_CAPTURED`).

### 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)

```json
{
  "execution_id": "7c1e9a4f-2b6d-4f83-a5c0-9e3d1b8f6a24",
  "events": [
    {
      "type": "message",
      "role": "user",
      "content": "Fix the flaky checkout test and open a PR."
    },
    {
      "type": "tool_use",
      "tool": "Bash",
      "call_id": "toolu_01Fj19",
      "args": {
        "command": "bun test checkout"
      }
    },
    {
      "type": "tool_result",
      "tool": "Bash",
      "call_id": "toolu_01Fj19",
      "success": false,
      "output": "1 fail"
    },
    {
      "type": "message",
      "role": "assistant",
      "content": "Pinned the clock in checkout.spec.ts and opened PR 412."
    }
  ]
}
```
