Skip to main content
Filters define the event properties and values you can use to select groups of usage within a billable metric. For example, a compute metric measures hours of usage. A region filter lets you distinguish where that usage occurred, while a provider filter identifies the cloud provider. You can use the same metric across these dimensions.

How filters work

A dimension is an attribute of usage, such as its region or model. Define each filter with a key and a list of values:
  • key: the event property to match, such as region.
  • values: the configured values for that property, such as us-east-1 and eu-west-1.
Your application sends these properties with each event. The metric’s aggregation determines how the quantity is calculated; the filter identifies which group the event matches.

Use cases

Measure compute hours across regions. Include region in each event to identify where the usage occurred.
Measure token usage across models. Include model in each event to identify which model processed the tokens.
Measure API calls by service tier. Use tier to distinguish real-time requests from batch requests.
Include both region and model when you want to distinguish usage by where it occurred and which model was used.

Create filters

The compute metric adds the hours reported in usage events. Define provider and region filters to distinguish the cloud provider and location associated with that usage.
  1. Create a new billable metric.
  2. Add a new filter.
  3. Define its key and values.
Adding filter keys and values on the billable metric form in the Lago dashboard

How to add filters

An event carrying both dimensions:
Event with filter values
This event reports 0.07 hours of compute usage on aws in us-east-1. The hours property supplies the quantity; provider and region supply the dimensions.
Values are case-sensitive. An event must send the exact value to match. With the filters above, "aws" matches and "AWS" does not.

Edit filters

When you update filters, send the complete set you want to keep. The supplied array replaces the existing filters. An empty array removes all filters, subject to restrictions on values already referenced by Product filters. Filter values referenced by Product filters cannot be removed. Remove or change the Product filter first.
Payload A
Payload B
Sending Payload B after Payload A:
  1. europe stays.
  2. usa is removed, unless a product filter references it. In that case the update is rejected.
  3. USA is added. Keys and values are case-sensitive, so it is a new value.
  4. africa is added.
Once the metric is attached to a Plan, only its name, description and permitted filter changes can be updated.

Design guidance

  • Choose a metric code that describes the measurement, such as compute_hours.
  • Send the dimensions you need to distinguish as event properties.
  • Use consistent spelling and capitalization for filter values.

Next step

See Product filters to learn how to select combinations of these dimensions for a Product.

Create a billable metric (API)

POST /billable_metrics

Create a product filter (API)

POST /products/{product_code}/filters