docs(api): add ModelMetricsMap type and improve breakdown field documentation

Extract ModelMetricsMap as a named type with documentation comments
explaining the map structure and providing examples. Update the
TrafficBucket.Breakdown field to use the new type and enhance the
GetTrafficChart endpoint description with detailed breakdown field
documentation including example usage.
This commit is contained in:
2026-01-08 16:31:34 +08:00
parent b71c7f2541
commit 341b54b185

View File

@@ -616,12 +616,17 @@ type TrafficMetrics struct {
TokensOut int64 `json:"tokens_out"`
}
// ModelMetricsMap is a map from model name to TrafficMetrics.
// Keys are model names (e.g. "gpt-4", "claude-3-opus") or "other" for aggregated remaining models.
// Example: {"gpt-4": {"count": 10, "tokens_in": 1000, "tokens_out": 500}, "other": {"count": 3, "tokens_in": 200, "tokens_out": 100}}
type ModelMetricsMap map[string]TrafficMetrics
// TrafficBucket represents one time bucket with model breakdown
type TrafficBucket struct {
Time string `json:"time"`
Timestamp int64 `json:"timestamp"`
// Breakdown contains per-model metrics, keyed by model name (e.g. "gpt-4", "claude-3-opus", "other")
Breakdown map[string]TrafficMetrics `json:"breakdown" swaggertype:"object,object" example:"{\"gpt-4\":{\"count\":10,\"tokens_in\":1000,\"tokens_out\":500},\"claude-3-opus\":{\"count\":5,\"tokens_in\":800,\"tokens_out\":400},\"other\":{\"count\":3,\"tokens_in\":200,\"tokens_out\":100}}"`
// Breakdown is a map from model name (e.g. "gpt-4", "claude-3-opus", "other") to its metrics
Breakdown ModelMetricsMap `json:"breakdown"`
Total TrafficMetrics `json:"total"`
}
@@ -641,7 +646,7 @@ const (
// GetTrafficChart godoc
// @Summary Traffic chart data (admin)
// @Description Get time × model aggregated data for stacked traffic charts. Returns time buckets with per-model breakdown.
// @Description Get time × model aggregated data for stacked traffic charts. Returns time buckets with per-model breakdown. The 'breakdown' field in each bucket is a map where keys are model names (e.g. "gpt-4", "claude-3-opus") and values are TrafficMetrics objects. Models outside top_n are aggregated under the key "other". Example: {"gpt-4": {"count": 10, "tokens_in": 1000, "tokens_out": 500}, "other": {"count": 3, "tokens_in": 200, "tokens_out": 100}}
// @Tags admin
// @Produce json
// @Security AdminAuth