Skip to main content
This page provides complete reference documentation for configuring billable metrics in Alguna. Use this as a reference when setting up metrics in the dashboard or via API.

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

Metrics can be created and read through the API (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. The method selects the calculation; field names the event property it reads and is required for every method except count.

Count

Count the number of events.
Use cases:
  • API calls
  • Transactions processed
  • Messages sent
  • User logins
  • Webhook deliveries
How it works:
  • 3 events received → Result: 3

Count Unique

Count unique values of a specified field.
Use cases:
  • Monthly active users
  • Unique IP addresses
  • Distinct customers served
  • Unique devices
How it works:
  • Events with user_id: “u1”, “u2”, “u1”, “u3” → Result: 3 (unique: u1, u2, u3)

Sum

Sum the values of a numeric field.
Use cases:
  • Data transfer (bytes/GB)
  • Storage used
  • Compute hours consumed
  • Revenue processed
  • Tokens/credits consumed
How it works:
  • Events with bytes: 1000, 2500, 500 → Result: 4000

Average

Calculate the average value of a numeric field.
Use cases:
  • Average response time
  • Average order value
  • Average session duration
  • Mean compute time
How it works:
  • Events with values: 100, 150, 200 → Result: 150

Min

Find the minimum value of a numeric field.
Use cases:
  • Minimum latency achieved
  • Lowest price point
  • Fastest response time
How it works:
  • Events with values: 100, 50, 200 → Result: 50

Max

Find the maximum value of a numeric field.
Use cases:
  • Peak concurrent users
  • Maximum storage used during period
  • Highest bandwidth reached
  • Peak compute instances
How it works:
  • 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:
Exclude failed requests:
Filter several regions at once:
Filter large files:

Filter Combinations

Filters live in filter_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:
This matches: (premium OR enterprise) AND not failed.

Complete Metric Examples

API Call Counter

Count API calls, excluding errors:

Data Transfer

Sum bytes transferred:
Alguna aggregates the raw property value and does not convert units. If you price per GB, send the property already expressed in GB rather than in bytes.

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:
Premium Storage:

API Calls by Region

Create separate metrics for different regions: NA Region:
EMEA 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

  1. Verify events are being sent with the correct event_name
  2. Check that filters aren’t excluding all events
  3. Ensure the aggregation field exists in events (for sum, max, etc.)

Unexpected Values

  1. Review filter conditions for typos
  2. Confirm the aggregation method and field are the ones you meant
  3. Verify event data types (string vs number)

Missing Events

  1. Confirm events are being sent successfully
  2. Check event timestamps are within the billing period
  3. Verify the event account resolves to the customer on the subscription

Next Steps

Define Metrics

Create billable metrics in the dashboard.

Send Usage

Send usage events to Alguna.