Metric Structure
A billable metric defines how usage events are aggregated for billing. Here’s the complete structure:
Metric ids are prefixed
mtr_. The id, created_at and updated_at fields are read-only and returned by the API — you never send them.
Create a Metric
POST /metrics, GET /metrics, GET /metrics/{id}). Editing an existing metric is done in the dashboard.
Aggregation Types
Aggregation defines how event values are combined into a billable quantity. Themethod selects the calculation; field names the event property it reads and is required for every method except count.
Count
Count the number of events.- API calls
- Transactions processed
- Messages sent
- User logins
- Webhook deliveries
- 3 events received → Result: 3
Count Unique
Count unique values of a specified field.- Monthly active users
- Unique IP addresses
- Distinct customers served
- Unique devices
- Events with user_id: “u1”, “u2”, “u1”, “u3” → Result: 3 (unique: u1, u2, u3)
Sum
Sum the values of a numeric field.- Data transfer (bytes/GB)
- Storage used
- Compute hours consumed
- Revenue processed
- Tokens/credits consumed
- Events with bytes: 1000, 2500, 500 → Result: 4000
Average
Calculate the average value of a numeric field.- Average response time
- Average order value
- Average session duration
- Mean compute time
- Events with values: 100, 150, 200 → Result: 150
Min
Find the minimum value of a numeric field.- Minimum latency achieved
- Lowest price point
- Fastest response time
- Events with values: 100, 50, 200 → Result: 50
Max
Find the maximum value of a numeric field.- Peak concurrent users
- Maximum storage used during period
- Highest bandwidth reached
- Peak compute instances
- Events with values: 100, 250, 180 → Result: 250
Filter Operators
Filters allow you to include only specific events in the aggregation. A filter is{field, operator, value}, and value is always a string — even for numeric comparisons.
String Operators
Numeric Operators
The event property and the filter value are compared as numbers when both parse as numbers.If an event does not carry the filtered property at all, only
not_equal matches it. Every other operator treats the event as non-matching.Filter Examples
Filter by region:Filter Combinations
Filters live infilter_groups. Each group has an operator of and or or that combines the filters inside it. Groups themselves are always combined with AND — an event must match every group to be aggregated.
AND Logic (All Conditions Must Match)
OR Logic (Any Condition Can Match)
Combining Groups
Use several groups when each condition must hold independently:Complete Metric Examples
API Call Counter
Count API calls, excluding errors:Data Transfer
Sum bytes transferred:Monthly Active Users
Count unique users:Peak Concurrent Users
Track maximum concurrent users:Compute Hours
Sum compute time in hours:Storage by Tier
Track storage separately for different tiers: Standard Storage:API Calls by Region
Create separate metrics for different regions: NA Region:Best Practices
Use Descriptive Names
Choose names that clearly identify what’s being measured: “API Calls (Premium)” not “Metric 1”.
Filter Early
Add filters to exclude irrelevant events at the metric level, not in pricing.
Test with Real Data
Verify metric calculations with known event data before going live.
Document Definitions
Use descriptions to explain exactly what each metric measures.
Troubleshooting
Metric Shows Zero
- Verify events are being sent with the correct
event_name - Check that filters aren’t excluding all events
- Ensure the aggregation field exists in events (for sum, max, etc.)
Unexpected Values
- Review filter conditions for typos
- Confirm the aggregation
methodandfieldare the ones you meant - Verify event data types (string vs number)
Missing Events
- Confirm events are being sent successfully
- Check event timestamps are within the billing period
- Verify the event
accountresolves to the customer on the subscription
Next Steps
Define Metrics
Create billable metrics in the dashboard.
Send Usage
Send usage events to Alguna.