获取单个会话的完整历史
返回会话元数据、按时间排序的消息以及尚未回答的问题。
GET /v1/sessions/:id
这是主要的历史读取接口:返回会话元数据、按时间顺序持久化的全部消息,以及会话中仍处于打开状态的交互队列问题。客户端先据此渲染历史;若 is_streaming 为 true,再订阅以该会话 ID 为键的 WebSocket chat 频道以跟随实时轮次。
| 方法 | GET |
| 路径 | /v1/sessions/:id |
| 认证 | 设置 GATEWAY_AUTH_TOKEN 时需要 Authorization: Bearer <token> |
| 类别 | sessions |
响应体
{ "id": "chat_abc", "title": "BTC analysis", "origin": "web", "kind": "chat", "created_at_ms": 1747000000000, "updated_at_ms": 1747000500000, "message_count": 2, "has_unseen_completion": true, "completion_settled_at_ms": 1747000500000, "messages": [ { "id": 1, "role": "user", "content": "analyze BTC", "ts_ms": 1747000000000, "metadata": null }, { "id": 2, "role": "assistant", "content": "…", "ts_ms": 1747000400000, "metadata": { "segments": [ { "kind": "text", "text": "…" }, { "kind": "tool", "toolId": "call_1" } ], "toolCalls": [ { "id": "call_1", "name": "get_quote", "args": { "symbol": "BTC" }, "ok": true, "result": "…", "duration_ms": 812 } ] } } ], "is_streaming": false, "pending_questions": [] }说明
metadata 的结构取决于消息角色。Assistant 行包含有序渲染计划 segments、按 toolId 引用的 toolCalls,并可在轮次提前停止时包含 interrupted: true。User 行可包含 attachments、用于轮次中途引导的 interjection: true 以及语音输入键。旧消息可能为 metadata: null,此时将 content 按普通 Markdown 渲染。pending_questions 与 pending_question_added 流事件结构一致,可通过 POST /v1/interactions/:id/answer 回答。未知 ID 返回 404。
响应还包含 has_unseen_completion,表示最新完成或失败的 Agent 任务结果尚未查看。completion_settled_at_ms 标识该状态对应的完成结果,防止旧读取恢复已确认的结果。