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:
- Compute allowance from plan (
free/pro/team) - Set
available = max(current_available, allowance)— never reduces carryover or purchased top-ups - Log positive delta as
monthly_resettransaction - Advance
reset_atto 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