流式对话恢复
更新时间:2026-04-14
POST
https://qianfan.baidubce.com/v2/app/streaming/conversation/recover
本接口用于恢复因页面切换或连接中断导致的流式输出丢失。
权限说明
调用本文API,需使用API Key鉴权方式。使用API Key鉴权调用API流程,具体调用流程,请查看认证鉴权。
请求参数
Headers 参数
除公共头域外,无其它特殊头域
Body 参数
conversation_id
string
对话ID。
必选
version
string
报告生成版本,默认为“v2”。
可选
请求结构
POST /v2/app/streaming/conversation/recover HTTP/1.1
HOST: qianfan.baidubce.com
Authorization: Bearer <API Key>
Content-Type: application/json
{
"conversation_id": "1f3b84c5-****-45bd-b9a9-2bd507457c28",
"turn_id": "d8534a1b-5d9b-****-b1ce-83bf332083dd"
}
示例代码
请求示例
curl -X POST "https://qianfan.baidubce.com/v2/app/streaming/conversation/recover" \
-H "Authorization: Bearer bce-v3/ALTAK-******ZftZDTn7/125eeb1c5e9ddc8cf3edf18ef6d03f1517ec9408" \
-H "Content-Type: application/json" \
-d '{
"conversation_id": "1f3b84c5-****-45bd-b9a9-2bd507457c28",
"turn_id": "d8534a1b-5d9b-****-b1ce-83bf332083dd"
}'
返回响应
Headers 参数
除公共头域外,无其它特殊头域
返回参数
role
string
当前消息的发送者角色。
可选
status
string
当前消息的传输状态。
可选
message_id
string
消息 ID。同一轮对话中所有流式片段共享同一个 message_id。
可选
conversation_id
string
对话 ID。
可选
trace_id
string
追踪 ID,用于链路追踪。
可选
user_id
string
用户 ID。
可选
end_user_id
string
终端用户 ID。
可选
content
array
内容片段列表。每条流式事件包含一个或零个片段。
可选
显示子属性
隐藏子属性
items
object {9}
显示子属性
隐藏子属性
type
string
内容片段类型。
可选
name
string
内容业务标识名称。
可选
visible_scope
string
内容可见范围。
可选
text
object {0}
具体文本内容。结构因 type 不同而不同。
可选
显示子属性
隐藏子属性
暂无参数
event
object {3}
事件元数据。
可选
显示子属性
隐藏子属性
id
string
事件 ID。
可选
name
string
事件名称。
可选
status
string
事件执行状态。
可选
render
object {2}
渲染信息。
可选
显示子属性
隐藏子属性
answer
string
回答文本。
可选
component_detail
object {6}
组件详情。
可选
显示子属性
隐藏子属性
is_workflow
boolean
是否为工作流组件。
可选
name
string
组件英文名。
可选
name_cn
string
组件中文名。
可选
thought
string
模型在调用该组件前的思考过程文本。
可选
path
array
事件调用链路。
可选
显示子属性
隐藏子属性
items
object {2}
显示子属性
隐藏子属性
event_id
string
当前节点的事件 ID。
可选
parents_id
array
父节点的事件 ID 列表。
可选
显示子属性
隐藏子属性
items
string
arguments
object {2}
工具调用的入参。
可选
显示子属性
隐藏子属性
upload_files_selected
array
用户上传的文件列表。
可选
显示子属性
隐藏子属性
items
string
upstream_files_selected
array
上游节点输出的文件列表。
可选
显示子属性
隐藏子属性
items
string
metrics
object {2}
性能指标,记录节点执行的时间信息。
可选
显示子属性
隐藏子属性
begin_time_stamp
number
节点开始执行的时间戳(Unix 时间戳,精确到毫秒级浮点数)。
可选
current_time_stamp
number
当前片段生成时的时间戳(Unix 时间戳,精确到毫秒级浮点数)。
可选
usage
object {5}
Token 消耗信息。
可选
显示子属性
隐藏子属性
type
string
调用类型。如 chat。
可选
name
string
使用的模型名称。如 deepseek-v3.1-250821。
可选
prompt_tokens
integer
输入 Token 数量。
可选
completion_tokens
integer
输出 Token 数量。
可选
total_tokens
integer
总 Token 数量。
可选
raw_data
object {2}
原始数据。不同节点类型下结构不同。
可选
显示子属性
隐藏子属性
event_status
string
工具执行状态标识。
可选
completion_details
object {3}
补充详情。
可选
显示子属性
隐藏子属性
flag
integer
标志位。
可选
ban_round
object
封禁轮次信息。
可选
显示子属性
隐藏子属性
need_clear_history
object
是否需要清除历史记录。
可选
显示子属性
隐藏子属性
JSON
data: {"role": "assistant", "status": "running", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": [{"type": "text", "name": "text", "visible_scope": "", "text": {"info": "用户要求生成包含文本'Hello AI'的二维码图片"}, "event": {"id": "1", "name": "/thought/thought_agent", "status": "running"}, "render": {"component_detail": {"is_workflow": false, "name": "ThoughtAgent", "thought": "", "path": [{"event_id": "1", "parents_id": []}]}}, "metrics": {"begin_time_stamp": 1776066011.542, "current_time_stamp": 1776066012.701}, "usage": {}, "raw_data": {}}]}
data: {"role": "tool", "status": "running", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": [{"type": "text", "name": "/toolcall/code_interpreter_general", "visible_scope": "", "text": {"info": ""}, "event": {"id": "2", "name": "/toolcall/code_interpreter_general", "status": "preparing"}, "render": {"component_detail": {"is_workflow": false, "name": "CodeInterpreterGeneral", "name_cn": "代码解释器Agent", "thought": "用户要求生成包含文本'Hello AI'的二维码图片", "path": [{"event_id": "2", "parents_id": ["1"]}], "arguments": {"upload_files_selected": [], "upstream_files_selected": []}}}, "metrics": {"begin_time_stamp": 1776066016.347, "current_time_stamp": 1776066016.348}, "usage": {}, "raw_data": {}}]}
data: {"role": "tool", "status": "running", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": [{"type": "code", "name": "code", "visible_scope": "user", "text": {"code": "print(\"[拒绝回答]:当前环境中未安装所需的第三方库\")\n"}, "event": {"id": "2", "name": "/toolcall/code_interpreter_general", "status": "running"}, "render": {"component_detail": {"is_workflow": false, "name": "CodeInterpreterGeneral", "name_cn": "代码解释器Agent", "thought": "用户要求生成包含文本'Hello AI'的二维码图片", "path": [{"event_id": "2", "parents_id": ["1"]}], "arguments": {"upload_files_selected": [], "upstream_files_selected": []}}}, "metrics": {"begin_time_stamp": 1776066016.347, "current_time_stamp": 1776066018.350}, "usage": {}, "raw_data": {"event_status": "done"}}]}
data: {"role": "tool", "status": "running", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": [{"type": "text", "name": "", "visible_scope": "llm", "text": {"info": "\n代码的执行结果如下:\n[拒绝回答]:当前环境中未安装所需的第三方库"}, "event": {"id": "2", "name": "/toolcall/code_interpreter_general", "status": "running"}, "render": {"component_detail": {"is_workflow": false, "name": "CodeInterpreterGeneral", "name_cn": "代码解释器Agent", "thought": "", "path": [{"event_id": "2", "parents_id": ["1"]}], "arguments": {"upload_files_selected": [], "upstream_files_selected": []}}}, "metrics": {"begin_time_stamp": 1776066016.347, "current_time_stamp": 1776066019.715}, "usage": {}, "raw_data": {}}]}
data: {"role": "tool", "status": "running", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": [{"type": "text", "name": "/toolcall/code_interpreter_general", "visible_scope": "", "text": {"info": ""}, "event": {"id": "2", "name": "/toolcall/code_interpreter_general", "status": "done"}, "render": {"component_detail": {"is_workflow": false, "name": "CodeInterpreterGeneral", "name_cn": "代码解释器Agent", "thought": "", "path": [{"event_id": "2", "parents_id": ["1"]}], "arguments": {"upload_files_selected": [], "upstream_files_selected": []}}}, "metrics": {"begin_time_stamp": 1776066016.347, "current_time_stamp": 1776066019.721}, "usage": {}, "raw_data": {}}]}
data: {"role": "assistant", "status": "running", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": [{"type": "text", "name": "content", "visible_scope": "all", "text": {"info": "很抱歉,由于当前环境限制,我无法直接生成二维码图片。"}, "event": {"id": "6", "name": "/chat/chat_agent", "status": "running"}, "render": {"answer": "很抱歉,由于当前环境限制,我无法直接生成二维码图片。", "component_detail": {"is_workflow": false, "name": "ChatAgent", "thought": "", "path": [{"event_id": "6", "parents_id": ["5"]}]}}, "metrics": {"begin_time_stamp": 1776066028.702, "current_time_stamp": 1776066029.601}, "usage": {"type": "chat", "name": "deepseek-v3.1-250821", "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0}, "raw_data": {"completion_details": {"flag": 0, "ban_round": null, "need_clear_history": null}}}]}
data: {"role": "assistant", "status": "running", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": [{"type": "text", "name": "content", "visible_scope": "all", "text": {"info": ""}, "event": {"id": "6", "name": "/chat/chat_agent", "status": "running"}, "render": {"answer": "", "component_detail": {"is_workflow": false, "name": "ChatAgent", "thought": "", "path": [{"event_id": "6", "parents_id": ["5"]}]}}, "metrics": {"begin_time_stamp": 1776066028.702, "current_time_stamp": 1776066038.137}, "usage": {"type": "chat", "name": "deepseek-v3.1-250821", "prompt_tokens": 488, "completion_tokens": 249, "total_tokens": 737}, "raw_data": {"completion_details": {"flag": 0, "ban_round": null, "need_clear_history": null}}}]}
data: {"role": "tool", "status": "done", "message_id": "27f1cc60-a9bd-46e2-ac21-4a838a6ae4fb", "conversation_id": "ce7e7280-0b29-40e2-a2a7-2d8f67ffc4b4", "trace_id": "3161c512-cef7-4002-a6d9-4d9fdf53d93d", "user_id": "47996032-9ed5-4a9c-adaa-0dc1409ec54f", "end_user_id": "", "content": []}
评价此篇文章
