Commit graph

8 commits

Author SHA1 Message Date
Tejas Chopra
54ae7b9928
Merge pull request #147 from JerrettDavis/feat/anthropic-usage-insights
feat: AI quota & rate-limit tracking — Anthropic, OpenAI Codex, and GitHub Copilot
2026-04-12 10:54:22 -07:00
Adib Mohsin
911eb85a44 new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
JerrettDavis
788d0e7265 feat(dashboard): expand Codex and Copilot cards to match Anthropic card layout
- Codex: 2-column Primary/Secondary window grid (h-3 bars, window labels,
  reset countdowns); Credits moved to bordered section like Anthropic
  extra-usage panel
- Copilot: 3-column category grid (Chat/Completions/Premium) with big
  used/entitlement numbers, color-coded % bars, overage-permitted status
  per category; Monthly Reset section with month-elapsed progress bar and
  formatMonthlyReset() helper
- All three provider cards now share consistent visual language:
  uppercase section labels, h-3 progress bars, border-t dividers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-12 00:20:10 -05:00
JerrettDavis
d11feea511 feat: add GitHub Copilot monthly quota tracking
Adds passive tracking of GitHub Copilot per-category monthly quotas
(chat, completions, premium_interactions) via GET /copilot_internal/user
on api.github.com.

Token discovery checks environment variables in priority order:
  GITHUB_COPILOT_GITHUB_TOKEN > GITHUB_TOKEN >
  COPILOT_GITHUB_TOKEN > GITHUB_COPILOT_API_TOKEN

- headroom/subscription/copilot_quota.py: CopilotQuotaCategory,
  CopilotQuotaSnapshot, CopilotQuotaState, parse_copilot_quota(),
  discover_github_token(), _CopilotQuotaTracker singleton (60s poll)
- headroom/subscription/__init__.py: export new symbols
- headroom/proxy/server.py: start/stop tracker in lifecycle;
  _get_copilot_quota_stats(); copilot_quota key in /stats
- dashboard.html: GitHub Copilot Quota panel with per-category
  progress bars, remaining counts, overage alerts, reset date
- tests/test_copilot_quota.py: 25 unit tests (all pass)
- docs/screenshots/subscription_window_active.png: updated to show
  all three panels (Anthropic + Codex + GitHub Copilot)

Env vars sourced from @github/copilot v1.0.24 app.js (k6e array).
API schema sourced from copilot_internal/user via eBo/QRt zod schemas.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-11 23:58:44 -05:00
JerrettDavis
a3abbec4a3 feat: add OpenAI Codex rate-limit window tracking
Passively capture x-codex-* response headers from proxied Codex API
calls and surface them in /stats and the dashboard.

Unlike Anthropic subscription window tracking (which polls a dedicated
OAuth endpoint), Codex embeds rate-limit data directly in every API
response header — no polling, no new credentials needed.

Changes:
- headroom/subscription/codex_rate_limits.py: new module with
  CodexRateLimitWindow, CodexCreditsSnapshot, CodexRateLimitSnapshot
  data models and a thread-safe CodexRateLimitState singleton;
  parse_codex_rate_limits() parses x-codex-primary/secondary-used-percent,
  window-minutes, reset-at, credits, limit-name, and promo-message headers
- headroom/subscription/__init__.py: re-export new public symbols
- headroom/proxy/handlers/openai.py: call
  get_codex_rate_limit_state().update_from_headers() after each
  proxied /v1/chat/completions and /v1/responses response
- headroom/proxy/server.py: add codex_rate_limits key to /stats
  via _get_codex_rate_limit_stats() helper
- headroom/dashboard/templates/dashboard.html: new OpenAI Codex
  Rate-Limit Window panel (primary + secondary progress bars, credits
  balance, limit name, reset countdown); hidden when no data
- tests/test_codex_rate_limits.py: 25 unit tests covering parsing,
  window labels, reset time, credits, state updates
- docs/screenshots/subscription_window_active.png: updated screenshot
  showing both Anthropic and Codex panels in the real dashboard

Header schema (from codex-rs/codex-api/src/rate_limits.rs):
  x-codex-primary-used-percent / x-codex-primary-window-minutes /
  x-codex-primary-reset-at  (and secondary- variants)
  x-codex-credits-has-credits / -unlimited / -balance
  x-codex-limit-name / x-codex-promo-message

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-11 23:34:19 -05:00
JerrettDavis
86efb59615 docs: replace mock screenshots with real dashboard renders
Active state shows the full headroom dashboard with the Anthropic
Subscription Window panel integrated in-line after Savings Breakdown,
including 5h/7d utilisation bars, overage credit bar, Headroom
contribution grid, and anomaly detection alert.

Inactive state shows the standard dashboard without the panel —
it is conditionally rendered only when subscription_window data
is present in /stats.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-11 22:30:43 -05:00
JerrettDavis
958c731e75 docs: add dashboard screenshots for subscription window panel
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-11 21:58:28 -05:00
JerrettDavis
4226372b15 Add dashboard screenshots for cache TTL metrics PR 2026-04-06 21:52:09 -05:00