Choose what to measure
Metric fields
Create the API calls metric
Use COUNT (count_agg) when each event is one API call. field_name is not needed.
- Dashboard
- API
- Access the Billable metrics section in the side menu.
- Create a new billable metric.
- Enter its
name, acodeyour events will send, and an optionaldescription. - Select the aggregation type that defines how consumption is measured.
- Define the property to aggregate, except for Count.
- Define
filtersif you want to group usage by dimensions such as region or provider. - Set
recurring: trueto carry the aggregated value between billing cycles, orrecurring: falseto reset it at the end of each cycle. - Save the billable metric.
Verify the metric
Retrieve the metric and confirm thatcode, aggregation_type and recurring match. Add expands[]=filters to see its filters.
Retrieve api_calls
Test with sample usage
Once a metered product uses the metric and a test contract includes its rate card, send two events and check the count. Use a contract with an open billing period and no other matching usage.Send one API call event
transaction_id set to api-call-test-002. The omitted timestamp defaults to the request time. Then read contract current usage: the api_calls_usd entry should show units of "2". Newly accepted events may take time to appear.
Update a metric
PUT /billable_metrics/{code} accepts partial updates. Once the metric is attached to a plan, only name, description and permitted filter changes are allowed. Changes to locked fields return 422. Filter values referenced by product filters cannot be removed.
Next step: connect the metric to a Product
To use the metric for billing, connect it to a metered Product. Setproduct_type to metered and billable_metric_code to api_calls. Configure pricing separately through a Rate Card.
Aggregation types
Choose how usage is measured.
Metered products
Connect your metric to a Product.
Create a billable metric (API)
POST /billable_metricsUpdate a billable metric (API)
PUT /billable_metrics/{code}