Meters

Define how a stream of usage events is aggregated into billable units. The unit label doubles as the display unit and as the credit bucket the meter settles into. A duplicate name within the store is rejected with 409 meter_name_taken.

post/v1/meters

Request

Request body

namestring required

Human-readable meter name, unique within your store

event_namestring required

The usage event name this meter consumes

aggregation'count' | 'sum' | 'average' | 'min' | 'max' | 'unique' required

Aggregation applied to the matching events

aggregation_propertystring

Event property the aggregation reduces. Required for every aggregation except "count", which ignores it.

unit_labelstring required

Display unit for the metered quantity. Also names the customer-credits bucket the meter settles into.

Example request

{
  "name": "Image generations",
  "event_name": "image.generated",
  "aggregation": "sum",
  "aggregation_property": "tokens",
  "filter": {
    "conjunction": "and",
    "clauses": [
      {
        "property": "tier",
        "operator": "equals"
      }
    ]
  },
  "unit_label": "images"
}

Response

Meter created

idstring required

Meter ID

store_idstring required

Store ID

namestring required

Meter name

event_namestring required

Usage event name the meter consumes

aggregation'count' | 'sum' | 'average' | 'min' | 'max' | 'unique' required

Aggregation applied to matching events

aggregation_propertystring nullable required

Property the aggregation reduces; null for "count"

unit_labelstring required

Display unit

status'active' | 'archived' required

Whether the meter is active or archived

created_atstring required

Creation timestamp (ISO 8601)

updated_atstring required

Last update timestamp (ISO 8601)

Example response

{
  "id": "mtr_abc123",
  "store_id": "sto_abc123",
  "name": "Image generations",
  "event_name": "image.generated",
  "aggregation": "sum",
  "aggregation_property": "tokens",
  "filter": {
    "conjunction": "and",
    "clauses": [
      {
        "property": "tier",
        "operator": "equals"
      }
    ]
  },
  "unit_label": "images",
  "status": "active"
}

Changes