feat: implement /api/usage/clients endpoint
Added client-specific usage aggregation for the analytics dashboard.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user