---
title: "Let customers download the usage behind · Agent Wranglers"
url: https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/usage-export
id: USG-20
level: Recommended
applies: payments
updated: 2026-10-22
tokens: 860
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Let customers download the usage behind each invoice

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-22.

- ID: USG-20
- Level: Recommended
- Chapter: [Usage on invoices](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices.md)
- Rule: Offer a CSV download of the usage behind each invoice line. Give the event time, meter, quantity and the customer's own reference, such as a project.
- Check: A test downloads the export for an invoice and sums the quantity per meter. Each sum equals the quantity on that meter's invoice line. The export contains no prompt text.
- Applies when: The project takes payments.
- How: Finance teams split a usage bill across projects and clients. They need the detail, and an export saves a support ticket for every invoice. Build the export from the same raw events as the invoice, as [Keep raw events and derive every total from them](https://agentwranglers.se/playbook/usage-billing/metering/raw-usage-events.md) says. Leave out personal data the billing contact may not see, such as prompts or end-user names. Stream large exports as a file, as in [Run long jobs asynchronously](https://agentwranglers.se/playbook/api-design/reliability/long-running-jobs.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.

### Python example

```python
import csv

def write_usage_export(rows, out) -> None:
    writer = csv.writer(out)
    writer.writerow(["occurred_at", "meter", "quantity", "reference"])
    for row in rows:
        writer.writerow([row.occurred_at.isoformat(), row.meter, row.quantity, row.reference or ""])
```

### JavaScript example

```js
import { stringify } from 'csv-stringify'

export function usageExportStream(rows) {
  const csv = stringify({ header: true, columns: ['occurred_at', 'meter', 'quantity', 'reference'] })
  for (const row of rows) csv.write([row.occurredAt.toISOString(), row.meter, row.quantity, row.reference ?? ''])
  csv.end()
  return csv
}
```

## Related rules

- USG-3 [Keep raw events and derive every total from them](https://agentwranglers.se/playbook/usage-billing/metering/raw-usage-events.md) in Usage-based billing
- API-37 [Run long jobs asynchronously](https://agentwranglers.se/playbook/api-design/reliability/long-running-jobs.md) in API design

**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/usage-export">Agent Wranglers usage-based billing playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Show each metered charge as its own line](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/itemised-usage-lines.md)
- Next: [Credit back usage your own fault caused](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices/usage-credit-notes.md)
- [Usage on invoices](https://agentwranglers.se/playbook/usage-billing/usage-on-invoices.md)
