feat: implement /api/usage/clients endpoint
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

Added client-specific usage aggregation for the analytics dashboard.
This commit is contained in:
2026-03-19 12:31:11 -04:00
parent 1f3adceda4
commit 26d8431998
2 changed files with 28 additions and 2 deletions

View File

@@ -370,6 +370,32 @@ func (s *Server) handleProvidersUsage(c *gin.Context) {
c.JSON(http.StatusOK, SuccessResponse(rows))
}
func (s *Server) handleClientsUsage(c *gin.Context) {
var filter UsagePeriodFilter
if err := c.ShouldBindQuery(&filter); err != nil {
// ignore
}
clause, binds := filter.ToSQL()
var rows []struct {
ClientID string `db:"client_id" json:"client_id"`
Requests int `db:"requests" json:"requests"`
}
err := s.database.Select(&rows, fmt.Sprintf(`
SELECT COALESCE(client_id, 'unknown') as client_id, COUNT(*) as requests
FROM llm_requests
WHERE 1=1 %s
GROUP BY client_id
`, clause), binds...)
if err != nil {
c.JSON(http.StatusOK, SuccessResponse([]interface{}{}))
return
}
c.JSON(http.StatusOK, SuccessResponse(rows))
}
func (s *Server) handleAnalyticsBreakdown(c *gin.Context) {
var filter UsagePeriodFilter
if err := c.ShouldBindQuery(&filter); err != nil {