Usage-based pricing
Overview
Use usage-based pricing (metered billing) to charge customers based on how much they consume rather than a fixed recurring amount. Instead of paying $50/month regardless of activity, a customer pays based on actual usage — a light user pays less, a heavy user pays more.
Common use cases:
- API calls or compute tokens
- Cloud storage or bandwidth
- Email or SMS delivery
- Utility-style services
Core concepts
Usage-based billing is built on three concepts:
Before you begin
- Create at least one product in your catalog
- Create a customer in the account
- Have an API key with account-level access
Create a meter
A meter defines the usage metric you want to track. Each meter has an event name (a unique identifier your application uses when sending events) and an aggregation formula that controls how events are combined.
Response:
Use sum when the event value represents a quantity (e.g., tokens, bytes, seconds). Use count when each event represents one billable action regardless of the value field.
Create a metered price
Link a meter to a product by creating a price with usage_type: "metered". Metered prices support three pricing patterns:
Per-unit pricing
Charge a flat rate per unit of usage. Set a quantity_divisor to bill per batch of units (e.g., per 100 tokens).
This charges $0.04 per 100 tokens (4 atoms per batch, where 1 atom = $0.01). A customer who uses 15,000 tokens in a month pays ceil(15,000 / 100) × $0.04 = $6.00.
Free tier + overage (graduated tiered)
Offer a free allowance by setting the first tier’s unit amount to $0:
The first 1,000 units are free. Usage beyond that is $0.01/unit. A customer who uses 3,000 units pays (1,000 × $0) + (2,000 × $0.01) = $20.00.
Flat fee + included allowance
Charge a base fee that includes a usage allowance, with per-unit charges for overage:
This charges $200/month (the flat fee of 20,000 atoms) which includes 100,000 units. Overage is $0.01/unit. A customer who uses 150,000 units pays $200 + (50,000 × $0.01) = $700.00. Zero usage still charges the $200 flat fee.
All pricing patterns — per-unit, free tier, and flat fee + allowance — are built on the same graduated tiered pricing engine. Free tiers are just tiers with a $0 unit amount, and flat fees are just tiers with a flat_amount_atom.
Send usage events
Report usage by sending events to the meter events endpoint. Each event includes the meter’s event_name, a payload with the customer ID and usage value, and an optional timestamp.
Single event
Batch events
Send up to 100 events in a single request for higher throughput:
The batch response reports how many events were accepted and lists any per-event errors:
If some events fail validation, valid events are still ingested:
Event validation rules
For high-throughput use cases, batch events and send them periodically rather than one at a time. You can also pre-aggregate usage on your side and send periodic summary events.
Subscribe a customer to a metered price
Create a subscription that includes a metered price. Metered items have no upfront charge — the customer is billed based on usage at the end of each billing period.
A subscription can include both fixed and metered prices. Fixed-price items are invoiced at the beginning of each billing period (at renewal). Metered-price items accumulate usage during the period and are invoiced at the end (at the next renewal), based on actual usage.
How billing works at renewal
When a billing period ends:
- PaymentKit aggregates usage events for each metered item over the completed period
- The aggregated usage is run through the pricing model (per-unit or tiered) to calculate the charge
- Metered charges appear as line items on the renewal invoice alongside any fixed charges
- The invoice is finalized and payment is collected
For zero usage: if the price has a flat fee (e.g., a base subscription fee), the flat fee is still charged. If there is no flat fee, a $0 line item is created.
Query usage
Meter-level usage
Get the aggregated usage for a specific meter and customer over a time range:
Subscription-level usage
Get the current-period usage for all metered items in a subscription:
Manage meters
Deactivate a meter
Deactivate a meter to stop accepting new events. Existing prices linked to the meter continue to function for billing purposes.
Reactivate a meter
End-to-end example
A complete walkthrough of usage-based billing for an AI token processing service:
-
Create a meter for token tracking:
-
Create a metered price at $0.04 per 100 tokens:
-
Subscribe a customer — no upfront charge for the metered item:
-
Send usage events throughout the month:
-
At month-end, PaymentKit aggregates: 15,000 total tokens. Charge:
ceil(15,000 / 100) × $0.04 = $6.00. An invoice is generated with a $6.00 line item for “Tokens Processed”.