通过 SSE 订阅 Forward Session 事件流。
GET /api/v1/forward/sessions/{session_id}/events/stream
以 Server-Sent Events 形式实时返回 Session 事件;data payload 与历史查询使用相同的 Forward 字段过滤模型。新接入如需流式输出,建议通过 event_deltas[] 订阅流式增量事件。
请求头
| Header | 是否必填 | 说明 |
|---|---|---|
| Authorization | 是 | Bearer <PAT 或 SAT> |
| Accept | 是 | text/event-stream |
| Last-Event-ID | 否 | 从该 Event ID 之后恢复订阅。 |
路径参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| session_id | string | 是 | Session ID。 |
查询参数
| 参数 | 类型 | 是否必填 | 默认值 | 说明 |
|---|---|---|---|---|
| event_deltas[] | string | 否 | - | 订阅指定公开事件类型的流式增量事件。支持重复传参,取值见 Session 与 Event 数据结构。 |
| include_tool_calls | boolean | 否 | true | 是否包含工具调用类事件。 |
| include_thinking | boolean | 否 | true | 是否包含思考过程事件。 |
示例请求
示例响应
HTTP 200 OK
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | SSE event ID,等于 Event ID。 |
| event | string | Event 类型。 |
| data | object | 过滤后的 Forward Event JSON。普通公开事件的 payload 字段遵循 List Session Events 中按 Event type 分发的字段矩阵;流式增量事件见数据结构文档中的 event_start / event_delta。 |
连接中断与重连
SSE 连接可能因网关超时、服务端重启等原因断开,服务端不保证连接长期存活,客户端必须自行实现重连重试:
- 持续记录最后收到的 SSE frame 的
id(即 Event ID)。 - 断开后用
Last-Event-ID请求头携带该 ID 重新订阅,从断点继续,避免漏收事件。 - 重连不带
Last-Event-ID时,从该 Session 的第一条 Event 开始回放;不会遗漏事件,但会重复收到已消费的 Event,请基于 Event ID 做幂等消费。
错误
| HTTP | Type | Code | 触发条件 |
|---|---|---|---|
| 404 | not_found_error | - | Last-Event-ID 对应的 Event 不存在或不属于当前 Session。 |
| 404 | not_found_error | session_not_found | Session 不存在。 |
| 401 | authentication_error | authentication_required | PAT 或 SAT 无效或已过期。 |
备注
event_deltas[]是推荐的新流式开启方式;未传该参数时只返回普通公开事件。- 一次模型调用完成后会输出
span.model_request_end模型用量事件,model_usage.credits为单次调用增量;Session 累计用量请通过获取 Session 接口读取usage.total_credits,字段见数据结构文档中的模型用量事件。 - 未知 Event 类型可用时会作为 envelope-only 事件转发。
include_thinking=false会过滤 thinking 事件、旧版 thinking delta,以及新流式中的agent.thinking事件开始信号和delta.content.type=thinking的增量片段。include_tool_calls=false会过滤工具调用事件和旧版工具输入/输出 delta。