获取会话历史消息
curl --request GET \
--url https://{deployed_api_base_url}/v2/messages \
--header 'Authorization: Bearer <token>'import requests
url = "https://{deployed_api_base_url}/v2/messages"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://{deployed_api_base_url}/v2/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{deployed_api_base_url}/v2/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://{deployed_api_base_url}/v2/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))
}HttpResponse<String> response = Unirest.get("https://{deployed_api_base_url}/v2/messages")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://{deployed_api_base_url}/v2/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"limit": 20,
"has_more": false,
"data": [
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"conversation_id": "0f8fad5b-d9cb-469f-a165-70867728950e",
"parent_message_id": "00000000-0000-0000-0000-000000000000",
"inputs": {
"order_id": "ORDER-1001"
},
"query": "Where is my refund now?",
"answer": "Your refund is being processed by the bank.",
"feedback": null,
"retriever_resources": [],
"created_at": 1787788860,
"agent_thoughts": [],
"message_files": [
{
"id": "a8098c1a-f86e-51da-bd1e-66d42f3f323a",
"filename": "receipt.pdf",
"type": "document",
"url": "/v2/files/16fd2706-8baf-433b-82eb-8c7fada847da/preview?user=customer-001",
"mime_type": "application/pdf",
"size": 48231,
"transfer_method": "local_file",
"belongs_to": "user",
"upload_file_id": "16fd2706-8baf-433b-82eb-8c7fada847da"
}
],
"message_tokens": 28,
"answer_tokens": 19,
"total_tokens": 47,
"provider_response_latency": 0,
"total_price": "0.0012",
"currency": "USD",
"status": "normal",
"error": null,
"extra_contents": []
}
]
}部署环境
获取会话历史消息
适用于:Chatflow。
以滚动加载的方式返回会话的历史消息。不传 first_id 时,返回最新的 limit 条消息,按时间正序排列;传入 first_id 时,返回它之前的消息。
对应的标准 API 接口:获取会话历史消息。差异:
user为必填。- 以下响应字段的取值固定:
feedback始终为null。retriever_resources始终为空。agent_thoughts始终为空。parent_message_id始终是全零 UUID。
- 错误码不同。
GET
/
v2
/
messages
获取会话历史消息
curl --request GET \
--url https://{deployed_api_base_url}/v2/messages \
--header 'Authorization: Bearer <token>'import requests
url = "https://{deployed_api_base_url}/v2/messages"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://{deployed_api_base_url}/v2/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{deployed_api_base_url}/v2/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://{deployed_api_base_url}/v2/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))
}HttpResponse<String> response = Unirest.get("https://{deployed_api_base_url}/v2/messages")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://{deployed_api_base_url}/v2/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"limit": 20,
"has_more": false,
"data": [
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"conversation_id": "0f8fad5b-d9cb-469f-a165-70867728950e",
"parent_message_id": "00000000-0000-0000-0000-000000000000",
"inputs": {
"order_id": "ORDER-1001"
},
"query": "Where is my refund now?",
"answer": "Your refund is being processed by the bank.",
"feedback": null,
"retriever_resources": [],
"created_at": 1787788860,
"agent_thoughts": [],
"message_files": [
{
"id": "a8098c1a-f86e-51da-bd1e-66d42f3f323a",
"filename": "receipt.pdf",
"type": "document",
"url": "/v2/files/16fd2706-8baf-433b-82eb-8c7fada847da/preview?user=customer-001",
"mime_type": "application/pdf",
"size": 48231,
"transfer_method": "local_file",
"belongs_to": "user",
"upload_file_id": "16fd2706-8baf-433b-82eb-8c7fada847da"
}
],
"message_tokens": 28,
"answer_tokens": 19,
"total_tokens": 47,
"provider_response_latency": 0,
"total_price": "0.0012",
"currency": "USD",
"status": "normal",
"error": null,
"extra_contents": []
}
]
}授权
查询参数
分页游标:当前页第一条消息的 id。传入它可获取上一页(更早的消息);省略则获取最新消息。
每次请求返回的聊天历史消息数量。
必填范围:
1 <= x <= 100