Skip to main content
POST
/
v1
/
billable-metrics
/
create
Create a billable metric
curl --request POST \
  --url https://api.metronome.com/v1/billable-metrics/create \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "CPU Hours",
  "event_type_filter": {
    "in_values": [
      "cpu_usage"
    ]
  },
  "property_filters": [
    {
      "name": "cpu_hours",
      "exists": true
    },
    {
      "name": "region",
      "exists": true,
      "in_values": [
        "EU",
        "NA"
      ]
    },
    {
      "name": "machine_type",
      "exists": true,
      "in_values": [
        "slow",
        "fast"
      ]
    }
  ],
  "aggregation_type": "SUM",
  "aggregation_key": "cpu_hours",
  "group_keys": [
    [
      "region"
    ],
    [
      "machine_type"
    ]
  ]
}'
{
  "data": {
    "id": "58fb0650-e54a-4d17-93cb-ba8e56c32c65"
  }
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

The details of the billable metric to create.

name
string
required

The display name of the billable metric.

sql
string

The SQL query associated with the billable metric. This field is mutually exclusive with aggregation_type, event_type_filter, property_filters, aggregation_key, and group_keys. If provided, these other fields must be omitted.

event_type_filter
object

An optional filtering rule to match the 'event_type' property of an event.

property_filters
object[]

A list of filters to match events to this billable metric. Each filter defines a rule on an event property. All rules must pass for the event to match the billable metric.

aggregation_type
enum<string>

Specifies the type of aggregation performed on matching events.

Available options:
count,
Count,
COUNT,
latest,
Latest,
LATEST,
max,
Max,
MAX,
sum,
Sum,
SUM,
unique,
Unique,
UNIQUE
aggregation_key
string

Specifies the type of aggregation performed on matching events. Required if sql is not provided.

group_keys
string[][]

Property names that are used to group usage costs on an invoice. Each entry represents a set of properties used to slice events into distinct buckets.

custom_fields
object

Custom fields to attach to the billable metric.

Response

200 - application/json

Success

data
object
required