Skip to main content
Limited Release
A metric defines how to aggregate event data and calculate billable usage. An event is an action your customer performs while using your system, such as placing an API call. Metrics connect the following:
  • Pricing plans that apply pricing models to metric usage for calculating charges.
  • Usage events that the metric aggregates to determine billable consumption.

1. Decide the event to track

Before you create metrics, choose which event you want to track and the event details (event properties) you require. For most aggregation methods, you need to include the event property name in the API call to create metrics.

2. Decide the metric type

Based on your business use case, decide on one of the following metric types:
  • Metered metric: Customers are charged based on exactly how much of a feature they use within a specific billing period. The usage resets to zero each cycle and customers pay only for what they use in that period. For example, a metric that calculates usage based on the number of API calls placed in a month.
  • Recurring metric: Customers are charged for usage that persists across billing periods. The usage accumulates or remains steady until modified. For example, a metric that calculates usage as the total storage space utilized.
You need to pass the metric type in the API call to create metrics.

3. Decide the aggregation type and aggregation field

Aggregation type determines how the metric aggregates event data and calculates usage. Based on your business use case, choose an aggregation type from the following.
Recurring metrics support only SUM and COUNT_DISTINCT aggregation types.
You can track multiple properties of an event. Aggregation field specifies the specific property on which the selected aggregation type is applied. For example, an event for using data storage can contain properties such as storage_gb and region. You can set up a metric that aggregates storage_gb to determine billable usage. In this case, storage_gb is the aggregation field. You need to pass the aggregation type in the API call to create metrics.

4. Create metrics

Use a valid access token and make a POST call to the /v1/commerce/billing/metrics endpoint. Include the following parameters: For information on all parameters, see API reference.
A successful call returns a 201 Created response. The response includes the following parameters: For information on all parameters, see API reference.

5. Filter aggregation field values

Field filters let you include only specific events or data in your metric calculation. The system only includes events that match all your filter rules. For each filter, choose a property name (key) and the values you want to match. Common ways to use filters and samples:
  • By region: Track usage across different geographic locations.
  • By performance tier: Separate different service levels.
  • By token type: Distinguish between different AI processing types.
  • By feature: Track premium vs standard features.
  • By status: Count only successful operations.

6. Manage metrics

You can update metric configurations when adjusting aggregation methods, modifying field filters, or changing metric descriptions. To review a metric’s current configuration, call the Get metric details endpoint.