> ## Documentation Index
> Fetch the complete documentation index at: https://docs.integrateledger.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Metered allowances

> Give each plan its own allowance of every action per period, from a handful to unlimited, enforced on every request.

> **Pro:** 1,000 messages and 50 exports a month. **Business:** unlimited messages, 500 exports.

Metered allowances give every action its own limit on every plan: 50 exports on Pro, 500 on Business, unlimited messages at the top. Ledger enforces each allowance on every request and resets it every period.

A `metered` feature has its own balance per customer: the plan's item grants `included` units at the start of each period, each use spends from it, and what's left ends with the period. Use it when your pricing page counts each action separately. When one balance should cover several actions at different prices, use [credits](https://docs.integrateledger.com/pricing/credits.md) instead.

## The catalog

```ts ledger.config.ts theme={"system"}
import { defineCatalog, feature, plan } from "integrateledger-cli";

export default defineCatalog({
	features: [
		feature({ id: "messages", name: "Messages", type: "metered" }),
		feature({ id: "exports", name: "Exports", type: "metered" }),
	],
	plans: [
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 0,
			priceCents: 2900,
			items: [
				{ featureId: "messages", included: 1000 },
				{ featureId: "exports", included: 50 },
			],
		}),
		plan({
			id: "business",
			name: "Business",
			monthlyCredits: 0,
			priceCents: 9900,
			items: [
				{ featureId: "messages", unlimited: true },
				{ featureId: "exports", included: 500 },
			],
		}),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "messages", "name": "Messages", "type": "metered" },
    { "id": "exports", "name": "Exports", "type": "metered" }
  ],
  "plans": [
    { "id": "pro", "name": "Pro", "monthlyCredits": 0, "priceCents": 2900,
      "items": [{ "featureId": "messages", "included": 1000 }, { "featureId": "exports", "included": 50 }] },
    { "id": "business", "name": "Business", "monthlyCredits": 0, "priceCents": 9900,
      "items": [{ "featureId": "messages", "unlimited": true }, { "featureId": "exports", "included": 500 }] }
  ],
  "addOns": []
}
```

Each item grants `included` units per period (0 or more), or makes the feature `unlimited: true`.

## What check and track return

Check before the action, then track it once it succeeds. Send `quantity` when one use is several units, such as an export of 3 files; it defaults to 1.

```typescript TypeScript theme={"system"}
const { allowed } = await billing.checkCredits({
	customerId: user.id,
	featureId: "exports",
	quantity: files.length,
});
if (!allowed) {
	return showUpgradeOffer();
}

const exportJob = await exportFiles(files);

await billing.trackUsage({
	customerId: user.id,
	featureId: "exports",
	requestId: exportJob.id,
	quantity: files.length,
});
```

```python Python theme={"system"}
decision = billing.check_credits(
    customer_id=user.id, feature_id="exports", quantity=len(files)
)
if not decision["allowed"]:
    return show_upgrade_offer()

export_job = export_files(files)

billing.track_usage(
    customer_id=user.id,
    feature_id="exports",
    request_id=export_job.id,
    quantity=len(files),
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/check \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "user_123", "featureId": "exports", "quantity": 3}'

curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "user_123", "featureId": "exports", "request_id": "export_0042", "quantity": 3}'
```

The track answers with the feature's balance after the use:

```json Response theme={"system"}
{
  "allowed": true,
  "availableCredits": 0,
  "chargedCredits": 0,
  "overageCredits": 0,
  "overageRemainingCents": null,
  "request_id": "export_0042",
  "idempotent": false,
  "featureType": "metered",
  "chargedQuantity": 3,
  "balance": { "included": 50, "used": 13, "remaining": 37, "overageAllowed": false, "resetsAt": "2026-12-23T09:14:00.000Z" }
}
```

* `balance.included` is what this period granted, `used` what it has spent, `remaining` what's left after any [reservations](https://docs.integrateledger.com/customers/reservations.md), and `resetsAt` when the allowance ends.
* `chargedQuantity` is the units this track applied. Credit fields stay at 0: a metered use spends no credits ([why](https://docs.integrateledger.com/customers/check-and-track.md#credit-fields-on-other-feature-types)).
* When `quantity` is more than `remaining`, `check` answers `allowed: false` with `reason: "limit_reached"`, and `track` is refused with `409 limit_reached` and the `balance`. Nothing is charged: a use is applied whole or not at all.
* A feature the customer's plan has no item for answers `feature_not_in_plan`, and a customer with no plan `no_plan`. [Check and track](https://docs.integrateledger.com/customers/check-and-track.md) has the order of refusals.

## Durations and sizes

`quantity` is a whole number. To bill time or data, track it in a small whole unit and set the price per a larger one with `overageBillingUnits`.

> **Compute:** 10 hours a month, then $0.40 an hour. **Storage transfer:** 50 GB a month, then $0.09 a GB.

Track compute in seconds and transfer in megabytes. `overageBillingUnits: 3600` prices compute per hour, and `overageBillingUnits: 1024` prices transfer per GB:

```ts ledger.config.ts theme={"system"}
import { defineCatalog, feature, plan } from "integrateledger-cli";

export default defineCatalog({
	features: [
		feature({ id: "compute_seconds", name: "Compute (seconds)", type: "metered" }),
		feature({ id: "transfer_mb", name: "Transfer (MB)", type: "metered" }),
	],
	plans: [
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 0,
			priceCents: 2000,
			items: [
				// 10 hours, then 40 cents per 3,600 seconds
				{ featureId: "compute_seconds", included: 36_000, overageUnitAmountCents: 40, overageBillingUnits: 3600 },
				// 50 GB, then 9 cents per 1,024 MB
				{ featureId: "transfer_mb", included: 51_200, overageUnitAmountCents: 9, overageBillingUnits: 1024 },
			],
		}),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "compute_seconds", "name": "Compute (seconds)", "type": "metered" },
    { "id": "transfer_mb", "name": "Transfer (MB)", "type": "metered" }
  ],
  "plans": [
    { "id": "pro", "name": "Pro", "monthlyCredits": 0, "priceCents": 2000,
      "items": [
        { "featureId": "compute_seconds", "included": 36000, "overageUnitAmountCents": 40, "overageBillingUnits": 3600 },
        { "featureId": "transfer_mb", "included": 51200, "overageUnitAmountCents": 9, "overageBillingUnits": 1024 }
      ] }
  ],
  "addOns": []
}
```

Track a job when it ends, with its duration rounded up to whole seconds, and a download with its size rounded up to whole megabytes:

```typescript TypeScript theme={"system"}
await billing.trackUsage({
	customerId: user.id,
	featureId: "compute_seconds",
	requestId: job.id,
	quantity: Math.ceil(job.durationMs / 1000), // 754
});

await billing.trackUsage({
	customerId: user.id,
	featureId: "transfer_mb",
	requestId: download.id,
	quantity: Math.ceil(download.bytes / (1024 * 1024)), // 38
});
```

```python Python theme={"system"}
import math

billing.track_usage(
    customer_id=user.id,
    feature_id="compute_seconds",
    request_id=job.id,
    quantity=math.ceil(job.duration_ms / 1000),  # 754
)

billing.track_usage(
    customer_id=user.id,
    feature_id="transfer_mb",
    request_id=download.id,
    quantity=math.ceil(download.bytes / (1024 * 1024)),  # 38
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "user_123", "featureId": "compute_seconds", "request_id": "job_3104", "quantity": 754}'

curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "user_123", "featureId": "transfer_mb", "request_id": "dl_8812", "quantity": 38}'
```

The period's overage is added up first, then rounded up to whole billing units: 40,000 seconds past the 10 hours bill `ceil(40,000 ÷ 3,600)` = 12 hours, \$4.80. [Prices below a cent](https://docs.integrateledger.com/pricing/overage.md#prices-below-a-cent) has the rule. For a job that runs for hours, [reserve](https://docs.integrateledger.com/customers/reservations.md) its expected seconds with the check and settle the real duration with the track.

## Unlimited

An item with `unlimited: true` always allows the use and never debits anything. `check` answers `unlimited: true`, and the balance counts uses without a limit:

```json Response theme={"system"}
{
  "allowed": true,
  "availableCredits": 0,
  "creditCost": 0,
  "featureType": "metered",
  "unlimited": true,
  "balance": { "included": null, "used": 8412, "remaining": null, "overageAllowed": false, "resetsAt": "2026-12-23T09:14:00.000Z" }
}
```

Keep tracking an unlimited feature: every use is recorded as a [usage event](https://docs.integrateledger.com/concepts/usage-events.md), so you can see who uses what.

## Rules

* **Each item takes `included` or `unlimited: true`.** Metered features take no `creditCost`, and unlimited items take no overage price.
* **`quantity` is a whole number** from 1 to 2,147,483,647 on a metered feature.
* **The allowance lasts one period.** Unused units end when the period ends, and the next period grants `included` again. On an [annual plan](https://docs.integrateledger.com/pricing/annual.md) the period is a month unless `resetInterval` is `year`.
* **A feature keeps its type.** To change type, create a new feature; changing `type` on an existing one returns `409 feature_type_locked`.
* **Items are part of the plan version.** Changing `included` publishes a new [plan version](https://docs.integrateledger.com/billing/plan-versions.md); current subscribers keep their allowance.
* **One item per feature per plan.** List each feature once in a plan.
* **Grants and expiry.** [Balances](https://docs.integrateledger.com/concepts/balances.md) explains when an allowance arrives and ends.

## Related

* [Overage](https://docs.integrateledger.com/pricing/overage.md): bill the units past `included` instead of refusing them.
* [Pay as you go](https://docs.integrateledger.com/pricing/pay-as-you-go.md): `included: 0`, every unit billed.
* [Credits](https://docs.integrateledger.com/pricing/credits.md): one shared balance across actions.
* [Reservations](https://docs.integrateledger.com/customers/reservations.md): hold units before long-running work.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.