A .usage file says what your product counts, how it adds up and what each plan charges. Money is exact: decimals with 18 places, never floats.
Try it in the playgroundWhat your product counts, and the events your services send when it happens.
What numbers count. Units are checked like dimensions: credit/token times token is credit, and credits plus seats doesn't compile.
unit token, credit, seatThe money unit. Each invoice line is rounded to its minor unit (cents for USD), half away from zero.
currency USDA closed set of values, such as models, countries or GPU types.
type Model = "gpt-4o" | "small"One usage event: its fields with their types, units and defaults.
struct llm_call {
model: Model
input_tokens: int<token>
cached: bool = false
user_id: string
}How events add up over a billing period.
A rate card keyed by a type. Every value needs a rate (or a default), or the schema doesn't compile.
table input_rate[Model]: credit/token {
"gpt-4o": 0.0025
"small": 0.0002
}Adds events up: sum, count, count_distinct (people, seats), max, min, avg and latest. Over one struct, several (a | b) or all (*), with where filters and by breakdowns.
meter credits: credit = sum(input_tokens * input_rate[model]) from llm_call where cached == false by modelA formula over meters, such as a free allowance, with the same unit checks.
metric billable: credit = max(credits - 1000 credit, 0 credit)What a plan charges for what was measured.
Turns meters and metrics into an invoice: flat fees, charges and a minimum spend.
plan pro "Pro" {
fee "Pro subscription" 49 USD
charge credits "AI credits" { price 0.002 USD/credit }
minimum 99 USD
}A price per unit, a package (per started 1,000), graduated tiers (each tier its own rate) or volume tiers (one rate set by the total), with an included allowance and a minimum or maximum per charge.
charge credits "AI credits" {
included 50000 credit
tiered graduated {
up to 500000 credit at 0.0015 USD/credit
above at 0.001 USD/credit
}
}A cap on a meter or metric: a spend cap, a rate limit, seats or workspaces. Per minute, hour, day or month (UTC calendar windows), or over the whole history.
limit credits 200000 credit per monthMonths of made-up usage and the numbers they must produce.
Run by cusage test, by every server before it starts, and in the playground on each change. The calculators offer them as starting points.
test "a quiet month" {
plan pro
events {
llm_call { model: "small", input_tokens: 2000, user_id: "ana" } x 100
}
expect total == 99 USD
}Everything above in one file that compiles and whose test passes.
unit token, credit, seat
currency USD
type Model = "gpt-4o" | "small"
struct llm_call {
model: Model
input_tokens: int<token>
user_id: string
}
table input_rate[Model]: credit/token {
"gpt-4o": 0.0025
"small": 0.0002
}
meter credits: credit = sum(input_tokens * input_rate[model]) from llm_call by model
meter seats: seat = count_distinct(user_id) from llm_call
/** The first 1,000 credits are free. */
metric billable: credit = max(credits - 1000 credit, 0 credit)
plan starter "Starter" {
charge billable "AI credits" { price 0.002 USD/credit }
charge seats "Seats" { price 8 USD/seat }
limit credits 200000 credit per month
}
test "a small month" {
plan starter
events {
llm_call { model: "gpt-4o", input_tokens: 400000, user_id: "ana" } x 2
}
expect credits == 2000 credit
expect total == 10 USD
}