Creating and managing meters for Usage Based Billing
Meters are there to filter and aggregate the events that are ingested. Said another way, this is how you define what usage you want to charge for, based on the events you send to Polar. For example:
ai_usage
and sums the total_tokens
field.video_streamed
and sums the duration
field.file_uploaded
and sums the size
field.You can create and manage your meters from the dashboard. Polar is then able to compute the usage over time, both globally and per customer.
To create a meter, navigate to the Meters page in the sidebar and click the “Create Meter” button.
A filter is a set of clauses that are combined using conjunctions. They’re used to filter events that you’ve ingested into Polar.
A clause is a condition that an event must meet to be included in the meter.
Properties are the properties of the event that you want to filter on.
If you want to match on a metadata field, you can use the metadata key directly. No need to include a metadata.
prefix.
Operators are the operators that you want to use to filter the events.
Values are automatically parsed in the filter builder. They’re parsed in the following order:
A conjunction is a logical operator that combines two or more clauses.
The aggregation is the function that is used to aggregate the events that match the filter.
For example, if you want to count the number of events that match the filter, you can use the Count aggregation. If you want to sum the value of a metadata field, you can use the Sum aggregation.
Example
Consider the following events:
Here is the result of each aggregation function, over the total_tokens
metadata property:
If you want to use a metadata property in the aggregation, you can use the metadata property directly. No need to include a metadata.
prefix.
The following Meter Filter & Aggregation will match events that have the name openai-usage
and sum units over metadata property completionTokens
.
You can Preview the events matched by the meter while creating it.
A few things to keep in mind when creating and managing meters:
You may update a meter’s filters or aggregation function as long as the meter doesn’t have any processed events.
Meters are permanent. Once created, they cannot be deleted.