---
title: "Bill early when unbilled usage passes a · Agent Wranglers"
url: https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/threshold-billing
id: USG-31
level: Recommended
applies: payments
updated: 2026-10-27
build: a2a6bdfed830
tokens: 876
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Bill early when unbilled usage passes a threshold

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Usage on invoices](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: USG-31
- Level: Recommended
- Chapter: [Usage on invoices](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices.md)
- Rule: 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.
- 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.
- Applies when: The project takes payments.
- How: 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](https://agentwranglers.se/playbook/payments/failed-payments-and-dunning/dunning-schedule.md), and pauses metered work until it is paid.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
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

```python
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)
```

## Related rules

- PAY-35 [Retry failed renewals on a fixed schedule](https://agentwranglers.se/playbook/payments/failed-payments-and-dunning/dunning-schedule.md) in Payments and billing

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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.

- Previous: [Name the tier model of every metered price](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/tiered-or-volume.md)
- Next: [Bill commitment shortfalls and overages from the contract](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/committed-use-true-up.md)
- [Usage on invoices](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices.md)
