Metering rules
What one unit of a metric costs.
A metering rule prices one billable metric. The rule sets how many millicredits one unit costs.
The price can be flat, per unit, or tiered by how much a customer used. QuotaStack finds the active rule and debits the balance each time a usage event comes in.
Which call do I want?
- You are setting or changing the price of a billable metric →
POST /v1/metering-rulesThis step turns off the old rule and makes the billable metric, if needed. - You want the current or past rules for a metric →
GET /v1/metering-rules
List metering rules
/v1/metering-rules | Idempotency-Key | Not used. This is a read. |
|---|---|
| Environment | Sandbox and Live |
| Auth | Tenant API key |
| Writes | Nothing. A read has no side effects. |
| Fires | No webhooks. |
This endpoint lists metering rules, oldest first. Filter by billable_metric_key for one metric’s price history. Add active_only=true to see only the rule charged today.
| Field | Type | Meaning |
|---|---|---|
billable_metric_keyoptional | string | Only rules for this metric key. If you leave it out: You get every rule for this metric. |
active_onlyoptional | boolean | Only the one rule charged today for each metric — the rule with no If you leave it out: You get every rule, old and new. |
cursoroptional | string | Opaque pagination cursor from the previous page's |
limitoptional | integer | Page size. Default 20, max 100. |
{
"data": [
{
"id": "0192f5a4-7c31-7b8e-9a2d-4f6c8e1b3a53",
"billable_metric_key": "chat_message",
"cost_type": "per_unit",
"base_cost": 0,
"unit_cost": 500,
"tier_config": null,
"effective_from": "2026-07-20T09:00:00Z",
"effective_until": null,
"metadata": {},
"created_at": "2026-07-20T09:00:00Z",
"updated_at": "2026-07-20T09:00:00Z"
}
],
"pagination": {
"has_more": false,
"next_cursor": null
}
} | Field | Type | Meaning |
|---|---|---|
datarequired | array | One entry per metering rule, oldest first. Old rules stay in the list unless you add |
paginationrequired | object | Cursor-based pagination envelope. Returned on every list endpoint. No |
See also
Create a metering rule
/v1/metering-rules | Idempotency-Key | Required. Returns 422 without it. |
|---|---|
| Environment | Sandbox and Live |
| Auth | Tenant API key |
| Writes | One new metering rule, active right away. If the metric had an old rule, QuotaStack turns it off. If the billable metric itself did not exist yet, QuotaStack makes one. |
| Fires | No webhooks. |
Creating a rule sets the price for one billable metric. If billable_metric_key does not match one that exists, QuotaStack makes a plain one — type metered, named after the key. If a rule is already active for this key, QuotaStack turns it off first. Only one rule stays active per metric.
| Field | Type | Meaning |
|---|---|---|
Idempotency-Keyrequired | string | A unique string you choose, up to 256 characters. It stops a retry from doing the work twice. This header is required on every POST and PATCH. Leave it out and the request fails with Send the same key twice and QuotaStack replays the first response. The second call's status and body match the first, and the response carries Derive the key from the business event rather than a random value, so a retry from anywhere reuses it — for example |
| Field | Type | Meaning |
|---|---|---|
billable_metric_keyrequired | string | The key of the billable metric this rule prices. If you leave it out: QuotaStack rejects the call. This field is required. |
cost_typerequired | string | How QuotaStack turns units used into a charge. If you leave it out: QuotaStack rejects the call. This field is required.
|
base_costoptional | integer (int64) | The flat charge for a Unit: millicredits, where 1 credit is 1000 millicredits. If you leave it out: Required for |
unit_costoptional | integer (int64) | The charge per unit for a Unit: millicredits, where 1 credit is 1000 millicredits. If you leave it out: Required, and must be over zero, for |
tier_configoptional | unknown | The price ladder for a If you leave it out: Required for |
metadataoptional | object | Your own key-value tags. QuotaStack stores them unchanged and returns them on every read. If you leave it out: Left out, QuotaStack stores |
{
"billable_metric_key": "chat_message",
"cost_type": "per_unit",
"unit_cost": 500
} {
"id": "0192f5a4-7c31-7b8e-9a2d-4f6c8e1b3a53",
"billable_metric_key": "chat_message",
"cost_type": "per_unit",
"base_cost": 0,
"unit_cost": 500,
"tier_config": null,
"effective_from": "2026-07-20T09:00:00Z",
"effective_until": null,
"metadata": {},
"created_at": "2026-07-20T09:00:00Z",
"updated_at": "2026-07-20T09:00:00Z"
} | Field | Type | Meaning |
|---|---|---|
idrequired | string (uuid) | |
tenant_idrequired | string (uuid) | |
billable_metric_keyrequired | string | The key of the billable metric this rule prices. |
cost_typerequired | string | How QuotaStack turns units used into a charge.
|
base_costoptional | integer (int64) | The flat charge for a Unit: millicredits, where 1 credit is 1000 millicredits. |
unit_costoptional | integer (int64) | The charge per unit for a Unit: millicredits, where 1 credit is 1000 millicredits. |
tier_configoptional | unknown | The price ladder for a |
effective_fromrequired | string (date-time) | When this rule started pricing its metric, the moment you made it. |
effective_untiloptional | string (date-time) |
|
metadatarequired | object | Your own key-value tags, unchanged since the last write. |
created_atrequired | string (date-time) | |
updated_atrequired | string (date-time) |
Errors
422—billable_metric_keyorcost_typeis missing, or a fieldcost_typeneeds is wrong:base_costforflat, aunit_costover zero forper_unit, or a validtier_configfortiered. The response names the field. validation-error
See also
Loading…