TokenAgents / API Docs
聊天请求
向站内聊天系统提交一条用户消息,并返回流式助手响应。
POST
/api/chatChat API聊天请求
向站内聊天系统提交一条用户消息,并返回流式助手响应。
鉴权方式
需要登录态 Cookie,会校验 chatId 与当前用户。
调试方式
所有页面都提供 shell curl 模板,方便你直接复制联调。
适配模型
当前页已关联 4 个模型目录,和前端实际可选模型保持同步。
请求体
当前接口支持的请求字段如下。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| chatId | string | 是 | 当前对话 ID。 |
| model | string | 是 | 模型 ID,需来自当前聊天模型列表。 |
| webSearch | boolean | 是 | 是否开启联网搜索。当前 UI 默认关闭。 |
| reasoning | boolean | 否 | 是否展示 reasoning。 |
| message | UIMessage | 是 | 用户消息对象,至少包含一段 text parts。 |
响应行为
使用当前接口时,可参考以下返回说明。
Response
HTTP 200
Content-Type: text/event-stream
返回 AI SDK 的 UI message stream,包含 assistant 消息片段、sources(如启用)和 reasoning(如启用)。关联模型
当前接口支持的模型目录。
Shell 调用示例
复制下面的 curl 模板,替换占位变量后即可联调。
curl
curl -N -X POST "{{baseUrl}}/api/chat" \
-H "Content-Type: application/json" \
-H "Cookie: {{sessionCookie}}" \
-d '{
"chatId": "{{chatId}}",
"model": "openai/gpt-5",
"webSearch": false,
"reasoning": false,
"message": {
"id": "msg_001",
"role": "user",
"parts": [
{"type": "text", "text": "Hello"}
]
}
}'调用说明
- • 会先写入用户消息,再通过 OpenRouter 发起流式请求,结束后保存 assistant 消息。