Projects BibleWeb AI Tools Cost tracking & analytics
Done

Cost tracking & analytics

Area: AI Tools Milestone: v3

Context

Problem: AI API calls have real costs (per-token pricing). Without tracking, it's impossible to know how much the AI feature costs, which users consume the most, or whether pricing tiers are sustainable.

Solution: Log every AI API call with token counts and estimated costs. Provide an admin dashboard to view usage patterns, costs per user, and aggregate statistics.

Not included: User-facing usage dashboards or billing integration. This is admin-only analytics.

Functional

Expected behavior:

  • Every AI chat request logs: user ID, timestamp, input tokens, output tokens, estimated cost
  • Admin dashboard shows: total costs, costs per user, usage over time, average tokens per query

Current state: Token/cost logging exists but the admin dashboard is minimal.

UX & Design

Admin dashboard only — not visible to regular users.

TODO: Design the admin analytics dashboard — charts, tables, filters

Technical

Logging: Each /api/ask call captures token usage from the Anthropic API response.

Data storage:

TODO: Verify if logs go to a DB table or just server logs

Admin route:

TODO: Check if /admin has AI cost analytics

Files:

  • apps/web/src/routes/api/ask/+server.ts — token logging
  • apps/web/src/routes/(app)/admin/+page.svelte — admin dashboard (if exists)

Status

Current: IN_PROGRESS Milestone: v3 Priority: Medium — important for business sustainability

What's done:

  • Full token/cost logging per API call
  • Basic admin visibility

What remains:

  • Comprehensive admin dashboard with charts and filters
  • Cost aggregation and reporting
  • Alert thresholds for unexpected cost spikes

Dependencies:

  • Requires: AI chat (DONE), admin system (DONE)