> ## 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.

# AI usage in dollars

> Bill every model call in dollars at its real cost plus your markup, priced by Ledger from the call's model and tokens.

> **Pro:** $20 a month, including $10 of AI usage, then usage at cost.

Sell AI usage in dollars, at cost or with a margin, across Anthropic, OpenAI, Google and more. Your backend reports each model call's model and tokens. Ledger prices them from its model price table (or your own prices), adds your markup, and charges the dollars to the customer's balance. You never work out a cost yourself.

## The catalog

An `ai_tokens` feature prices each call. The catalog's `creditsPerUsd` makes the shared credit pool a dollar balance: at 100,000 credits per dollar (the recommended value), one credit is $0.00001 and `monthlyCredits: 1_000_000` is $10.

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

export default defineCatalog({
	creditsPerUsd: 100_000, // one credit is $0.00001
	features: [
		feature({ id: "chat", name: "Chat", type: "ai_tokens", markupPercent: 30 }),
	],
	plans: [
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 1_000_000, // $10 of AI usage
			priceCents: 2000,
			overageUnitAmountCents: 1, // 1 cent...
			overageBillingUnits: 1000, // ...per 1,000 credits: usage at cost
		}),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "creditsPerUsd": 100000,
  "features": [
    { "id": "chat", "name": "Chat", "type": "ai_tokens", "markupPercent": 30 }
  ],
  "plans": [
    { "id": "pro", "name": "Pro", "monthlyCredits": 1000000, "priceCents": 2000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 1000 }
  ],
  "addOns": []
}
```

Balances store whole credits; every response shows dollars beside them. `creditsPerUsd` is one of 100, 1,000, 10,000, 100,000 or 1,000,000. Other features on a dollar pool keep their fixed `creditCost`, now readable as dollars: an image at `creditCost: 4000` costs \$0.04.

## The shared pool or its own balance

An AI feature spends one of two balances, set when it's created and locked afterwards:

| `balance` | Spends | Plan items |
| - | - | - |
| `pool` (default) | The shared credit pool, like a [credits](https://docs.integrateledger.com/pricing/credits.md) feature. Needs the catalog's `creditsPerUsd`. | Only `unlimited: true` |
| `own` | Its own dollars, granted each period by a plan item, apart from the pool. Set `creditsPerUsd` on the feature. | `included` (credits of its balance) or `unlimited: true`, with an optional overage price, like a [metered](https://docs.integrateledger.com/pricing/metered.md) item |

```ts ledger.config.ts theme={"system"}
features: [
	feature({ id: "export_pdf", name: "Export a PDF", creditCost: 3 }),
	feature({
		id: "assistant",
		name: "Assistant",
		type: "ai_tokens",
		balance: "own",
		creditsPerUsd: 100_000,
		markupPercent: 30,
		providerMarkupPercent: { openai: 20 },
		modelMarkupPercent: { "anthropic/claude-sonnet-4-5": 15, "openai/gpt-4o-mini": -100 },
	}),
],
plans: [
	plan({
		id: "pro",
		name: "Pro",
		monthlyCredits: 1000, // action credits, for export_pdf
		priceCents: 2000,
		items: [
			{
				featureId: "assistant",
				included: 1_000_000, // $10 of assistant usage
				overageUnitAmountCents: 1,
				overageBillingUnits: 1000,
			},
		],
	}),
],
```

```json ledger.catalog.json theme={"system"}
"features": [
  { "id": "export_pdf", "name": "Export a PDF", "creditCost": 3 },
  { "id": "assistant", "name": "Assistant", "type": "ai_tokens", "balance": "own",
    "creditsPerUsd": 100000, "markupPercent": 30,
    "providerMarkupPercent": { "openai": 20 },
    "modelMarkupPercent": { "anthropic/claude-sonnet-4-5": 15, "openai/gpt-4o-mini": -100 } }
],
"plans": [
  { "id": "pro", "name": "Pro", "monthlyCredits": 1000, "priceCents": 2000,
    "items": [{ "featureId": "assistant", "included": 1000000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 1000 }] }
]
```

This Pro has 1,000 action credits in the pool and \$10 of assistant usage of its own, then assistant usage at cost. AI calls never touch the action credits: an own-balance feature always spends its own balance, and the plans that sell it give it an item.

## Markup

A percent with up to two decimals, from -100 to 1,000. Ledger uses the first that applies:

1. `modelMarkupPercent` for the call's model ID;
2. `providerMarkupPercent` for its provider (the model ID up to the first `/`);
3. the feature's `markupPercent`;
4. 0.

-100 makes a model free: the call is recorded and nothing is charged. A new markup applies from the next call; earlier calls keep the markup they were charged at.

## Model prices

Ledger keeps a model price table, generated from [models.dev](https://models.dev) for Anthropic, OpenAI, Google, xAI, Mistral, DeepSeek and OpenRouter. A daily job proposes every price change for review, and the table applies to calls after it deploys. Model IDs are `provider/model` as models.dev lists them: `anthropic/claude-sonnet-4-5`, `openai/gpt-4o`, `openrouter/anthropic/claude-opus-4.6`. Dated IDs work where models.dev lists them. An unknown ID returns `400 model_not_found`, so a typo never prices at 0.

Prices are per million tokens, for input, output, cache reads, cache writes, reasoning, audio input and audio output. A pool a model doesn't price uses its input rate (cache, audio input) or output rate (reasoning, audio output). Some models have a long-context tier: when a call's input, cache read and cache write tokens pass its threshold (200,000 tokens, for example), every pool uses the tier's rates.

Every charge records the table's version and the rates it used, so a past charge stays explainable after prices change.

### Your own prices

The catalog's `models` prices your own `custom/` models, or sets a negotiated rate for a listed one. Dollars per million tokens, as decimal strings:

```json ledger.catalog.json theme={"system"}
"models": [
  { "id": "custom/my-finetune", "inputUsdPerMTok": "0.5", "outputUsdPerMTok": "1.5" },
  { "id": "openai/gpt-4o", "inputUsdPerMTok": "2", "outputUsdPerMTok": "8", "cacheReadUsdPerMTok": "1" }
]
```

A `custom/` model sets input and output; the other pools are optional and use the same rates as above. A charge at your own price records `priceVersion: "org"`. [Get the catalog](https://docs.integrateledger.com/api-reference/catalog/get.md) reads `creditsPerUsd` and `models` back.

## Track a call

Send the model and the call's tokens with the track. Each pool counts its tokens once: `input` excludes cached tokens, `output` excludes reasoning tokens.

```typescript TypeScript theme={"system"}
const message = await anthropic.messages.create({ model: "claude-sonnet-4-5", ...request });

