通过 Server-Sent Events 流式订阅指定 Forward Session Thread 的公开 Event。
GET /api/v1/forward/sessions/{session_id}/threads/{thread_id}/stream
请求参数
| 位置 | 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|---|
| Header | Authorization | string | 是 | Bearer <PAT 或 SAT> |
| Header | Accept | string | 否 | 建议使用 text/event-stream;省略时仍可建立连接。 |
| Header | Last-Event-ID | string | 否 | 从该 Thread Event 之后继续订阅。 |
| Path | session_id | string | 是 | sess_ 前缀的 Session ID。 |
| Path | thread_id | string | 是 | sthr_ 前缀的 Thread ID。 |
type、types、types[]、include_tool_calls、include_thinking 或 event_deltas[]。即使这些参数的值为空,也会返回 400 invalid_request,且不会建立下游流。
示例请求
流格式
: heartbeat 注释行以保持连接。客户端应消费全部 frame、在本地做展示过滤,并持续保存最后收到的 SSE id 用于重连。
Last-Event-ID
Last-Event-ID 必须属于当前 Thread:
- 游标属于其他 Session 或 Thread 时,返回
404 thread_not_found。 - 运行时明确判定它是当前 Thread 的非法 Event cursor 时,返回
400 invalid_event_cursor。 - 省略该 Header 时,从该 Thread 的第一条 Event 开始回放;不会遗漏事件,但会重复收到已消费的 Event,请基于 Event ID 做幂等消费。
- SSE 连接可能因网关超时、服务端重启等原因断开,服务端不保证连接长期存活;客户端必须自行实现重连重试,重连时携带最后收到的 Event ID 作为
Last-Event-ID,从断点继续订阅。
错误
| HTTP | Type | Code | 触发条件 |
|---|---|---|---|
| 400 | invalid_request | invalid_request | 传入该接口不支持的 selector。 |
| 400 | invalid_request_error | invalid_event_cursor | Last-Event-ID 是当前 Thread 的非法 Event cursor。 |
| 401 | authentication_error | authentication_required | PAT 或 SAT 无效或已过期。 |
| 404 | not_found | session_not_found | Session 不存在或当前调用方不可见。 |
| 404 | not_found_error | thread_not_found | Thread 不存在、不属于该 Session,或 cursor 指向其他 Session/Thread。 |
| 502 | api_error | runtime_unavailable | Thread 运行服务暂时不可用。 |
Thread 发现与恢复
父 Session history/stream 会通过以下 lifecycle Event 暴露 child Thread 的创建和状态变化:session.thread_created、session.thread_status_running、session.thread_status_idle、session.thread_status_rescheduled、session.thread_status_terminated。
从父 Session stream 收到 session.thread_created 后,可将该 Event 的 ID 作为 child Thread stream 的首个 Last-Event-ID,避免遗漏发现 Thread 到建立连接之间产生的 Event。
如果通过 Thread 列表发现已经活跃的 child Thread,请先读取 Thread Event 历史,再使用响应中的 last_id 建立 stream。Thread 归档后不能新建或恢复 child Thread stream;请改用父 Session history/stream 恢复 lifecycle Event,并通过获取 Thread 接口读取最终状态。