Skip to content

获取历史消息

接口说明

获取用户的对话历史。

请求信息

  • Method: GET
  • Path: /v1/conversations/messages
  • 认证: 需要

查询参数

参数类型必填默认值说明
limitint20返回消息数量,最大100
offsetint0偏移量,用于分页

响应示例

json
{
  "code": 0,
  "message": "success",
  "data": {
    "messages": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "role": "user",
        "content": "你好",
        "timestamp": "2025-10-03T12:30:00Z"
      },
      {
        "id": "550e8400-e29b-41d4-a716-446655440001",
        "role": "assistant",
        "content": "你好呀!很高兴见到你~",
        "timestamp": "2025-10-03T12:30:01Z"
      }
    ],
    "total": 42,
    "has_more": true
  }
}

错误情况

  • 401: 未认证
  • 400: 参数错误

示例代码

bash
curl -X GET "http://localhost:8081/v1/conversations/messages?limit=20&offset=0" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
javascript
const response = await fetch(
  'http://localhost:8081/v1/conversations/messages?limit=20&offset=0',
  {
    headers: {
      'Authorization': `Bearer ${accessToken}`
    }
  }
);

const data = await response.json();
console.log(data.data.messages);
python
import requests

response = requests.get(
    'http://localhost:8081/v1/conversations/messages',
    headers={
        'Authorization': f'Bearer {access_token}'
    },
    params={
        'limit': 20,
        'offset': 0
    }
)

data = response.json()
print(data['data']['messages'])

Released under the MIT License.