日志管理
日志接口用于查询和管理 API 调用日志。
接口地址
GET https://ai-tokenhub.com/v1/admin/logs
GET https://ai-tokenhub.com/v1/admin/logs/{id}查询参数
| 参数 | 类型 | 说明 |
|---|---|---|
| start_time | string | 开始时间 (ISO 8601) |
| end_time | string | 结束时间 (ISO 8601) |
| api_key_id | string | API Key ID |
| model | string | 模型名称 |
| status | string | 状态 (success/error) |
| page | integer | 页码 |
| page_size | integer | 每页数量 (最大100) |
获取日志列表
bash
curl "https://ai-tokenhub.com/v1/admin/logs?page=1&page_size=50" \
-H "Authorization: Bearer YOUR_API_KEY"响应示例
json
{
"object": "list",
"data": [
{
"id": "log_xxx",
"api_key_id": "key_xxx",
"api_key_name": "Production Key",
"model": "gpt-4o",
"request_tokens": 100,
"response_tokens": 50,
"status": "success",
"latency": 1200,
"ip": "203.0.113.1",
"created_at": "2024-01-01T12:00:00Z"
}
],
"meta": {
"total": 1000,
"page": 1,
"page_size": 50,
"total_pages": 20
}
}获取单条日志详情
bash
curl https://ai-tokenhub.com/v1/admin/logs/log_xxx \
-H "Authorization: Bearer YOUR_API_KEY"日志详情
json
{
"id": "log_xxx",
"api_key_id": "key_xxx",
"model": "gpt-4o",
"request": {
"messages": [...],
"temperature": 0.7,
"max_tokens": 1000
},
"response": {
"choices": [...],
"usage": {
"prompt_tokens": 100,
"completion_tokens": 50,
"total_tokens": 150
}
},
"status": "success",
"error_code": null,
"error_message": null,
"latency": 1200,
"ip": "203.0.113.1",
"user_agent": "Mozilla/5.0...",
"created_at": "2024-01-01T12:00:00Z"
}字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 日志唯一标识 |
| api_key_id | string | 使用的 API Key ID |
| api_key_name | string | API Key 名称 |
| model | string | 调用的模型 |
| request_tokens | integer | 请求 token 数 |
| response_tokens | integer | 响应 token 数 |
| status | string | 调用状态 |
| latency | integer | 延迟 (毫秒) |
| ip | string | 请求来源 IP |