await billing.trackUsage({
	customerId: team.id,
	featureId: "chat",
	requestId: message.id,
	model: "anthropic/claude-sonnet-4-5",
	tokens: {
		input: message.usage.input_tokens,
		output: message.usage.output_tokens,
		cacheRead: message.usage.cache_read_input_tokens ?? 0,
		cacheWrite: message.usage.cache_creation_input_tokens ?? 0,
	},
});
```

```python Python theme={"system"}
message = anthropic.messages.create(model="claude-sonnet-4-5", **request)

billing.track_usage(
    customer_id=team.id,
    feature_id="chat",
    request_id=message.id,
    model="anthropic/claude-sonnet-4-5",
    tokens={
        "input": message.usage.input_tokens,
        "output": message.usage.output_tokens,
        "cache_read": message.usage.cache_read_input_tokens or 0,
        "cache_write": message.usage.cache_creation_input_tokens or 0,
    },
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "team_42", "featureId": "chat", "request_id": "msg_01H",
       "model": "anthropic/claude-sonnet-4-5",
       "tokens": {"input": 1200, "output": 350, "cacheRead": 8000, "cacheWrite": 0}}'
```

```json Response theme={"system"}
{
  "allowed": true,
  "availableCredits": 998537,
  "availableUsd": "9.98537",
  "chargedCredits": 1463,
  "chargedUsd": "0.01463",
  "uncoveredCredits": 0,
  "featureType": "ai_tokens",
  "ai": {
    "model": "anthropic/claude-sonnet-4-5",
    "baseCostUsd": "0.011250",
    "markupPercent": 30,
    "markupSource": "feature",
    "costUsd": "0.014625",
    "priceVersion": "2026-11-23.1"
  },
  "request_id": "msg_01H",
  "idempotent": false
}
```

* **`model` and `tokens` are the amount.** Ledger prices them, as it prices `quantity` at `creditCost` on other features.
* **`tokens.input` and `tokens.output` are required;** `cacheRead`, `cacheWrite`, `reasoning`, `audioInput` and `audioOutput` are optional.
* **`chargedUsd` is the charge** for any AI feature, on either balance. On the pool, `chargedCredits` is the same charge in credits. On an own balance, `chargedCredits` is 0 (the pool is untouched), `chargedQuantity` is the credits charged to the feature, and `balance` carries `includedUsd`, `usedUsd` and `remainingUsd`.
* **Rounding.** A call is rounded up once, to a whole credit: at 100,000 per dollar, by under \$0.00001. A call that costs anything is never charged 0.
* **Retries.** A repeat `request_id` returns the first call's charge and its `ai` block, whatever tokens the retry carries.

### A call past the balance

A model call has already happened when it's tracked, so Ledger charges what the balance and any overage under the cap cover, and reports the rest as `uncoveredCredits`, with `200`. The call is recorded with both numbers, and the next check is refused, so an empty balance stops the next call before it runs.

## Check and reserve

`check` takes the same `model` and `tokens` as an estimate: prompt tokens plus `max_tokens` of output. Without one, an AI check asks whether anything is left, at a cost of 1 credit. On the pool, `creditCost` is the priced estimate; on an own balance it's 0 and the estimate is compared with `balance.remaining`. The response adds `ai`, `costUsd`, and `availableUsd` on the pool.

With `reserve`, the hold is the priced estimate. The track that settles it sends the real model and tokens under the same `request_id`: up to the hold it always succeeds, and above the hold it charges what fits and reports the rest as `uncoveredCredits`.

```typescript TypeScript theme={"system"}
const { allowed } = await billing.checkCredits({
	customerId: team.id,
	featureId: "chat",
	requestId: run.id,
	model: "anthropic/claude-sonnet-4-5",
	tokens: { input: promptTokens, output: MAX_OUTPUT_TOKENS },
	reserve: {},
});
if (!allowed) {
	return showTopUpOffer();
}
```

```python Python theme={"system"}
decision = billing.check_credits(
    customer_id=team.id,
    feature_id="chat",
    request_id=run.id,
    model="anthropic/claude-sonnet-4-5",
    tokens={"input": prompt_tokens, "output": MAX_OUTPUT_TOKENS},
    reserve={},
)
if not decision["allowed"]:
    return show_top_up_offer()
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/check \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "team_42", "featureId": "chat", "request_id": "run_0001",
       "model": "anthropic/claude-sonnet-4-5",
       "tokens": {"input": 4000, "output": 8000}, "reserve": {}}'
