M-05-call-statistics.json
6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
"id": "M-05",
"name": "调用统计",
"fileKey": "call-statistics",
"desc": "调用统计数据的聚合存储和计算服务,支持按小时/天预聚合",
"apis": [
{
"method": "GET",
"path": "/api/v1/statistics",
"name": "统计列表",
"description": "按时间范围/模型/维度查询聚合统计数据,支持分页",
"params": [
{"name": "page", "in": "query", "type": "integer", "required": false, "desc": "页码"},
{"name": "page_size", "in": "query", "type": "integer", "required": false, "desc": "每页条数"},
{"name": "agg_dimension", "in": "query", "type": "string", "required": false, "desc": "聚合维度:hourly/daily"},
{"name": "model_name", "in": "query", "type": "string", "required": false, "desc": "按模型名称筛选"},
{"name": "account_id", "in": "query", "type": "string", "required": false, "desc": "按账号筛选"},
{"name": "biz_type", "in": "query", "type": "string", "required": false, "desc": "按业务类型筛选"},
{"name": "start_time", "in": "query", "type": "string", "required": false, "desc": "开始时间(ISO 8601)"},
{"name": "end_time", "in": "query", "type": "string", "required": false, "desc": "结束时间(ISO 8601)"}
],
"responses": [
{"code": 200, "desc": "成功", "schema": "Statistics[]"},
{"code": 400, "desc": "参数错误", "schema": ""}
],
"backend": [
{"tag": "receive", "text": "接收 GET /api/v1/statistics 请求"},
{"tag": "validate", "text": "验证请求参数"},
{"tag": "query", "text": "从数据库表按条件查询记录"},
{"tag": "return", "text": "返回分页结果"}
]
},
{
"method": "GET",
"path": "/api/v1/statistics/:id",
"name": "统计详情",
"description": "查询指定时间段的详细统计快照",
"params": [
{"name": "id", "in": "path", "type": "string", "required": true, "desc": "统计记录 ID"}
],
"responses": [
{"code": 200, "desc": "成功", "schema": "Statistics"},
{"code": 404, "desc": "记录不存在", "schema": ""}
],
"backend": [
{"tag": "receive", "text": "接收 GET /api/v1/statistics/:id 请求"},
{"tag": "validate", "text": "验证请求参数"},
{"tag": "query", "text": "从数据库表查询单条记录"},
{"tag": "return", "text": "返回操作结果"}
]
},
{
"method": "GET",
"path": "/api/v1/statistics/trends",
"name": "趋势数据",
"description": "返回时间序列趋势数据,用于前端折线图展示",
"params": [
{"name": "start_time", "in": "query", "type": "string", "required": true, "desc": "开始时间(ISO 8601)"},
{"name": "end_time", "in": "query", "type": "string", "required": true, "desc": "结束时间(ISO 8601)"},
{"name": "granularity", "in": "query", "type": "string", "required": false, "desc": "粒度:hourly/daily,默认 daily"},
{"name": "model_name", "in": "query", "type": "string", "required": false, "desc": "按模型筛选"}
],
"responses": [
{"code": 200, "desc": "成功", "schema": "[{time: string, total_calls: int, success_count: int, fail_count: int, avg_latency: float, total_tokens: int}]"},
{"code": 400, "desc": "参数错误", "schema": ""}
],
"backend": [
{"tag": "receive", "text": "接收 GET /api/v1/statistics/trends 请求"},
{"tag": "validate", "text": "验证时间范围参数"},
{"tag": "query", "text": "从预聚合统计表按时间范围查询数据,按 granularity 聚合"},
{"tag": "return", "text": "返回时间序列数组"}
]
},
{
"method": "GET",
"path": "/api/v1/statistics/by-model",
"name": "按模型聚合",
"description": "按模型维度统计调用次数/成功率/Token 消耗",
"params": [
{"name": "start_time", "in": "query", "type": "string", "required": false, "desc": "开始时间(ISO 8601)"},
{"name": "end_time", "in": "query", "type": "string", "required": false, "desc": "结束时间(ISO 8601)"},
{"name": "top_n", "in": "query", "type": "integer", "required": false, "desc": "返回 TopN 模型(默认 10)"}
],
"responses": [
{"code": 200, "desc": "成功", "schema": "[{model_name: string, total_calls: int, success_rate: float, total_tokens: int}]"},
{"code": 400, "desc": "参数错误", "schema": ""}
],
"backend": [
{"tag": "receive", "text": "接收 GET /api/v1/statistics/by-model 请求"},
{"tag": "validate", "text": "验证时间范围参数"},
{"tag": "query", "text": "从预聚合表按 model_name GROUP BY 聚合统计"},
{"tag": "return", "text": "返回模型维度列表"}
]
},
{
"method": "GET",
"path": "/api/v1/statistics/by-account",
"name": "按账号聚合",
"description": "按账号维度统计调用次数/成功率/Token 消耗",
"params": [
{"name": "start_time", "in": "query", "type": "string", "required": false, "desc": "开始时间(ISO 8601)"},
{"name": "end_time", "in": "query", "type": "string", "required": false, "desc": "结束时间(ISO 8601)"},
{"name": "top_n", "in": "query", "type": "integer", "required": false, "desc": "返回 TopN 账号(默认 10)"}
],
"responses": [
{"code": 200, "desc": "成功", "schema": "[{account_name: string, total_calls: int, success_rate: float, total_tokens: int}]"},
{"code": 400, "desc": "参数错误", "schema": ""}
],
"backend": [
{"tag": "receive", "text": "接收 GET /api/v1/statistics/by-account 请求"},
{"tag": "validate", "text": "验证时间范围参数"},
{"tag": "query", "text": "从预聚合表按 account_id JOIN 账号名称 GROUP BY 聚合统计"},
{"tag": "return", "text": "返回账号维度列表"}
]
}
],
"changelogs": [
{"date": "2026-06-17", "id": "CHG-023", "type": "add", "title": "新增趋势图+维度聚合接口", "desc": "新增 GET /api/v1/statistics/trends(时间序列趋势数据)、GET /api/v1/statistics/by-model(按模型聚合)、GET /api/v1/statistics/by-account(按账号聚合)。", "done": true}
]
}