Meter Structure
A meter consists of these core components:| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique meter identifier (e.g., mtr_api_calls) |
name | string | Yes | Display name |
event_name | string | Yes | Event type to track (must match event_name in events) |
aggregation | object | Yes | How to aggregate events |
filters | array | No | Event property filters |
reset_usage | string | No | When to reset accumulated usage |
Example Meter Configuration
Aggregation Configuration
Theaggregation object defines how events are transformed into usage metrics.
Aggregation Fields
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Aggregation method (see Aggregations) |
field | string | Conditional | Property name to aggregate (required for SUM, MAX, AVG, LATEST) |
expression | string | No | CEL expression for complex calculations |
multiplier | decimal | Conditional | Multiplier for SUM_WITH_MULTIPLIER type |
bucket_size | string | No | Time window for bucketed MAX or SUM aggregations |
group_by | string | No | Property to group by (MAX with bucket_size only) |
Common Aggregation Patterns
Filters
Filters allow you to create multiple meters from the same event type by matching specific property values.Filter Structure
- key: Property name from
event.properties - values: Array of acceptable values (OR logic)
- Multiple filters use AND logic
Filter Examples
Reset Usage Behavior
Thereset_usage field controls when accumulated usage resets:
| Value | Behavior | Use Case |
|---|---|---|
BILLING_PERIOD | Reset at start of each billing period | API calls, data transfer |
NEVER | Never reset (continuous accumulation) | Storage, peak usage |
Examples
Resetting Usage (API Calls):- Customer starts billing period with 0 usage
- Usage accumulates throughout the period
- Resets to 0 at start of next period
- Usage represents current state (e.g., GB currently stored)
- Latest value is used for billing
- Historical values are preserved
Advanced Configurations
Bucketed Aggregations
For MAX or SUM aggregations, usebucket_size to calculate over time windows:
- Events are grouped into hourly buckets
- MAX is calculated within each bucket
- Buckets are summed for billing period total
HOUR, DAY, WEEK, MONTH
Grouped Aggregations
For bucketed MAX meters, usegroup_by to aggregate per property value:
- Events are grouped by bucket (day) and
organization_id - MAX is calculated per organization per day
- Results are summed across all organizations and days
group_by is only supported for MAX aggregation with bucket_size configured.CEL Expressions
Use Common Expression Language (CEL) for complex calculations:- Access event properties directly by name (e.g.,
tokens,duration) - Standard math operators:
+,-,*,/,% - Comparison:
==,!=,<,<=,>,>= - Logical:
&&,||,!
Creating Meters via API
Meters are typically created through the FlexPrice dashboard, but can also be managed via API:Validation Rules
FlexPrice validates meter configurations:Use Case Examples
API Metering by Endpoint
Track different API endpoints separately:Storage by Tier
Measure storage across different tiers:AI/ML Token Usage
Track token consumption by model:Peak Concurrent Usage
Measure maximum concurrent connections:Best Practices
One Meter per Billable Metric
Create separate meters for each distinct usage metric you want to bill.
Choose Appropriate Aggregation
Match aggregation type to your pricing model (COUNT for per-request, SUM for consumption, MAX for capacity).
Test with Real Events
Send test events and verify meters calculate usage correctly before production use.
Next Steps
Aggregation Methods
Learn about available aggregation types
Send Events
Start sending events to your meters
Query Usage
Retrieve aggregated usage data
Connect to Pricing
Link meters to prices for billing