Creates a billing meter.
Parameters
- default_
aggregationobjectRequired The default settings to aggregate a meter’s events with.
- default_aggregation.
formulaenumRequired Specifies how events are aggregated. Allowed values are
count
to count the number of events,sum
to sum each event’s value andlast
to take the last event’s value in the window.Possible enum valuescount
Count the number of events.
last
Take the last event’s value in the window.
sum
Sum each event’s value.
- display_
namestringRequired The meter’s name. Not visible to the customer.
- event_
namestringRequired The name of the meter event to record usage for. Corresponds with the
event_
field on meter events.name - customer_
mappingobject Fields that specify how to map a meter event to a customer.
- customer_mapping.
event_ payload_ keystringRequired The key in the meter event payload to use for mapping the event to a customer.
- customer_mapping.
typeenumRequired The method for mapping a meter event to a customer. Must be
by_
.id Possible enum valuesby_
id Map a meter event to a customer by passing a customer ID in the event’s payload.
- event_
time_ windowenum The time window which meter events have been pre-aggregated for, if any.
Possible enum valuesday
Events are pre-aggregated in daily buckets.
hour
Events are pre-aggregated in hourly buckets.
- value_
settingsobject Fields that specify how to calculate a meter event’s value.
- value_settings.
event_ payload_ keystringRequired The key in the usage event payload to use as the value for this meter. For example, if the event payload contains usage on a
bytes_
field, then set the event_payload_key to “bytes_used”.used
Returns
Returns a billing meter.
{ "id": "mtr_test_61Q8nQMqIFK9fRQmr41CMAXJrFdZ5MnA", "object": "billing.meter", "created": 1704824589, "customer_mapping": { "type": "by_id", "event_payload_key": "stripe_customer_id" }, "default_aggregation": { "formula": "sum" }, "display_name": "Search API Calls", "event_name": "ai_search_api", "event_time_window": null, "livemode": false, "status": "active", "status_transitions": { "deactivated_at": null }, "updated": 1704824589, "value_settings": { "event_payload_key": "value" }}