%20(1).png)
API Metering: What to Measure, Where, and How to Enforce It
API metering turns API traffic into a financial-grade record. Learn what to meter, where the meter belongs, and how to enforce limits in the request path.
Build an event-based billing system with reliable events, metering, pricing, customer attribution, and invoicing for SaaS, APIs, and AI products.
%20(1).png)
Event-based billing looks clean in a pricing document. A customer does something, you record it, and the bill reflects the usage. It’s production traffic that adds the harder parts. Events retry, arrive late, carry the wrong account ID, or need different treatment under an enterprise contract.
This guide shows how event-based billing works from event capture to invoicing, how to build it reliably, and where runtime usage controls fit.
Event-based billing is a billing method that uses recorded product actions as the input for calculating customer charges.
A billable event could represent an API request, transaction, message, compute job, document processed, workflow completed, or another measurable action.
The event usually records usage first. A meter then decides how that activity counts, and a rating layer applies the customer’s pricing terms.
Event-based billing overlaps with several related concepts. Usage-based billing describes pricing that changes with consumption, while metered billing focuses on measuring that consumption.
A product can use all of these ideas together. API requests become events, a meter counts them, and the customer pays according to the rate attached to that usage.
Event-based billing moves product activity through a billing pipeline until the usage becomes a financial charge. A typical flow looks like this:
Product action → event → ingestion → metering → rating → invoice
The application records a defined action when it occurs. A messaging product might send an event like this:
{
"event_id": "evt_7421",
"customer_id": "cus_104",
"event_type": "sms_sent",
"quantity": 1,
"timestamp": "2026-08-31T13:42:19Z"
}
The payload captures what happened and who produced the usage. The application does not need to calculate the customer’s final price at this stage.
Keeping commercial logic downstream lets the same sms_sent event work across different plans, volume bands, and enterprise contracts.
The event now enters the metering or billing infrastructure.
Real traffic brings retries, malformed payloads, temporary outages, and bursts of events. The ingestion layer needs predictable handling for each case because event accuracy eventually becomes invoice accuracy.
A stable event ID is especially useful. If a producer retries delivery after a timeout, the system can identify the repeated event and avoid counting the same action twice.
Raw events do not always equal the final billing unit.
A compute product could record every completed job and use those events to measure:
Usage metering defines how those source events become measurable quantities.
One event stream can support several meters, which gives you room to change pricing without rebuilding product instrumentation every time.
The rating layer takes measured usage and applies the relevant commercial rules.
Those can include per-unit rates, included allowances, pricing tiers, commitments, credits, overage charges, and customer-specific rates.
A customer might generate 120,000 API requests on a plan that includes 100,000. The meter records the full usage, while the rating layer prices the 20,000 requests above the allowance.
That boundary keeps rate cards and contract logic out of application services.
Rated usage eventually reaches the billing system, where it can become an invoice line item.
The wider billing software architecture may also own adjustments, tax, payments, refunds, and financial records.
Traceability should survive the full path. A disputed charge is much easier to investigate when you can follow the invoice line item back through its meter to the events that created it.
A good billing event contains enough context to identify, measure, and trace the usage consistently.
Most event contracts need a small set of fields.
Field definitions deserve as much attention as field names. quantity: 50 is useless if one producer means 50 requests and another means 50 megabytes.
Treat the schema as a long-lived contract. Once invoices and meters depend on a field, changing its meaning affects historical usage as well as new events.
Billing infrastructure should assume delivery can happen more than once.
A producer may successfully send an event, lose the response, and retry. A stable event ID or idempotency key lets the receiver recognize that both deliveries belong to the same product action.
AWS Marketplace applies deduplication rules to metering records and documents retry handling for failed submissions. Keep the same billing identity for a product action across every retry.
Usage can reach the billing pipeline after it occurs.
A job completed near the end of a billing period may sit in a queue and arrive after the next period has started. Keeping event time and ingestion time separate gives you enough information to handle that delay consistently.
Your billing policy should define how long late events are accepted, how closed periods are treated, and where corrections appear.
Billable metrics define how raw events count toward the customer’s usage.
A data product might emit four query_executed events. Those same records could feed a meter for four queries, total compute seconds, unique users, or usage grouped by processing class.
The product event stays stable while the commercial measurement changes.
That separation is useful when pricing evolves. You may be able to introduce a new meter or pricing plan while leaving the underlying event producer untouched.
It also prevents product code from becoming tightly coupled to every commercial experiment you run.
Event data can support several pricing structures.
Consumption-based billing covers these broader usage models and how they apply to variable-cost products.
Event-based billing fits products where usage can be measured consistently and tied to a meaningful customer action or resource.
The useful pattern across all five is the same. Keep granular product activity available without forcing every internal operation onto the customer’s invoice.
A reliable implementation starts with a clear billable action, then builds identity, event contracts, ingestion, metering, and correction rules around it.
Start with the unit the customer sees and understands. A document-processing product might track database reads, storage, and compute internally while billing for documents, pages, or processing units.
The strongest billing units stay useful even as the underlying implementation changes.
Usage often moves through several layers before it reaches the account that pays for it.
Agent → workspace → department → organization
The agent may create the event, the workspace may hold the allowance, and the organization may receive the invoice. Keeping that hierarchy intact gives you clearer attribution, reporting, allocation, and usage controls.
Every producer should follow the same rules for the data it sends.
A shared contract should define:
Document what each field means as well. A stable schema gives downstream meters a dependable input and prevents two services from interpreting the same field differently.
Billing events will be retried, delayed, rejected, and occasionally delivered more than once. Design for that behavior from the beginning.
Generate one stable event ID at the source and reuse it across delivery attempts. The ingestion layer can then recognize repeated records without creating additional usage.
Monitoring belongs here too. Duplicate rates, rejected payloads, and ingestion lag can expose pipeline problems before they affect an invoice.
The pipeline should preserve a clean division of responsibility.
That separation lets one stream of product events support several plans, customer contracts, and pricing models. Application services can keep reporting the same activity while the commercial layer evolves around it.
Late events and incorrect records are normal cases, which makes correction behavior part of the initial design.
A useful audit trail preserves the original usage record, the correction, and the resulting financial change. Backfills, attribution fixes, and quantity adjustments should remain traceable after an invoice changes.
Financial ownership should be explicit too. Invoice generation, refunds, taxes, contract changes, and adjustments each need one authoritative system. Clear boundaries keep the same billing rule from drifting across several services.
Event-based billing breaks when usage data becomes inaccurate, delayed, or inconsistent across the pipeline.
A simple in-house pipeline can handle a few event types well. It gets harder once more services emit usage, contracts add overrides, or historical events need reprocessing.
Event-based billing records and prices usage after it happens, while runtime enforcement uses current usage state to decide whether the next action can run.
An API may need to block request 100,001 once a customer reaches a 100,000-call limit. An AI product may need to check a credit balance before another model call or tool execution creates cost.
That decision relies on entitlements, usage limits, or credit state in the request path. Billing can keep recording consumption while runtime enforcement controls what the product allows next.
Stigg sits in the part of the stack where usage starts affecting what the product can do next: the runtime layer above your billing system.
Stigg is the usage runtime for AI products, enforcing entitlements, credits, usage limits, and spend rules synchronously in the request path, and integrates with Stripe, Zuora, Chargebee, or custom billing without a rip-and-replace.
For event-driven products, Stigg gives you:
The Sidecar runs as a Docker container alongside your application, caching entitlement data in Redis so access decisions resolve from local cache even if the Stigg API is unreachable.
Cache hits resolve instantly, and on a cache miss, the Sidecar fetches from Stigg's Edge API in around 100ms, with a configurable timeout to prevent upstream latency from cascading into your application.
This keeps usage checks reliable under high-volume traffic without scattering credit and limit logic across your codebase.
Startups can begin with a single SDK integration or one runtime component, adopting metering, credits, or entitlements independently. The Stigg docs show how each piece connects to the wider usage runtime.
Event-based billing uses product events to calculate customer charges. Common events include API calls, transactions, messages, compute jobs, and completed workflows. Those events are then metered, priced, and passed to the billing system.
Event-based billing captures product activity, turns events into usage metrics, applies pricing rules, and sends the rated usage to billing. A typical pipeline includes event ingestion, validation, metering, rating, and invoicing.
The main difference between event-based billing and usage-based billing is what each term describes.
Event-based billing focuses on capturing activity as events, while usage-based billing describes pricing that changes with customer consumption. Many usage-based products use event-based infrastructure underneath.
Yes. Event-based billing can support hybrid pricing, where a recurring subscription includes a usage allowance and additional events are charged once that allowance is used. This is common when you want a predictable base fee with variable charges on top.
To prevent duplicate billing events, use a stable event ID or idempotency key for each product action.
Reusing that identifier across retries lets the ingestion layer recognize duplicates and count the usage once. This prevents temporary network failures from turning into inflated usage or incorrect invoices.