USG-31Recommended
Bill early when unbilled usage passes a threshold
Set an amount of unbilled usage, such as 500 euros or the plan fee. When usage passes it, invoice and charge at once instead of waiting for the period end. Lower it for new accounts.
How to do it
A customer can run up a month of usage, then let the card fail at the end. You have already paid the model provider. Charging at a threshold limits that loss to one threshold. Most providers offer it, such as Stripe's billing thresholds, or you can run it as a job that finalises an interim invoice. Start new accounts low and raise the threshold after a few paid invoices. A failed threshold charge follows Retry failed renewals on a fixed schedule, and pauses metered work until it is paid.
Examples
JavaScript example
export async function billIfOverThreshold(account, billing) {
const unbilledMinor = await billing.unbilledUsageMinor(account.id)
if (unbilledMinor < account.thresholdMinor) return null
return billing.invoiceNow(account.id, { reason: 'threshold', idempotencyKey: `threshold-${account.id}-${account.periodStart}-${account.thresholdCount}` })
}
Python example
def bill_if_over_threshold(account, billing):
unbilled_minor = billing.unbilled_usage_minor(account.id)
if unbilled_minor < account.threshold_minor:
return None
key = f"threshold-{account.id}-{account.period_start}-{account.threshold_count}"
return billing.invoice_now(account.id, reason="threshold", idempotency_key=key)
How to check
A test account with a threshold of 500 euros sends usage worth 510 euros in one day. An invoice for that usage is created and charged that day. A test with a failing card pauses the account's metered work.
Related rules
- PAY-35 Retry failed renewals on a fixed schedule in Payments and billing
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/threshold-billing">Agent Wranglers usage-based billing playbook</a>. In code you write, add a comment next to it with the same link.