对话消息
发送对话消息
适用于:Chatflow、Agent、聊天助手、旧版 Agent。
向对话型应用发送一条消息并返回助手的回复。流式响应中的事件因应用类型而异。
POST
/
chat-messages
curl --request POST \
--url https://{api_base_url}/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"inputs": {},
"query": "What are the specs of the iPhone 13 Pro Max?",
"response_mode": "blocking",
"user": "abc-123"
}
'{
"answer": "iPhone 13 Pro Max specs are listed here:...",
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"created_at": 1705407629,
"event": "message",
"id": "b01a39de-3480-4f3e-9f1e-4841a80f8e5e",
"message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
"metadata": {
"retriever_resources": [
{
"content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\" \"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\"",
"dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
"dataset_name": "iPhone",
"document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
"document_name": "iPhone List",
"position": 1,
"score": 0.98457545,
"segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a"
}
],
"usage": {
"completion_price": "0.0002560",
"completion_price_unit": "0.001",
"completion_tokens": 128,
"completion_unit_price": "0.002",
"currency": "USD",
"latency": 0.7682376249867957,
"prompt_price": "0.0010330",
"prompt_price_unit": "0.001",
"prompt_tokens": 1033,
"prompt_unit_price": "0.001",
"total_price": "0.0012890",
"total_tokens": 1161
}
},
"mode": "chat",
"task_id": "c3800678-a077-43df-a102-53f23ed20b88"
}Authorizations
Body
application/json
发送对话消息的请求体。
用户发送的消息。
响应返回模式。省略时默认为阻塞模式。
streaming(推荐):回复以 Server-Sent Events 形式返回。blocking:生成完成后一次性返回。生成时间较长时有中断风险:在 Dify Cloud 上,如果边缘代理在超时时间内未收到响应,就可能中断连接。- 旧版 Agent 和 Agent 应用仅支持
streaming;使用blocking会返回 400。
Available options:
streaming, blocking 仅适用于 Chatflow 应用。 指定要执行的已发布工作流版本 ID。如果未提供,将使用最新发布的版本。在 Dify Cloud 上,指定版本需要付费套餐。
Response
请求成功。内容类型和结构取决于请求中的 response_mode 参数。
- 如果
response_mode为blocking,返回application/json和ChatCompletionResponse对象。 - 如果
response_mode为streaming,返回text/event-stream和服务器发送事件流。
完整的响应内容。
会话 ID。
消息创建时间戳(Unix 纪元秒)。
事件类型,固定为 message。
该响应事件的唯一 ID。
唯一的消息 ID。调用反馈或推荐问题接口时,将此值作为 message_id 参数使用。
包含用量和检索资源的元数据。
Show child attributes
Show child attributes
应用模式。chat 表示聊天助手应用,agent-chat 表示旧版 Agent 应用,advanced-chat 表示 Chatflow 应用。
用于请求追踪和停止响应 API 的任务 ID。
Last modified on September 30, 2026
Was this page helpful?
⌘I
curl --request POST \
--url https://{api_base_url}/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"inputs": {},
"query": "What are the specs of the iPhone 13 Pro Max?",
"response_mode": "blocking",
"user": "abc-123"
}
'{
"answer": "iPhone 13 Pro Max specs are listed here:...",
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"created_at": 1705407629,
"event": "message",
"id": "b01a39de-3480-4f3e-9f1e-4841a80f8e5e",
"message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
"metadata": {
"retriever_resources": [
{
"content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\" \"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\"",
"dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
"dataset_name": "iPhone",
"document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
"document_name": "iPhone List",
"position": 1,
"score": 0.98457545,
"segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a"
}
],
"usage": {
"completion_price": "0.0002560",
"completion_price_unit": "0.001",
"completion_tokens": 128,
"completion_unit_price": "0.002",
"currency": "USD",
"latency": 0.7682376249867957,
"prompt_price": "0.0010330",
"prompt_price_unit": "0.001",
"prompt_tokens": 1033,
"prompt_unit_price": "0.001",
"total_price": "0.0012890",
"total_tokens": 1161
}
},
"mode": "chat",
"task_id": "c3800678-a077-43df-a102-53f23ed20b88"
}