Skip to main content
A billable metric defines what you want to measure from your customers’ usage and how Lago calculates the quantity. For example, you can count API calls, sum tokens consumed, or track the highest number of CPUs used. Your application sends usage events to Lago. The metric identifies the matching events and applies an aggregation rule, such as counting events or adding the values of an event property. Start with the quantity you need to track. Pricing is configured separately through Products and Rate Cards.

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.
  1. Access the Billable metrics section in the side menu.
  2. Create a new billable metric.
  3. Enter its name, a code your events will send, and an optional description.
  4. Select the aggregation type that defines how consumption is measured.
  5. Define the property to aggregate, except for Count.
  6. Define filters if you want to group usage by dimensions such as region or provider.
  7. Set recurring: true to carry the aggregated value between billing cycles, or recurring: false to reset it at the end of each cycle.
  8. Save the billable metric.

Verify the metric

Retrieve the metric and confirm that code, aggregation_type and recurring match. Add expands[]=filters to see its filters.
Retrieve api_calls
Creating the metric does not create a product, a contract or an invoice.

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
Send a second event with 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. Set product_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_metrics

Update a billable metric (API)

PUT /billable_metrics/{code}