门户端接口【内部使用】6、我的作品
7.1 获取AI音频历史记录
POST
/api/audio/generation/history7.1 获取AI音频历史记录
获取AI音频历史记录
接口地址: POST /api/audio/generation/history
权限要求: 🔒 需要登录验证
请求头:
token: {token}描述: 获取当前用户的AI音频生成历史记录,支持分页查询,按创建时间降序排列
请求参数:
{ "page": 1, "page_size": 20}| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| page | int | 否 | 页码,从1开始,默认为1 |
| page_size | int | 否 | 每页条数,默认为20,最大为100 |
请求示例:
curl -X POST "https://your-domain.com/api/audio/generation/history" \ -H "token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -H "Content-Type: application/json" \ -d '{ "page": 1, "page_size": 20 }'返回数据:
{ "code": 200, "data": { "list": [ { "id": 1, "task_id": "task_abc123", "user_id": 123, "model": "tts-1", "text": "Hello, this is a test.", "voice_key": "alloy", "params_json": "{\"speed\":1.0,\"volume\":1.0}", "resolved_json": "{\"speed\":1.0,\"volume\":1.0}", "warnings_json": "[]", "status": "succeeded", "progress": 100, "stage": "completed", "audio_url": "https://example.com/audio.mp3", "storage_key": "audio/abc123.mp3", "error_message": "", "creation_id": 0, "usage_json": "{\"tokens\":1000}", "client_request_id": "client_req_123", "created_at": "2026-01-01 12:00:00", "updated_at": "2026-01-01 12:05:00" } ], "total": 100, "page": 1, "page_size": 20 }, "message": "success"}字段说明:
| 字段名 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码(200=成功) |
| message | string | 消息 |
| list | array | 音频生成记录列表 |
| total | int64 | 总记录数 |
| page | int | 当前页码 |
| page_size | int | 每页条数 |
| id | int | 生成任务ID |
| task_id | string | 任务编号 |
| user_id | int | 用户ID |
| model | string | 模型名称 |
| text | string | 要转换的文本内容 |
| voice_key | string | 音色Key |
| params_json | string | 请求参数JSON |
| resolved_json | string | 解析后的参数JSON |
| warnings_json | string | 警告信息JSON |
| status | string | 任务状态(queued/running/succeeded/failed/cancelled) |
| progress | int | 进度百分比(0-100) |
| stage | string | 当前阶段描述 |
| audio_url | string | 生成的音频URL |
| storage_key | string | 存储Key |
| error_message | string | 错误信息 |
| creation_id | int | 作品ID |
| usage_json | string | 用量信息JSON |
| client_request_id | string | 客户端请求ID |
| created_at | string | 创建时间 |
| updated_at | string | 更新时间 |
执行逻辑:
- 从请求头中获取token,验证用户身份
- 获取分页参数(page、page_size),设置默认值(page=1,page_size=20,最大100)
- 计算偏移量:offset = (page - 1) * page_size
- 分页查询audio_generations表,条件为user_id等于当前用户ID,按created_at降序排列
- 查询符合条件的总记录数
- 将查询结果转换为响应格式
- 返回包含code、data、message的响应数据
注意事项:
- 需要登录验证,请求头必须包含token
- 只能查询当前用户自己的音频生成记录
- 分页参数page从1开始,page_size最大为100
- 返回数据按创建时间降序排列,最新的记录在前