feat(ai): Usage tracking and cost dashboard #368

Open
opened 2026-05-31 16:28:34 +00:00 by jmiller · 0 comments
Owner

Summary

Track all AI token usage per org/repo and display cost dashboards.

Parent Issue

#359

What Gets Tracked

Every AI action logs: org_id, repo_id, triggered_by user, action type (review/chat/agent), model, input tokens, output tokens, duration, timestamp.

Dashboards

Site Admin

  • Total usage across all orgs
  • Per-org breakdown
  • Daily/weekly/monthly charts
  • Alert thresholds

Org Admin

  • Org total usage and estimated cost
  • Per-repo and per-user breakdown
  • Budget remaining vs rate limit
  • Charts over time

Cost Calculation

  • Estimated USD per action based on Anthropic pricing
  • Monthly rollup
  • Compare against org rate limit

Rate Limit Enforcement

  • Check before every AI action
  • If exceeded: post comment and skip
  • Configurable: hard limit (block) vs soft limit (warn)

Implementation

  • models/ai/usage.go
  • services/ai/usage.go
  • routers/web/admin/ai.go (dashboard)
  • routers/web/org/setting/ai.go (dashboard)
  • templates/admin/ai/dashboard.tmpl
  • templates/org/settings/ai_dashboard.tmpl

Dependencies

  • AI settings schema
## Summary Track all AI token usage per org/repo and display cost dashboards. ## Parent Issue #359 ## What Gets Tracked Every AI action logs: org_id, repo_id, triggered_by user, action type (review/chat/agent), model, input tokens, output tokens, duration, timestamp. ## Dashboards ### Site Admin - Total usage across all orgs - Per-org breakdown - Daily/weekly/monthly charts - Alert thresholds ### Org Admin - Org total usage and estimated cost - Per-repo and per-user breakdown - Budget remaining vs rate limit - Charts over time ## Cost Calculation - Estimated USD per action based on Anthropic pricing - Monthly rollup - Compare against org rate limit ## Rate Limit Enforcement - Check before every AI action - If exceeded: post comment and skip - Configurable: hard limit (block) vs soft limit (warn) ## Implementation - models/ai/usage.go - services/ai/usage.go - routers/web/admin/ai.go (dashboard) - routers/web/org/setting/ai.go (dashboard) - templates/admin/ai/dashboard.tmpl - templates/org/settings/ai_dashboard.tmpl ## Dependencies - AI settings schema
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MokoConsulting/MokoGitea#368