GET /v1/sessions/{session_id}/threads/{thread_id}/stream
通过 Server-Sent Events (SSE) 实时接收指定 Session Thread 中的事件。连接建立后,服务端会推送该线程的完整事件历史,并在有新事件产生时继续推送。仅推送属于该线程的事件。
请求头
| 头部 | 必选 | 说明 |
|---|---|---|
Authorization | 是 | Bearer <PAT> |
Accept | 推荐 | text/event-stream |
Last-Event-ID | 否 | 从该事件 ID 之后继续推送。该 ID 必须属于当前线程 |
路径参数
| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
session_id | string | 是 | Session ID(sess_ 前缀) |
thread_id | string | 是 | Thread ID(sthr_ 前缀) |
查询参数
| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
type | string | 否 | 按事件类型过滤。支持逗号分隔多值 |
types[] | string | 否 | type 的数组写法替代方案 |
示例请求
示例响应
HTTP 200 OKContent-Type: text/event-stream
每个事件遵循 SSE 标准格式。所有事件都包含 session_thread_id 字段:
子线程创建:
线程事件类型
除了 Session 级别的通用事件类型外,线程维度新增以下事件类型:| event (SSE field) | 说明 |
|---|---|
session.thread_created | 新子线程被创建。包含 parent_thread_id、agent_id、agent_version、agent_name、role、created_by_tool_use_id |
session.thread_status_running | 线程开始执行。包含 agent_name、status |
session.thread_status_idle | 线程回到空闲。包含 status、stop_reason |
session.thread_status_terminated | 线程被归档或终止。包含 status、stop_reason |
agent.thread_message_sent | 线程间发送消息。包含 direction、content、from_session_thread_id、to_session_thread_id |
agent.thread_message_received | 线程间接收消息。包含 direction、content、is_error、from_session_thread_id、to_session_thread_id |
session_thread_id 字段。Session 级事件流(/sessions/{id}/events/stream)会包含所有线程的事件;线程级事件流仅包含指定线程的事件。
错误码
| HTTP | type | 触发条件 |
|---|---|---|
| 400 | invalid_request_error | Last-Event-ID 不属于该线程 |
| 401 | authentication_error | PAT 无效或过期 |
| 404 | not_found_error | Session 或 Thread 不存在 |
相关
Managed Agents
了解线程事件在多 Agent 协作中的语义。
列出线程事件
分页拉取线程的历史事件。
列出 Session Threads
查看 Session 中的所有线程。