Wei-Shaw/sub2api · error
failed to get model statistics
Error message
failed to get model statistics
What it means
Returned while assembling the v2 dashboard snapshot when includeModels is true and h.getModelStatsCached(...) fails. The model statistics query uses usagestats.ModelSourceRequested plus the snapshot filters; the original error is masked by this generic message. Infrastructure-side failure.
Source
Thrown at backend/internal/handler/admin/dashboard_snapshot_v2_handler.go:214
}
if includeModels {
models, _, err := h.getModelStatsCached(
ctx,
startTime,
endTime,
filters.UserID,
filters.APIKeyID,
filters.AccountID,
filters.GroupID,
usagestats.ModelSourceRequested,
filters.RequestType,
filters.Stream,
filters.BillingType,
filters.UpstreamModelMismatch,
)
if err != nil {
return nil, errors.New("failed to get model statistics")
}
resp.Models = models
}
if includeGroups {
groups, _, err := h.getGroupStatsCached(
ctx,
startTime,
endTime,
filters.UserID,
filters.APIKeyID,
filters.AccountID,
filters.GroupID,
filters.RequestType,
filters.Stream,
filters.BillingType,
filters.UpstreamModelMismatch,
)View on GitHub (pinned to 073e92d171)
Solutions
- Retry the request — transient DB failures are the most common cause
- Shorten the date range or reduce filter cardinality (add model/user filters)
- Inspect backend logs for the underlying model-stats error
- Exclude the models section from the snapshot while investigating
Defensive patterns
Strategy: retry
Try / catch
// TS
try { models = (await getSnapshotV2({ includeModels: true, start, end })).models; }
catch (e) {
if (e.message === 'failed to get model statistics') {
await sleep(2000);
models = (await getSnapshotV2({ includeModels: true, start: startPlus30d, end })).models; // narrower window
} else throw e;
} Prevention
- Add filters (user, key, model) to shrink model-stats aggregations
- Retry transient failures with backoff
- Alert on repeated model-stats failures to catch missing indexes early
When it happens
Trigger: GET dashboard snapshot v2 with the models section included while the model-stats aggregation over the requested window fails (DB error/timeout).
Common situations: Deployments with many distinct model names making the model-stats GROUP BY expensive; database contention from concurrent snapshot builds; missing usage-stats indexes after migration.
Related errors
- failed to get dashboard statistics
- failed to get usage trend
- failed to get group statistics
- failed to get user usage trend
- HTTP error! status: ${response.status}
AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15).
Data as JSON: /api/errors/06bf65afc154b76f.
Report an issue: GitHub.