```

## Entities

On a pool feature, a call with `entityId` spends the entity's `allowanceCredits` first, then the shared pool under its `capCredits`, as any credits track; on a dollar pool those amounts are dollars too. On an own balance the entity is recorded, and the customer's feature balance is spent. See [Entities](https://docs.integrateledger.com/customers/entities.md).

## Overage and invoices

"Usage at cost" is `overageUnitAmountCents: 1, overageBillingUnits: 1000` at 100,000 credits per dollar: one cent per cent of usage. Overage counts whole billing units, so keep the unit at a cent: at `100` per `100000`, $2.35 of usage would count as $3.00, against the cap and on the invoice. It works on the plan (the shared pool) or on an own-balance item, and one overage cap in cents covers all of a customer's overage.

On a dollar balance the invoice line shows dollars: "Pro – overage, $12.35" for the pool, "Pro – Assistant overage, $12.35" for an own balance. [Overage](https://docs.integrateledger.com/pricing/overage.md) has the cap and the rest of the rules.

## Mapping provider usage

| Provider field | Ledger pool |
| - | - |
| Anthropic `usage.input_tokens` | `input` (already excludes cache) |
| Anthropic `usage.cache_read_input_tokens` | `cacheRead` |
| Anthropic `usage.cache_creation_input_tokens` | `cacheWrite` |
| Anthropic `usage.output_tokens` | `output` |
| OpenAI `usage.prompt_tokens` − `prompt_tokens_details.cached_tokens` | `input` |
| OpenAI `usage.prompt_tokens_details.cached_tokens` | `cacheRead` |
| OpenAI `usage.completion_tokens` − `completion_tokens_details.reasoning_tokens` | `output` |
| OpenAI `usage.completion_tokens_details.reasoning_tokens` | `reasoning` |
| OpenAI `prompt_tokens_details.audio_tokens`, `completion_tokens_details.audio_tokens` | `audioInput`, `audioOutput` (subtract them from input and output too) |

## The usage log

[`GET /v1/usage`](https://docs.integrateledger.com/api-reference/usage/list) and [`GET /v1/usage/{id}`](https://docs.integrateledger.com/api-reference/usage/event) show each AI call's `ai`: the model, tokens, base cost, markup, cost, price version, and the credits it was priced at, charged and left uncovered.

## Rules

* **Price AI features with `model` and `tokens`.** A track sends them in place of `quantity`, and a reserve sends them as its estimate; a raw `reserve.quantity` returns `400 invalid_request`.
* **Give own-balance features an item** on each plan that sells them; without one the call returns `feature_not_in_plan`.
* **`creditsPerUsd` stays fixed once a balance has grants** (`409 credits_per_usd_locked`), so every customer's balance keeps its value.
* **One grant or charge holds at most 2,147,483,647 credits:** \$21,474.83 at 100,000 per dollar. The catalog refuses a plan, pack or item above that, with the limit in dollars.
* **A feature keeps its `balance`.** To switch between `pool` and `own`, make a new feature.
* **A track refused for its AI fields** charges nothing and logs a failed usage event with the reason.

| Error | When |
| - | - |
| `400 model_not_found` | No price for the model: not in Ledger's table or your catalog's `models` |
| `400 feature_not_ai` | `model` or `tokens` on a feature that isn't `ai_tokens` |
| `400 tokens_required` | An `ai_tokens` track without `model` and `tokens` |
| `400 reserve_estimate_required` | An `ai_tokens` reserve with no `model` and `tokens` estimate |
| `409 credits_per_usd_locked` | A catalog publish that would change `creditsPerUsd` of a balance with grants |

## Related

* [Credits](https://docs.integrateledger.com/pricing/credits.md): the shared pool an AI feature spends by default.
* [Prepaid dollar balance](https://docs.integrateledger.com/pricing/dollar-balance.md): a dollar balance for costs you work out yourself.
* [Reservations](https://docs.integrateledger.com/customers/reservations.md): hold an estimate, settle the real cost.
* [Overage](https://docs.integrateledger.com/pricing/overage.md): the cap and how a period's overage rounds.


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