获取会话历史消息
适用于:Chatflow、Agent、聊天助手、旧版 Agent。
返回会话的消息历史,按时间倒序(最新在前)。传入 first_id 可向前翻页获取更早的消息。
1 min read
get/messages
Request example
curl --request GET \
--url https://api.dify.ai/v1/messages \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.dify.ai/v1/messages"
headers = {
"Authorization": "Bearer <token>",
}
response = requests.request("GET", url, headers=headers)
print(response.text)const response = await fetch('https://api.dify.ai/v1/messages', {
method: 'GET',
headers: {
'Authorization': 'Bearer <token>'
}
});
const data = await response.json();
console.log(data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.dify.ai/v1/messages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer <token>',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;package main
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api.dify.ai/v1/messages"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dify.ai/v1/messages"))
.header("Authorization", "Bearer <token>")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require 'uri'
require 'net/http'
url = URI('https://api.dify.ai/v1/messages')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTP::Get.new(url)
request['Authorization'] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyResponse
{
"data": [
{
"agent_thoughts": [],
"answer": "iPhone 13 Pro Max specs are listed here:...",
"answer_tokens": 58,
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"created_at": 1705407629,
"currency": "USD",
"error": null,
"extra_contents": [],
"feedback": {
"rating": "like"
},
"id": "9da23599-e713-473b-982c-4328d4f5c78a",
"inputs": {
"city": "San Francisco"
},
"message_files": [],
"message_tokens": 100,
"parent_message_id": null,
"provider_response_latency": 1.234,
"query": "What are the specs of the iPhone 13 Pro Max?",
"retriever_resources": [],
"status": "normal",
"total_price": "0.0012825",
"total_tokens": 158
}
],
"has_more": false,
"limit": 20
}{
"code": "not_chat_app",
"message": "Please check if your app mode matches the right API route.",
"status": 400
}{
"code": "not_found",
"message": "Conversation Not Exists.",
"status": 404
}{
"code": "not_found",
"message": "First Message Not Exists.",
"status": 404
}get/messages
Authorization
Query parameters
分页游标:当前页第一条消息的
id。传入它可获取上一页(更早的消息);省略则获取最新消息。Responses
application/json
成功获取会话历史。
消息列表。
Show child attributesHide child attributes
该消息的 Agent 思考。
Show child attributesHide child attributes
助手回答文本。
生成回答的 token 数量。
会话 ID。
创建时间戳(Unix 纪元秒)。
total_price 的货币单位(例如 USD),无定价信息时为 null。当
status 为 error 时的错误消息。与此消息关联的附加执行内容,例如 Chatflow 工作流中人工介入节点的表单数据。
Show child attributesHide child attributes
由人工介入节点渲染的人工介入表单定义。
Show child attributesHide child attributes
表单上可用的操作按钮。
表单是否应在 UI 中显示。
表单过期的 Unix 时间戳。
与表单一起显示的 Markdown 或文本内容。
表单唯一标识符。
表单提交认证的令牌。
表单中的输入字段。
Show child attributesHide child attributes
表单输入的默认值配置。
存储输入值的变量名称。
表单输入控件类型。可用值:
paragraph(多行文本输入)、select(从列表中单选)、file(单文件上传)和 file-list(多文件上传)。生成该表单的人工介入节点 ID。
人工介入节点的标题。
表单输入的已解析默认值,按输出变量名称索引。
来自已提交的人工介入表单的数据。
人工介入表单是否已提交。
human_input 表示人工介入内容。该内容所属的工作流运行 ID。
该消息的用户反馈。
Show child attributesHide child attributes
反馈评分。
like 为正面,dislike 为负面。消息 ID。
该消息的输入变量。
附加到该消息的文件。
Show child attributesHide child attributes
该文件的所属者。用户上传的文件为
user,助手生成的文件为 assistant。原始文件名。
File ID.
文件的 MIME 类型。
文件大小(字节)。
使用的传输方式。
remote_url 表示基于 URL 的文件,local_file 表示已上传的文件,tool_file 表示工具生成的文件。文件类型,例如
image。通过
local_file 传输时的上传文件 ID。文件的预览 URL。
输入消息的 token 数量。
线程会话的父消息 ID。
模型供应商的响应延迟,单位为秒。
用户查询文本。
该消息使用的检索资源。
Show child attributesHide child attributes
资源的内容片段。
创建时间戳(Unix 纪元秒)。
数据源类型。
知识库 ID。
知识库名称。
文档 ID。
文档名称。
该块被命中的次数。
检索资源的唯一 ID。
索引节点的哈希值。
该资源所属消息的 ID。
资源在列表中的位置。
资源的相关性评分。
文档中特定块的 ID。
块在文档中的位置。
块内容的摘要。
块的字数。
消息状态。成功消息为
normal,生成失败时为 error。所用 token 的总价,无定价信息时为
null。使用的 token 总数,即
message_tokens 与 answer_tokens 之和。是否有更多消息。
每页条目数。