> ## 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 Event Stream

> 通过 SSE 订阅 Forward Session 事件流。

`GET /api/v1/forward/sessions/{session_id}/events/stream`

以 Server-Sent Events 形式实时返回 Session 事件；`data` payload 与历史查询使用相同的 Forward 字段过滤模型。

## 请求头

| Header        | 是否必填 | 说明                  |
| ------------- | ---- | ------------------- |
| Authorization | 是    | `Bearer <PAT>`      |
| Accept        | 是    | `text/event-stream` |
| Last-Event-ID | 否    | 从该 Event ID 之后恢复订阅。 |

## 路径参数

| 参数          | 类型     | 是否必填 | 说明          |
| ----------- | ------ | ---- | ----------- |
| session\_id | string | 是    | Session ID。 |

## 查询参数

| 参数                   | 类型      | 是否必填 | 默认值  | 说明                   |
| -------------------- | ------- | ---- | ---- | -------------------- |
| type                 | string  | 否    | -    | 按 Event 类型过滤，支持逗号分隔。 |
| types\[]             | string  | 否    | -    | 数组形式的 Event 类型过滤。    |
| include\_tool\_calls | boolean | 否    | true | 是否包含工具调用类事件。         |
| include\_thinking    | boolean | 否    | true | 是否包含思考过程事件。          |

## 示例请求

```bash theme={null}
curl -s -X GET 'https://api.qoder.com/api/v1/forward/sessions/sess_xxx/events/stream' \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Accept: text/event-stream"
```

## 示例响应

**HTTP 200 OK**

```text theme={null}
id: evt_xxx
event: agent.message
data: {"id":"evt_xxx","type":"agent.message","session_id":"sess_xxx","content":[{"type":"text","text":"Here is the analysis result."}],"processed_at":"2026-06-22T11:00:03Z"}
```

## 响应字段

| 字段    | 类型     | 说明                                                                                |
| ----- | ------ | --------------------------------------------------------------------------------- |
| id    | string | SSE event ID，等于 Event ID。                                                         |
| event | string | Event 类型。                                                                         |
| data  | object | 过滤后的 Forward Event JSON；payload 字段遵循 List Session Events 中按 Event `type` 分发的字段矩阵。 |

## 错误

| HTTP | Type                    | Code                      | 触发条件                           |
| ---- | ----------------------- | ------------------------- | ------------------------------ |
| 400  | `invalid_request_error` | `invalid_event_cursor`    | `Last-Event-ID` 不属于当前 Session。 |
| 404  | `not_found_error`       | `session_not_found`       | Session 不存在。                   |
| 401  | `authentication_error`  | `authentication_required` | PAT 无效或已过期。                    |

## 注意事项

* 增量流式由创建 Session 时的 `incremental_streaming_enabled` 控制，不能通过本接口临时开启。
* 未知 Event 类型可用时会作为 envelope-only 事件转发。
* `include_thinking=false` 会过滤 thinking 事件和可识别的 thinking delta。
* `include_tool_calls=false` 会过滤工具调用事件和可识别的工具输入/输出 delta。

## 相关

<CardGroup cols={2}>
  <Card title="创建 Session" icon="plus" href="/cloud-agents/api/forward/sessions/create" />

  <Card title="列出 Session Events" icon="list" href="/cloud-agents/api/forward/sessions/list-events" />
</CardGroup>
