Skip to Content
Credits & BillingMonthly reset

Monthly reset

Behavior

reset_monthly_generation_credits() runs on a schedule (pg_cron on hosted Supabase, or credits-monthly-reset Edge function).

For each org due for reset:

  1. Compute allowance from plan (free / pro / team)
  2. Set available = max(current_available, allowance)never reduces carryover or purchased top-ups
  3. Log positive delta as monthly_reset transaction
  4. Advance reset_at to next UTC month boundary

Orgs with active reserved credits are still reset (allowance metadata); reserved amounts are unchanged.

Stale jobs

reap_stale_generation_jobs() fails jobs stuck in queued/processing past a timeout (default 30 minutes) and refunds reserves via finalize_generation_job.

Schedule via pg_cron every 5 minutes or call generation-reap-stale Edge function with cron secret / service role.

Operations

# Edge (self-hosted) curl -X POST https://your-api/functions/v1/credits-monthly-reset \ -H "Authorization: Bearer $SERVICE_ROLE_KEY" curl -X POST https://your-api/functions/v1/generation-reap-stale \ -H "X-Cron-Secret: $CREDITS_CRON_SECRET"

See ADR docs/adr/0007-monthly-credit-reset.md.

Last updated on