CodeIssuesPull RequestsActionsSecurityInsights
✨ AI
More
Settings

Customer AI usage billing: meter + charge users for AI features (internal ops excluded)#200

Openccantynz opened this issue 24d ago
ccantynzAuthorcommented 24d ago

Owner directive 2026-08-08: internal platform AI runs on the owner's Anthropic account (shipped in PR #5440 — admin-selectable, Opus 5 default); customers must pay for their AI usage.

What already exists (good news — most of the plumbing is done):

  • Every AI call records cost per user/repo/category via recordAiCost()ai_cost_events, surfaced on /billing/usage and /api/v2/usage/*.
  • Agent budget tooling (gluecron_get_agent_budget) and Stripe bootstrap (scripts/stripe-bootstrap.ts) exist.

What's missing — the enforcement + billing layer:

  1. Plan gating: free tier gets N cents/month of AI (or zero); paid plans get quota or metered overage. A checkAiBudget(userId) guard at the getAnthropic()/modelForTask() chokepoint returning a clear "AI quota exhausted — upgrade or add billing" error.
  2. Stripe metered billing: monthly rollup of ai_cost_events per user → Stripe usage records, with a configurable markup multiplier over Anthropic list price.
  3. Internal exclusion: calls made with the internal tier (incident RCA, self-repair, demo seeding) tagged so they never appear in customer billing.
  4. BYOK option (maybe): let a user store their own Anthropic API key (encrypted, org-secrets AES infra exists) and run unmetered on their key.

Owner decisions needed before building:

  • Markup over Anthropic list price (e.g. 1.2×? 2×?)
  • Free-tier allowance (e.g. $0.50/month? zero?)
  • Is BYOK allowed, or is metered-only preferred (simpler, revenue-positive)?

Note on "Anthropic subscription": server-side platform AI calls bill to the Anthropic API account (usage-based) — a Claude Pro/Max subscription cannot back server-side automation. The internal/customer split shipped in #5440 controls which spend is whose, which is the part that matters.

ccantynzcommented 22d ago

Ship Agent failed during the failed phase.

Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits."},"request_id":"req_011CdtkQYLBbhZfXPNTXsKD1"}

Please review the issue and try again or implement manually.

ccantynzcommented 22d ago

Ship Agent failed during the failed phase.

Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits."},"request_id":"req_011CdtkZnBNTHVaovJa11asj"}

Please review the issue and try again or implement manually.

c comment · e edit title · x close/reopen · ? shortcuts