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

# 列出事件

> 列出 Session 的公开事件。

`GET /api/v1/cloud/sessions/{session_id}/events`

使用游标分页读取 Session 公开事件。如果 `Accept` header 请求 `text/event-stream`，该路由会切换到 SSE streaming；需要 JSON 分页响应时请使用 `Accept: application/json` 或省略 SSE media type。

如果 Session 创建时设置了 `incremental_streaming_enabled: true`，响应中可能包含已持久化的增量 agent 事件；如果该字段为 `false` 或省略，增量事件会被隐藏，只返回完整公开事件。

## 路径参数

| 参数           | 类型     | 说明                        |
| ------------ | ------ | ------------------------- |
| `session_id` | string | 以 `sess_` 为前缀的 Session ID |

## 请求头

| 头部              | 必选 | 说明                  |
| --------------- | -- | ------------------- |
| `Authorization` | 是  | `Bearer $QODER_PAT` |

## 查询参数

| 参数                | 类型             | 必填 | 说明                                                           |
| ----------------- | -------------- | -- | ------------------------------------------------------------ |
| `limit`           | integer        | 否  | 最大返回事件数。默认 20，范围 1-100。超过 100 返回 `400 invalid_request_error` |
| `page`            | string         | 否  | 上一次响应 `next_page` 返回的不透明游标。与 `before_id`、`after_id` 互斥       |
| `before_id`       | string         | 否  | 返回排在该事件 ID 之前的事件。与 `page`、`after_id` 互斥                      |
| `after_id`        | string         | 否  | 返回排在该事件 ID 之后的事件。与 `page`、`before_id` 互斥                     |
| `order`           | string         | 否  | 排序方向：`asc`（默认）或 `desc`                                       |
| `types`           | string 或 array | 否  | 按事件类型过滤。无法识别的事件类型会被静默忽略——响应中不会包含匹配项                          |
| `created_at[gt]`  | string         | 否  | 返回创建时间晚于该 RFC 3339 时间的事件                                     |
| `created_at[gte]` | string         | 否  | 返回创建时间不早于该 RFC 3339 时间的事件                                    |
| `created_at[lt]`  | string         | 否  | 返回创建时间早于该 RFC 3339 时间的事件                                     |
| `created_at[lte]` | string         | 否  | 返回创建时间不晚于该 RFC 3339 时间的事件                                    |

## 示例请求

```bash theme={null}
curl -X GET "https://api.qoder.com/api/v1/cloud/sessions/sess_019e392c0d1e74e095d21ea4c6b41def/events?limit=5&types=user.message,agent.message" \
  -H "Authorization: Bearer $QODER_PAT"
```

## 示例响应

**HTTP 200 OK**

```json theme={null}
{
  "data": [
    {
      "id": "evt_019e392c0d787cfaa21bda98e06cd913",
      "type": "user.message",
      "content": [
        {"type": "text", "text": "Hello, this is a test message."}
      ],
      "processed_at": "2026-05-18T03:40:48.888851795Z"
    },
    {
      "id": "evt_771c1195bcbd4a07834d4ed4dd6450ca",
      "type": "agent.message",
      "content": [
        {"type": "text", "text": "Hello! How can I help you today?"}
      ],
      "processed_at": "2026-05-18T03:40:55.123Z"
    }
  ],
  "first_id": "evt_019e392c0d787cfaa21bda98e06cd913",
  "has_more": false,
  "last_id": "evt_771c1195bcbd4a07834d4ed4dd6450ca",
  "next_page": null
}
```

完整事件类型见 [公开事件类型](/zh/cloud-agents/api/sessions/schemas#公开事件类型)。

对于开启增量流式的 Session，按 `types` 过滤时请使用顶层事件类型：`agent.message_start`、`agent.content_block_start`、`agent.content_block_delta`、`agent.content_block_stop`、`agent.message_delta`、`agent.message_stop`。不要使用 `text_delta` 或 `input_json_delta` 过滤；它们是 `agent.content_block_delta` 内部的 `delta.type`。

## 响应字段

| 字段          | 类型             | 说明                                                               |
| ----------- | -------------- | ---------------------------------------------------------------- |
| `data`      | array          | 公开 [Event 对象](/zh/cloud-agents/api/sessions/schemas#event-对象) 列表 |
| `has_more`  | boolean        | 当前结果集之后还有更多页时为 `true`                                            |
| `first_id`  | string \| null | 当前页第一个事件的 ID                                                     |
| `last_id`   | string \| null | 当前页最后一个事件的 ID                                                    |
| `next_page` | string \| null | 下一页的不透明游标，无更多结果时为 `null`                                         |

## 错误码

| HTTP | 类型                      | 触发条件                                                                   |
| ---- | ----------------------- | ---------------------------------------------------------------------- |
| 400  | `invalid_request_error` | `limit` 非正整数、`order` 非法、时间戳过滤非法，或 `page` 与 `before_id`/`after_id` 同时提供 |
| 401  | `authentication_error`  | PAT 无效或过期                                                              |

> **备注：** 该接口对不存在的 Session ID 返回 HTTP 200 并返回空 `data` 数组，便于客户端安全轮询。如需确认 Session 是否存在，请使用 `GET /api/v1/cloud/sessions/{id}`。

### 示例：400 `order` 非法

```json theme={null}
{
  "error": {
    "message": "Field 'order' must be one of: asc, desc.",
    "type": "invalid_request_error"
  },
  "request_id": "74c9b7ee-f2f4-450a-9283-933fd3315cf8",
  "type": "error"
}
```

### 示例：400 `limit` 非法

```json theme={null}
{
  "error": {
    "message": "Field 'limit' must be a positive integer.",
    "type": "invalid_request_error"
  },
  "request_id": "d582074b-11ec-45cb-9c94-929278a19261",
  "type": "error"
}
```

完整错误信封格式见 [错误参考](/zh/cloud-agents/api/conventions/errors)。

## 相关

<CardGroup cols={2}>
  <Card title="Session 事件流" icon="wave-pulse" href="/zh/cloud-agents/events-stream">
    通过 SSE 实时获取 Agent 的思考、消息、工具调用与状态。
  </Card>
</CardGroup>
