Overview
BoxBilling supports full usage-based billing. The pipeline works in three stages:- Events are ingested via the API with a metric code, customer ID, and properties
- Billable Metrics define how events are aggregated (count, sum, max, etc.)
- Charges attach metrics to plans with a pricing model (standard, graduated, volume, etc.)
- Fees are calculated at invoice time based on aggregated usage
Ingesting events
Single event
Batch ingestion
- Up to 100 events per batch
- Events are idempotent — duplicate
transaction_idvalues return the existing event - Rate limited per organization (default: 1000/minute, configurable)
ClickHouse acceleration
For high-volume event ingestion, enable ClickHouse by setting theCLICKHOUSE_URL environment variable. Events are dual-written to both the primary database and ClickHouse, with aggregation queries routed to ClickHouse for performance.
Billable metrics
Billable metrics define how raw events are aggregated into usage values.Create a metric
Aggregation types
| Type | Description | Requires field_name |
|---|---|---|
count | Number of events | No |
sum | Sum of a numeric property | Yes |
max | Maximum value of a property | Yes |
unique_count | Count of distinct property values | Yes |
weighted_sum | Time-weighted sum (proportional to duration) | Yes |
latest | Most recent event’s value | Yes |
custom | Custom expression evaluation | Requires expression |
Example: sum aggregation
Rounding
| Function | Behavior |
|---|---|
round | Half-up rounding |
ceil | Round up |
floor | Round down |
Filters
Filters segment events by property values, enabling different pricing per segment:Charge models
Charges connect billable metrics to plans with a pricing model. When creating a plan, include charges in the request:Available models
Standard
Simple per-unit pricing.amount = units × unit_price
Graduated
Tiered pricing where different unit ranges have different prices.Volume
The total units determine the per-unit price for all units.Package
Fixed price per block of units.Percentage
Percentage of a total amount.Graduated Percentage
Tiered percentage rates based on amount ranges.Custom
Uses a custom expression for aggregation:Dynamic
Per-event property-based pricing — each event is priced individually based on its properties.Charge filters
Apply different pricing based on event properties:properties (here, 0.01/unit).
Usage thresholds
Trigger actions when cumulative usage crosses a monetary threshold within a billing period.Create a threshold
- A
usage_threshold.crossedwebhook is sent - Progressive billing invoices can be generated for early collection
Check current usage
Daily usage aggregation
A background task runs daily at 00:30 UTC to pre-aggregate usage data into thedaily_usages table. This speeds up period-based usage queries for invoice generation and threshold checking.