Skip to content
  • Auto
  • Light
  • Dark
Talk to an expert

Create

Create a billable metric
v1.billable_metrics.create(BillableMetricCreateParams**kwargs) -> dataIDBillableMetricCreateResponse
post/v1/billable-metrics/create

Creates a new Billable Metric.

Parameters
namestr

The display name of the billable metric.

aggregation_keystr
optional

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

aggregation_typeliteral
optional
Literal["COUNT", "LATEST", "MAX", 2 more]

Specifies the type of aggregation performed on matching events.

Hide ParametersShow Parameters
"COUNT"
"LATEST"
"MAX"
"SUM"
"UNIQUE"
custom_fieldsDict[str, str]
optional
Dict[str, str]

Custom fields to attach to the billable metric.

event_type_filterin_valueslistnot_in_valueslistEventTypeFilter
optional

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

group_keysiterable
optional
Iterable[List[str]]

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.

property_filtersiterable
optional
namestrexistsboolin_valueslistnot_in_valueslistIterable[namestrexistsboolin_valueslistnot_in_valueslistPropertyFilter]

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.

Hide ParametersShow Parameters
namestr

The name of the event property.

existsbool
optional

Determines whether the property must exist in the event. If true, only events with this property will pass the filter. If false, only events without this property will pass the filter. If null or omitted, the existence of the property is optional.

in_valueslist
optional
Optional[List[str]]

Specifies the allowed values for the property to match an event. An event will pass the filter only if its property value is included in this list. If undefined, all property values will pass the filter. Must be non-empty if present.

not_in_valueslist
optional
Optional[List[str]]

Specifies the values that prevent an event from matching the filter. An event will not pass the filter if its property value is included in this list. If null or empty, all property values will pass the filter. Must be non-empty if present.

sqlstr
optional

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.

Returns
BillableMetricCreateResponseclass
Hide ParametersShow Parameters
dataidstrID
from metronome import Metronome

client = Metronome(
    bearer_token="My Bearer Token",
)
billable_metric = client.v1.billable_metrics.create(
    name="CPU Hours",
    aggregation_key="cpu_hours",
    aggregation_type="SUM",
    event_type_filter={
        "in_values": ["cpu_usage"]
    },
    group_keys=[["region"], ["machine_type"]],
    property_filters=[{
        "name": "cpu_hours",
        "exists": True,
    }, {
        "name": "region",
        "exists": True,
        "in_values": ["EU", "NA"],
    }, {
        "name": "machine_type",
        "exists": True,
        "in_values": ["slow", "fast"],
    }],
)
print(billable_metric.data)
200 Example
{
  "data": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
  }
}