Prompt
How do I set up usage-based billing for a SaaS product?
Latest observation
Setting up usage-based billing for a SaaS product usually involves four parts: what you meter, how you price it, how you track it, and how you invoice it.
1) Define the billable metric
Pick a usage unit that is:
- Easy to measure
- Closely tied to customer value
- Hard to game
- Predictable enough that customers can estimate cost
Examples:
- API calls
- GB stored
- Minutes processed
- Active seats
- Emails sent
- Compute time
Good metrics are usually one of:
- Volume-based: $ per GB, $ per request
- Tiered: first 1M requests at one rate, next at another
- Overage: fixed subscription includes some usage, then extra charges
- Credit-based: users buy credits and spend them on actions
2) Choose your pricing model
Common models:
Flat subscription + usage overage
Best if you want predictable recurring revenue plus variable upside.
Example:
- $99/month includes 100,000 API calls
- Extra calls: $0.002 each
Pure usage-based
Best when usage varies a lot and customers want to pay only for what they use.
Example:
- $0.10 per document processed
Tiered pricing
Best when you want volume discounts.
Example:
- 0–100k events: $0.01 each
- 100k–1M: $0.008 each
- 1M+: $0.005 each
Prepaid credits
Best when you want cash upfront and simple spend controls.
Example:
- Customer buys $500 in credits
- Each action consumes a known credit amount
3) Build metering
You need a reliable system to capture usage events.
What to record
For each billable event, log:
- Customer/account ID
- Event type
- Quantity
- Timestamp
- Metadata for audit/debugging
- A unique event ID for idempotency
Example event:
{
"event_id": "evt_123",
"customer_id": "cus_456",
"usage_type": "api_call",
"quantity": 1,
"timestamp": "2026-11-12T10:00:00Z"
}
Requirements
- Idempotent ingestion: don’t double count repeated events
- Near real-time or batch processing depending on your needs
- Tamper resistance: prevent client-side spoofing
- Auditability: be able to explain invoices
Common architecture
- App emits usage events
- Event pipeline sends them to a usage database
- Billing engine aggregates usage per billing period
- Invoice generator calculates charges
- Payment processor charges the customer
4) Decide when usage is counted
Important policy choices:
- Immediately when action occurs
- At end of a job
- On successful completion only
- On consumption, not on attempt
Be explicit in your terms:
- Are failed requests billed?
- Are refunds/credits given for downtime or errors?
- How do cancellations work mid-cycle?
5) Set billing periods and thresholds
Typical patterns:
- Monthly billing cycle
- Daily/weekly metering with monthly invoicing
- Real-time balance alerts for prepaid customers
Add:
- Usage thresholds
- Email/webhook alerts at 50%, 80%, 100%
- Hard limits or soft limits
- Auto top-up or overage permission
6) Integrate with a billing platform or build in-house
Most SaaS companies use a billing provider unless billing is a core product.
Common tools
- Stripe Billing / Stripe Metered Billing
- Chargebee
- Recurly
- Zuora
- Lago
- Orb
These help with:
- Metered usage records
- Proration
- Invoicing
- Taxes
- Subscription management
- Dunning and retries
If you build in-house, you’ll need:
- Usage ingestion API
- Rating engine
- Invoice generation
- Tax handling
- Payment retries
- Customer portal
- Revenue reporting
7) Handle taxes and compliance
Depending on where you operate:
- Sales tax / VAT / GST may apply
- You may need address collection and tax calculation
- Invoices may need legal entity details and tax IDs
Also think about:
- Revenue recognition
- Contract terms
- Data retention
- SOC 2 / audit logs if enterprise
8) Make it easy for customers to understand
Usage billing can create anxiety, so give customers:
- Live usage dashboard
- Forecasted bill estimate
- Alerts and limits
- Pricing examples
- Clear metric definitions
- Historic invoices and raw usage exports
If customers can’t predict charges, they’ll distrust the model.
9) Test with edge cases
Make sure you cover:
- Duplicate events
- Delayed event delivery
- Partial month signups/cancellations
- Refunds and credits
- Free trial usage
- Plan upgrades/downgrades
- Negative adjustments
- Currency differences
10) Start simple
A good first version is:
- One usage metric
- Monthly billing
- Stripe or another billing provider
- Usage dashboard
- Alerts at thresholds
- Manual review for large invoices
Then add more sophistication later:
- Multiple metrics
- Tiered discounts
- Credits
- Contracted minimums
- Custom enterprise rates
Simple implementation flow
- Customer signs up for a plan
- Your app emits usage events
- Events are validated and stored
- At billing close, usage is aggregated
- Billing engine applies pricing rules
- Invoice is generated
- Payment is collected automatically
- Customer can view usage and invoice details
Example setup for a typical SaaS
Say you have an AI API product:
- Base plan: $49/month
- Includes 100,000 tokens
- Overage: $0.00002 per token
- Usage tracked per API response
- Dashboard shows live token count
- Alerts at 80% and 100%
- Stripe handles invoicing and payment
- Monthly invoice created automatically
If you want, I can also give you:
- a recommended Stripe setup,
- a database schema for usage metering, or
- a pricing strategy example for your specific SaaS.