docs(admins): document credit usage rollup + events endpoints
Merged
SW
5mo ago+334+334+012345678901234567890123456789-1-1-0123456789
Summary
Documentation-driven development for the per-customer credit usage view on the admin dashboard. Defines the API contract first; the api implementation follows in a separate PR.
Two new admin endpoints:
| Endpoint | Purpose |
|---|---|
GET /api/admins/credits/rollup?period=…&limit=… | Per-account rollup, sorted by total credits deducted descending. Joins accounts + account_emails for human-readable rows. |
GET /api/admins/credits/events?account_id=…&period=…&limit=… | Raw usage_events rows for one account, sorted by created_at descending. Powers the drilldown subtable that expands when a rollup row is opened. |
Decisions baked into this contract
- Period selector: reuses the existing admin enum
all | daily | weekly | monthly(perlib/admins/adminPeriod.tsin api).daily=1d /weekly=7d /monthly=30d /all=no cutoff. Defaultmonthly. - Authorization:
validateAdminAuth— accepts bothx-api-keyandAuthorization: Bearer, then runscheckIsAdmin(accountId). Returns 401 (no creds) or 403 (not admin), matching every other endpoint under/api/admins/. - Account identity in the rollup row:
account_id(UUID) +account_name(fromaccounts) +account_email(fromaccount_emails) so the admin table is readable without further client-side joins. - Sort + scale: rollup sorted by
total_credits_deducted_cents DESC,limitdefault 100 (max 500) — matches the agreed "top 100 with show more" behavior. - Drilldown is a separate endpoint (lazy-loaded on row expand) rather than inline events in the rollup payload, so the rollup view stays snappy even with many accounts.
Follow-ups (separate PRs)
- api repo — implement
getAdminCreditsRollupHandler+getAdminCreditsEventsHandlerunderlib/admins/credits/, wireapp/api/admins/credits/rollup/route.tsandapp/api/admins/credits/events/route.ts, TDD with vitest. - admin repo —
/creditspage using@tanstack/react-tablewith the existingPeriodSelector, lazy-load events on row expand.
Test plan
-
python3 -c "import json; json.load(open('api-reference/openapi/accounts.json'))"— OpenAPI JSON parses -
python3 -c "import json; json.load(open('docs.json'))"— navigation config parses - Mintlify preview renders both pages with the expected request/response examples
- Nav shows the two new entries under the Admin group
🤖 Generated with Claude Code
Summary by cubic
Adds OpenAPI and Mintlify docs for admin credit usage: GET /api/admins/credits/rollup (per-account totals) and GET /api/admins/credits/events (per-account events) for the admin dashboard. Lets admins see top spenders and drill into event details.
Docs include page-based pagination (page query; page, limit, total_count in responses), period/limit and account_id (events), admin auth via x-api-key or Bearer; adds both pages to the Admin nav and cross-links them; API implementation will follow.
Summary by CodeRabbit
-
New Features
- Added two new admin endpoints for credit usage analytics: one for per-account rollup totals and one for detailed usage event logs with filtering.
-
Documentation
- Added API reference pages documenting the new credit tracking endpoints.