Skip to navigation

Meters

A meter turns the events you send into the quantities you bill. You send Paid what happened, such as a model call with its token counts, and a meter decides what part of it is billable: every call, the output tokens, or the number of distinct conversations. Meters live in Paid rather than in your code, so you can change what you charge for without changing what you send.

Use a meter to:

Meters are in the meters=v1 private beta: send Paid-Beta: meters=v1 with each request.

How a meter works

A meter does two things to every event you send:

  1. It selects. It reads only the events whose name it lists, and only those that pass its filters.
  2. It measures. It aggregates what it selected over each billing period: it counts the events, or sums, averages or takes the maximum of a field on them.

The result is a quantity in an explicit unit, such as 412000 token, for each customer and billing period. Prices turn that quantity into money or credits.

This page covers event meters, which measure over a billing period. A workflow meter instead groups related events, such as the messages in one support ticket, and measures each group by its outcome.

Create a meter

Lucerne runs a chat app that calls a language model for every message. It sends one chat_message event per reply, with the model call as an inference cost line, and charges for the output tokens. This meter sums them:

Create a meter with a key, the events it reads and how it measures them.

{
"key": "output_tokens",
"name": "Output tokens",
"description": "Output tokens generated for chat replies.",
"eventNames": ["chat_message"],
"measure": {
"type": "events",
"events": {
"aggregation": {
"type": "sum",
"sum": { "path": "cost.inference.outputTokens" }
},
"unit": "token"
}
}
}

Prices and the API refer to the meter by its key or its mtr_ ID. The key is unique on your account and can’t change.

Select events

A meter reads events by name, given in one of two ways:

  • eventNames: exact names, such as ["chat_message"].
  • eventNamePattern: a regular expression for a family of names, such as ^report_.

Event names aren’t registered anywhere, so a name you never send isn’t an error. It shows up as a warning in the meter’s health.

Add filters to narrow the selection. Every filter must hold, and an event without the filtered field doesn’t match:

"filters": [
{ "path": "payload.plan", "op": "eq", "value": "pro" }
]
opHolds when the field
eq, neequals, or doesn’t equal, value
in, notInis, or isn’t, one of the values in value
existsis present (send no value)

Measure

measure.events.aggregation sets how the selected events add up over a billing period:

typeThe meter’s quantity isExample
countthe number of eventsAPI calls
sumthe total of a fieldoutput tokens, pages reviewed
max, minthe largest or smallest value of a fieldpeak concurrent sessions
averagethe mean value of a fieldaverage response size
latestthe most recent value of a fieldstorage in use
uniqueCountthe number of distinct values of a fieldconversations, active users

Every aggregation except count reads one field, named by its path. unit names what the quantity is in, such as token or conversation; for count it defaults to event. A meter’s unit is what’s counted. It’s separate from the currency or credit currency a price charges in.

To bill per conversation instead of per message, count distinct correlation IDs:

"aggregation": { "type": "uniqueCount", "uniqueCount": { "path": "correlationId" } },
"unit": "conversation"

Paths

PathReads
payload.<field>your own event data, such as payload.pages
cost.<type>.<field>a field on the event’s cost lines of that type, summed across lines, such as cost.inference.outputTokens
correlationId, customer, productthe event’s top-level fields

Reading tokens from cost lets you send them once, then both bill them and see what they cost you. To bill input tokens, sum cost.inference.uncachedInputTokens, which Paid calculates. inputTokens also includes cached tokens, which a cache meter may already count.

A value at a path must be an integer or a decimal string, such as "12.5". A JSON number with a fractional part is rejected, because binary floating point can’t represent most decimal amounts exactly.

How it bills

Lucerne prices the meter at $10.00 per million output tokens: a usage price with unitAmount: "1000" (cents) per: "1000000". In November, Northwind’s users get replies totalling 18,450,000 output tokens:

StepValue
Events selected61,500 chat_message events
Meter quantity (sum of cost.inference.outputTokens)18,450,000 token
Price1000¢ per 1,000,000 tokens
Charge18,450,000 × 1000 ÷ 1,000,000 = 18,450¢
Invoice lineOutput tokens: $184.50

Paid calculates the charge exactly and rounds once, to whole cents, on the invoice line.

Split usage by dimension

groupBy splits a meter’s quantity by up to three paths, such as cost.inference.model. Each group gets its own quantity, so a rate card can price each model differently and usage summaries can report on them. A meter with groupBy is priced through a rate card, not a single price.

Check a meter’s health

A meter’s definition lives on the server, so a typo in an event name or a path doesn’t fail when you send events. It shows up in the meter’s health instead:

FieldTells you
lastMatchedAtwhen the meter last selected an event
matchedEvents24hhow many events it selected in the last 24 hours
invalidValues24hhow many had an invalid value at a path it reads
warningsproblems such as a path that has never matched or an event name never sent

Retrieve the meter after your first events arrive, and check matchedEvents24h isn’t 0.

validationMode decides what happens to an event with an invalid value at a path the meter reads. With lenient, the default, the event is stored but not billed by this meter, and counted in invalidValues24h. With strict, the event fails ingestion with a per-item error.

Change or retire a meter

Everything that decides what a meter bills is fixed when you create it, so every past invoice matches its meter. Update a meter to change only its name, description, validationMode and metadata.

To change what’s billed, create a new meter, create prices on it, and amend the orders that should use them.

Archive a meter to stop it measuring. It stays readable, because invoices refer to it. Archiving fails while an active, activating or paused order uses the meter through a price or rate card.

Single-event meters

A third mode, measure.type: "singleEvent", measures each event on its own, such as the characters in each email or the pages in each document. Use it with tierScope: "event" on a price, so tiers apply to each event rather than to the period’s total.

Single-event meters are drafted and may change before they’re released.