> ## 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.

# Thread 事件流

> 流式读取指定 Session thread 的事件。

`GET /api/v1/cloud/sessions/{session_id}/threads/{thread_id}/stream`

以 Server-Sent Events 流式返回一个 thread 的公开事件。

## 路径参数

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

## 请求头

| 头部              | 必选 | 说明                                                              |
| --------------- | -- | --------------------------------------------------------------- |
| `Authorization` | 是  | `Bearer $QODER_PAT`                                             |
| `Accept`        | 否  | 使用 `text/event-stream`                                          |
| `Last-Event-ID` | 否  | 提供后从该事件 ID 之后续传。事件 ID 不存在、已被归档、指向非公开内部事件，或不属于该 thread 时返回 `400` |

## 示例请求

```bash theme={null}
curl -N -X GET "https://api.qoder.com/api/v1/cloud/sessions/sess_019f00000000000000000000000000aa/threads/sthr_019f00000000000000000000000002bb/stream" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Accept: text/event-stream"
```

## 流格式

```text theme={null}
id: evt_019f00000000000000000000000003cc
event: agent.message
data: {"id":"evt_019f00000000000000000000000003cc","type":"agent.message","content":[{"type":"text","text":"Thread response"}],"processed_at":"2026-06-15T08:02:00.000Z"}

id: evt_c3d4e5f6a7b8c9d0
event: session.thread_status_idle
data: {"agent_name":"my-agent","id":"evt_c3d4e5f6a7b8c9d0","processed_at":"2026-06-15T08:02:01.000Z","session_thread_id":"sthr_019f00000000000000000000000002bb","stop_reason":{"type":"end_turn"},"type":"session.thread_status_idle"}
```

服务端会定期发送 `: heartbeat` 注释行以保持连接活跃。

## 错误码

| HTTP | 类型                      | 触发条件                                                                            |
| ---- | ----------------------- | ------------------------------------------------------------------------------- |
| 400  | `invalid_request_error` | `Last-Event-ID` 未能识别该 Session/thread 中的有效公开事件（事件不存在、已被归档、为非公开内部事件，或不属于该 thread） |
| 401  | `authentication_error`  | PAT 无效或过期                                                                       |
| 404  | `not_found_error`       | Session 或 thread 不存在                                                            |

**HTTP 404 Not Found**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "not_found_error",
    "message": "Session thread 'sthr_fakefakefake_xxxxxxxxxxxxxxxx' was not found."
  },
  "request_id": "b5822072-f264-48da-9d61-6d48ffb07551"
}
```

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

## 相关

<CardGroup cols={2}>
  <Card title="Managed Agents" icon="user-gear" href="/zh/cloud-agents/managed-agents">
    了解线程事件在多 Agent 协作中的语义。
  </Card>

  <Card title="列出线程事件" icon="list" href="/zh/cloud-agents/api/sessions/list-thread-events">
    分页拉取线程的历史事件。
  </Card>

  <Card title="列出 Session Threads" icon="layer-group" href="/zh/cloud-agents/api/sessions/list-threads">
    查看 Session 中的所有线程。
  </Card>
</CardGroup>
