AI Economics
How to meter usage for a software product
To meter usage for a software product, record each billable action as a durable event with a stable identifier, a customer reference, and the time it happened. Deduplicate retries, aggregate by customer and billing window, and define how to handle late events. Before closing a period, reconcile the quantities you calculated with the quantities the billing system will invoice.
Define the event that earns a charge
OpenMeter’s usage-event docs describe deduplication by event source and ID. Lago’s usage-ingestion guide explains how event timestamps assign usage to billing periods. Stripe’s Billing Meters API guide says Stripe processes meter events asynchronously, so upcoming invoices can lag behind received events. Stripe’s usage-recording overview describes Billing Meters as its basic usage-based billing path and recommends Metronome for new integrations.
Write down what earns a charge in terms you can use to answer a billing dispute. For an illustrative document-processing product, that might be each page in a successfully completed job. Emit usage once the completed job and its page count are durable. Use the job’s billing account and completion time. If both records live in the same transactional store, save the event alongside the completion record. A dispatcher can retry delivery from that stored record. This is a proposed design based on the event fields described by Lago and OpenMeter.
| Field | What to record in the illustrative product |
|---|---|
| Event identity | A stable source and an ID derived from the completed job and its billable action. Preserve both on replay. OpenMeter usage events |
| Billing identity | The account that owns the usage, with a recorded mapping to the destination’s customer or subscription. Lago usage ingestion · Stripe recording API |
| Occurrence time | The job’s completion time. Keep receipt time separately so you can investigate late arrivals. Lago usage ingestion |
| Meter and quantity | The completed-pages event type and its page count. Define the meter to sum page counts. Stripe meter configuration |
If your product bills for model usage, decide whether input and output tokens belong on separate meters before settling on an event schema. The AI SaaS pricing guide can help you decide which measured units to charge for.
Make retries preserve the original event
Generate the event ID when recording the billable action, then save the payload you intend to send. After a timeout, resend that stored event with the same identity, occurrence time, and quantity. If two incoming records share an identity but disagree on quantity, send the conflict for review. Handle intentional corrections through a separate workflow so operators can tell a correction from a delivery retry. OpenMeter usage events · Lago usage ingestion
Check the destination’s full deduplication key. OpenMeter’s usage-event documentation, updated August 21, 2026, specifies source plus id. Lago’s usage-ingestion guide says its Postgres store deduplicates by transaction_id and external_subscription_id and keeps the first copy. Its ClickHouse store also includes timestamp and code in the key and keeps the most recently ingested copy. In that store, retrying with a different timestamp creates a distinct event. Stripe’s Billing Meters API guide says you can supply an identifier and recommends idempotency keys for usage reporting.
In a reply in the June 2023 OpenMeter Launch HN thread, an OpenMeter cofounder described its focus on collecting infrastructure usage data and aggregating it in real time. In the February 2023 Lago Launch HN post, Lago’s founders described combining usage, subscriptions, and commercial terms to calculate customer bills. Use the vendor docs to check how the integration you build behaves.
Choose the aggregation rule and window
Choose an aggregation rule that matches what the customer buys. In the illustrative product, sum completed pages or count completed jobs. A meter that charges for the last reported value needs a different rule, such as selecting the latest recorded capacity. Stripe Billing Meters supports Sum, Count, and Last as billing-period formulas. Record the meter rule with each export so you can reproduce the billed quantity if you change how new usage is measured. Stripe meter configuration
Write down the start, end, and time zone of each billing period. Use a start-inclusive, end-exclusive interval in your own aggregation, and test an event exactly on the boundary. If you pre-aggregate before exporting to Stripe Billing Meters, align export buckets to the hourly or daily UTC boundaries in Stripe’s meter configuration guide. Stripe uses the most recently received event in each pre-aggregated bucket. For a Sum meter, send the full recomputed bucket total when revising it. Prevent older revisions from overwriting newer ones.
For an illustrative hourly replay, assume two distinct completed jobs contribute 4 and 6 pages, the 6-page event is retried with the same identity, and a distinct 3-page event later arrives with an occurrence time in that hour. The deduplicated total first reaches 10 pages, then 13 when you include the late job. With a Stripe Sum meter using pre-aggregated ingestion, the revised export for that bucket carries 13 pages. A replacement event carrying the 3-page increment would set the bucket value to 3 pages. The replay assumes retries preserve the event identity, as in OpenMeter’s deduplication rules.
Set a cutoff for late usage
Track when an action happened, when your system received it, and when the destination stops accepting usage for the invoice. Use occurrence time to assign the event to a period and receipt time to investigate delays. Stripe’s Billing Meters API guide requires event timestamps within the past 35 calendar days or up to 5 minutes in the future. Check the invoice type as well as its status. Under Stripe’s invoice grace-period rules, threshold invoices include only usage recorded before invoice creation, even while they are in draft.
| When usage arrives | How to handle it |
|---|---|
| During an open period | Recompute the affected aggregate and check that the destination reflects the revised quantity. Stripe recording API |
| After the period ends, while an eligible invoice is open | Apply the destination’s grace-period rules. Stripe’s invoice grace-period guide says subscription cycle invoices and schedule phase transition invoices that modify metered items can include usage reported during the grace period. For subscriptions using Billing Meters, a mid-cycle item price change prevents grace-period usage from appearing on current or subsequent invoices. |
| After the invoice finalizes | Record the discrepancy for review and retain its original period. Stripe says usage reported beyond the grace period can appear in meter summaries without appearing on the finalized or next invoice. Lago says a late event can affect the next cycle if it matches a recurring billable metric. Stripe invoice grace period · Lago usage ingestion |
Reconcile the export against the invoice quantity
Keep a record of what you intended to export for each account, meter, and window. Include the source event IDs or an immutable reference to them, the aggregate revision, the quantity, the destination identifier, and the delivery result. On a rerun, resume from that record. Retry an unresolved delivery with its original identity; create a revision only when you intend to send a changed aggregate. Stripe recording API · Stripe meter configuration
Before close, compare the quantity rebuilt from source events with the quantity sent and the destination’s meter summary for the same customer, meter, and period. If the first two disagree, inspect the selected events and aggregate revision. If the export and meter summary disagree, inspect customer mapping and processing errors. Stripe’s Billing Meters API guide says usage can take time to appear, so check the summary again before resending. After finalization, compare the invoice line quantity with the quantity you expected to be billable under the invoice grace-period rules. Keep the usage receipt available to trace the quantity back to its inputs.
Before enabling charges, replay the illustrative jobs through your normal export path. Repeat a delivery after a simulated timeout, send a job exactly on the window boundary, and deliver a late job on each side of finalization. Verify the local aggregate and invoice quantity separately. For replacement buckets, replay an older revision and confirm your exporter suppresses it. These cases cover deduplication, bucket replacement, and invoice inclusion. Lago usage ingestion · Stripe meter configuration · Stripe invoice grace period
Sources
- Launch HN for OpenMeter (Hacker News, June 22, 2023)
- Launch HN for Lago (Hacker News, February 13, 2023)
- Ingest usage (Lago, undated)
- Record usage for billing (Stripe, undated)
- Record usage with the API (Stripe, undated)
- Create and configure a meter (Stripe, undated)
- Configure an invoice finalization grace period (Stripe, undated)
- Usage events (OpenMeter, August 21, 2026)
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
How to meter usage for a software product. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/usage-metering-for-software-products/