GET /sessions/{sid}/messages

获取指定会话的消息列表。

GET /cells/{cellID}/sessions/{sid}/messages

路径参数

参数类型说明
cellIDstringCell ID
sidstring会话 ID

查询参数

参数类型必填默认值说明
beforestring否—消息 ID,返回此消息之前的消息(向前翻页)
limitinteger否50每页返回条数,范围 1–200

curl 示例

curl -s "http://localhost:9091/cells/dept-legal/sessions/ses-a1b2c3d4/messages?limit=20" \
  -H "Authorization: Bearer $TOKEN" | jq .

向前翻页(获取更早的消息):

curl -s "http://localhost:9091/cells/dept-legal/sessions/ses-a1b2c3d4/messages?before=msg-001&limit=20" \
  -H "Authorization: Bearer $TOKEN" | jq .

响应

200 OK

{
  "messages": [
    {
      "id": "msg-001",
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "请审查这份合同的违约条款"
        }
      ],
      "turn_num": 1,
      "created_at": "2026-09-20T10:30:00Z",
      "tool_calls": null
    },
    {
      "id": "msg-002",
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "我来审查这份合同的违约条款。让我先读取文件内容。"
        }
      ],
      "turn_num": 1,
      "created_at": "2026-09-20T10:30:05Z",
      "tool_calls": [
        {
          "id": "call-abc123",
          "name": "read",
          "arguments": "{\"path\": \"/workspace/contract.pdf\"}"
        }
      ]
    },
    {
      "id": "msg-003",
      "role": "tool",
      "content": [
        {
          "type": "text",
          "text": "{\"content\": \"甲方违约责任:...\"}"
        }
      ],
      "turn_num": 1,
      "created_at": "2026-09-20T10:30:06Z",
      "tool_calls": null
    }
  ]
}

消息对象字段说明:

字段类型说明
idstring消息唯一标识
rolestring角色:user / assistant / tool / system
contentContentBlock[]消息内容块数组(含 text / image / file_ref 等类型)
turn_numinteger轮次编号
created_atstring创建时间(RFC 3339)
tool_callsobject[] | null工具调用列表(仅 assistant 消息可能携带)

错误码

HTTP错误说明
401—未认证或 Token 无效
403—无权访问该会话(Actor 不匹配)
404—Cell 或会话不存在

相关端点