How It Works
The usage-based billing system follows a simple workflow:Send Events
Your application sends usage events to Polar whenever a billable action occurs (API calls, storage used, tokens consumed, etc.)
Meters Aggregate Events
Meters filter and aggregate events based on your configuration to calculate consumption
Credits Control Access
Customer meters track credited units (prepaid or included) vs. consumed units to control access
Key Concepts
Events
Events represent billable actions in your system. Each event contains:- Timestamp: When the action occurred
- Customer ID: Who performed the action
- Name: Type of event (e.g.,
api.request,storage.used) - Metadata: Additional context (e.g., tokens consumed, file size)
- User events: Created by your application via the API
- System events: Created automatically by Polar (subscriptions, credits, etc.)
Meters
Meters define how to measure consumption by:- Filtering events to include only relevant ones
- Aggregating events to calculate a quantity
api.request events where metadata.model = "gpt-4" and sum the metadata.tokens field.
Customer Meters
Customer meters track the balance for each customer:- Credited Units: Prepaid credits or included allowance
- Consumed Units: Actual usage measured by the meter
- Balance: Remaining credits (
credited - consumed)
Billing Entries
Billing entries are created for metered consumption during a billing period. They represent:- The time period (start and end timestamps)
- The consumed units
- The applicable price
- The calculated amount to charge
Pricing Models
Polar supports flexible metered pricing:Per-Unit Pricing
Charge a fixed amount per unit consumed:Tiered Pricing
Different rates for different usage levels:Volume Pricing
Rate applies to all units based on total volume:Aggregation Functions
Meters support multiple aggregation functions:| Function | Description | Example Use Case |
|---|---|---|
count | Count matching events | API requests, transactions |
sum | Sum a numeric property | Total tokens, total GB |
max | Maximum value observed | Peak concurrent users |
min | Minimum value observed | Lowest latency |
avg | Average value | Average response time |
unique | Count unique values | Unique users, unique IPs |
Common Use Cases
API Usage
Charge based on API calls, categorized by endpoint or model:Storage & Bandwidth
Track storage usage and data transfer:Compute Resources
Measure compute time, memory, or other resources:Seats & Licenses
Track active users or seats:Credit System
The credit system provides flexibility for prepaid and included usage:Included Credits
Include credits with subscriptions as benefits:- Set up a “Meter Credit” benefit on your product
- Specify number of units and whether they rollover
- Credits are automatically added when subscription starts
- Credits reset each billing cycle (unless rollover is enabled)
Prepaid Credits
Sell prepaid credit packs:- Create a one-time product with meter credits
- Customer purchases credits upfront
- Credits are applied to their meter balance
- Use for top-ups or pay-as-you-go models
Rollover
Control whether unused credits carry forward:- Rollover enabled: Unused credits accumulate
- Rollover disabled: Credits reset each cycle
Workflow Example
Here’s a complete example of usage-based billing in action:Customer subscribes
Customer subscribes to “Pro Plan” which includes:
- 10,000 API credits per month
- Metered billing at $0.001 per additional call
Credits are added
Polar automatically creates a
meter.credited event adding 10,000 units to the customer’s meterConsumption is tracked
The meter aggregates events in real-time:
- Consumed: 12,500 calls
- Credited: 10,000 calls
- Balance: -2,500 calls (overage)
Invoice is generated
At billing cycle end, an invoice is created:
- Pro Plan subscription: $49.00
- Additional API calls (2,500 × 2.50
- Total: $51.50
Best Practices
Event Design
- Use descriptive names:
api.requestinstead ofrequest - Include relevant metadata: Add context needed for filtering and aggregation
- Keep events atomic: One event per billable action
- Use timestamps correctly: Set timestamp to when action occurred, not when event was sent
Meter Configuration
- Start simple: Begin with basic count aggregations
- Test filters thoroughly: Ensure events match as expected
- Consider granularity: Balance detail with simplicity
- Document your meters: Explain what each meter measures
Credit Management
- Set appropriate limits: Match included credits to your pricing model
- Consider rollover carefully: Rollover increases goodwill but reduces revenue
- Monitor balances: Alert customers before they run out
- Provide visibility: Show customers their usage and balance
Performance
- Batch events when possible: Send multiple events in one request
- Use deduplication: Set
external_idto prevent duplicate billing - Monitor ingestion rate: Stay within API rate limits
- Cache meter balances: Don’t query on every request
Next Steps
Event Ingestion
Learn how to send usage events to Polar
Meters
Configure meters to measure consumption
Credits
Set up credit benefits and prepaid packs
Billing
Understand billing cycles and invoicing