METRONOME_BEARER_TOKEN
. In this example, it’ll be passed as an argument to the constructor instead.
usage
, allows you to pass in multiple event payloads in a request. Metronome supports passing up to 100 events within a single request.transaction_id
, provides Metronome with the unique idempotency key for the event. Metronome deduplicates based on this ID, allowing you to send events potentially many times without worrying about double-charging your customers.timestamp
, the time when the event occurred. Send in events with any timestamp up to 34 days in the past.customer_id
, the customer ID in Metronome or any other customer identifier you want to define. For example, customer email or internal customer ID within your platform. Later steps show how to define these custom identifiers for your customers in Metronome.event_type
, an arbitrary string that you can define within the request.properties
, an arbitrary set of data to include within the payload for metering and grouping within Metronome.name
, the name to give your billable metric.event_type_filter
, the set of values that matched against the event_type
field in the usage events. Omit this if you want to match against all event types.property_filters
, the set of properties you expect to find on the usage payload. If you mark a property as exists=True
in the billable metric definition and the property not found on the payload, the billable metric won’t match to the event.aggregation_key
, used to define the property with the relevant value to aggregate on.aggregation_type
, used to tell Metronome how to aggregate the values specified by the aggregation_key
as they come into the system. Supported operations are SUM
, COUNT
, and MAX
.group_keys
, used to define properties to separate the usage data into different buckets, similar to a group by
clause in SQL. The example above set user_id
as a group key, so you can display the invoice separated by the amount of tokens that each user consumed.name
, the display name for the customer in Metronome.ingest_aliases
, a list of identifiers used to match a Metronome customer against a usage event. Ingest aliases are useful if you want to start flowing in usage for customers before they’re created in Metronome. To do this, use the ID from your application’s customer table.team@example.com
, so the previous event gets matched correctly. After you set the customer up for invoicing in the next section, this event contributes to their current invoice.
langModel4
at a rate of $0.50 per 1 million tokens.
The first step is to create a product
for your billable metric. A product is where you configure the billable metric for presentation on the eventual invoice. It’s also where you can associate the metric with items in external systems, like the Stripe customer ID. Learn about the configuration options for products in the API docs for the create product endpoint.
Create a product associated to the billable metric, similar to this example:
name
, the name of the product that appears on the invoice. Often a cleaned presentation of the billable metric name (Language Model 4 Tokens (millions)
versus langModel4
).type
, determines how a product gets charged. Supported types include usage
, fixed
, composite
(for percentages of other usage products), and subscription
.billable_metric_id
, associates the product presentation with an existing billable metric.presentation_group_key
, used to group line items on your invoice by a given property value.quantity_conversion
, used to multiply or divide quantities displayed on the final invoice. For example, charge by million tokens (mTok) while sending in usage at the individual token level.entitled
, a boolean that indicates whether a rate shows up by default on a customer’s invoice. If False
, it won’t appear on a customer’s invoice unless overridden at the contract level.rate_type
, used to configure how a rate gets applied as usage flows in. Supported values include FLAT
or TIERED
.price
, the rate itself, by default in cents.starting_at
, used to set the time when the rate goes into effect. To evolve your rates over time, set starting_at
and ending_before
dates to ensure smooth pricing updates.starting_at
date. Usage data from the current period is visible to the DRAFT
invoice. Line items on draft invoices update seconds after Metronome receives usage data.
For the new contract from the example, the previously sent usage of 1 million tokens got applied.