Credits (Usage-Based Billing)

Stripe subscriptions are on by default. Metered credits are not, but the schema and server-action style in this repo are meant to make adding a balance + guard straightforward.

Recommended approach

  1. Add a credits_balance (or usage counter) to a workspace-scoped table
  2. Wrap any metered feature in a server-side guard:
    • authorize role
    • check balance
    • decrement atomically
    • write an audit log entry
  3. Optionally, sync usage to Stripe:
    • Stripe Metered Billing or usage records

Implementation notes

  • Keep credit deduction in the database (transaction) to avoid race conditions
  • Always scope by workspace_id

If you want a ready-made RAG + credits system, use the SaaSForge AI template and reuse pieces here.