---
title: "Match your usage totals with the provider · Agent Wranglers"
url: https://agentwranglers.se/playbook/usage-billing/metering/usage-reconciliation
id: USG-5
level: Recommended
applies: payments
updated: 2026-10-22
tokens: 820
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Match your usage totals with the provider before each invoice

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

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

- ID: USG-5
- Level: Recommended
- Chapter: [Metering](https://agentwranglers.se/playbook/usage-billing/metering.md)
- Rule: Before a usage invoice is finalised, compare your total per customer and meter with the total the billing provider holds. Hold the invoice when they differ.
- Check: A test drops one event on the way to a sandbox provider. The reconciliation job finds the gap, resends the event and the draft invoice total then matches your sum. A second run sends nothing.
- Applies when: The project takes payments.
- How: Events sent to a provider can fail, time out or arrive twice. Most billing engines leave a usage invoice in draft for a short time, such as an hour, before they finalise it. Use that window. Fetch the provider's summary for the period and compare it with your own sum. Send any missing events with their original keys, so nothing doubles. Alert a person when a gap remains. This is the usage side of [Reconcile every payout](https://agentwranglers.se/playbook/payments/payment-events-and-reconciliation/payout-reconciliation.md).

## 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 reconcileUsage(customerId, meter, period) {
  const ours = await usage.total(customerId, meter, period)
  const theirs = await billing.meterSummary(customerId, meter, period)
  if (ours === theirs) return 'matched'
  for (const event of await usage.notAcknowledged(customerId, meter, period)) {
    await billing.sendMeterEvent(event, { identifier: event.eventKey })
  }
  return 'resent'
}
```

### Python example

```python
def reconcile_usage(customer_id: str, meter: str, period) -> str:
    ours = usage.total(customer_id, meter, period)
    theirs = billing.meter_summary(customer_id, meter, period)
    if ours == theirs:
        return "matched"
    for event in usage.not_acknowledged(customer_id, meter, period):
        billing.send_meter_event(event, identifier=event.event_key)
    return "resent"
```

## Related rules

- PAY-22 [Reconcile every payout](https://agentwranglers.se/playbook/payments/payment-events-and-reconciliation/payout-reconciliation.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/metering/usage-reconciliation">Agent Wranglers usage-based billing playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Accept late events up to a fixed cut-off](https://agentwranglers.se/playbook/usage-billing/metering/late-usage-cutoff.md)
- [Metering](https://agentwranglers.se/playbook/usage-billing/metering.md)
