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

# Prepaid dollar balance

> Sell usage in dollars at exactly what it costs you, down to fractions of a cent, as a plan's monthly balance or a prepaid wallet.

> **Pro:** $20 a month, including $20 of usage at cost. Past that, usage at cost on your next invoice, up to $100 a month. Top up $10 any time.
>
> **Prepaid:** buy $10 or $50 of usage, spend it at cost, top up when it runs low.

A dollar balance lets you pass any cost through to customers at its exact price, from GPU seconds to third-party API calls, and show them a wallet in dollars. It is a [credits](https://docs.integrateledger.com/pricing/credits.md) balance where each credit is worth a fixed fraction of a dollar. This page uses \*\*1 credit = $0.0001** (a hundredth of a cent), so $1 is 10,000 credits and a model call that costs you \$0.0123 spends 123 credits. The feature costs 1 credit a unit (`creditCost: 1`), so your backend works out each use's real cost in credits and sends it as `quantity`.

For model calls, use [AI usage in dollars](https://docs.integrateledger.com/pricing/ai-credits.md): send each call's model and tokens, and Ledger prices them from its model price table plus your markup. This page is for costs you work out yourself.

The same catalog serves two ways to sell it: a monthly plan that includes a balance and bills usage past it, or [prepaid balance only](#prepaid-balance-only), where customers top up a wallet and never hold a plan.

## The catalog

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

// 1 credit = $0.0001, so $1 = 10,000 credits.
export default defineCatalog({
	// Top-ups of $5 to $500, at 10,000 credits a dollar.
	topUps: { minCents: 500, maxCents: 50_000, creditsPerUsd: 10_000 },
	features: [
		// 1 credit a unit: every call sends its real cost in credits as quantity.
		feature({ id: "model_call", name: "Model call", creditCost: 1 }),
	],
	plans: [
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 200_000, // $20 of usage
			priceCents: 2000,
			overageUnitAmountCents: 1, // 1 cent...
			overageBillingUnits: 100, // ...per 100 credits: $0.0001 a credit, at cost
			overageCapCents: 10_000, // $100 a month
		}),
	],
	creditPacks: [
		creditPack({ id: "usd_10", name: "$10 of usage", creditAmount: 100_000, priceCents: 1000 }),
		creditPack({ id: "usd_50", name: "$50 of usage", creditAmount: 500_000, priceCents: 5000 }),
	],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "topUps": { "minCents": 500, "maxCents": 50000, "creditsPerUsd": 10000 },
  "features": [{ "id": "model_call", "name": "Model call", "creditCost": 1 }],
  "plans": [
    { "id": "pro", "name": "Pro", "monthlyCredits": 200000, "priceCents": 2000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 100, "overageCapCents": 10000 }
  ],
  "addOns": [
    { "id": "usd_10", "name": "$10 of usage", "type": "credit_pack", "creditAmount": 100000, "priceCents": 1000 },
    { "id": "usd_50", "name": "$50 of usage", "type": "credit_pack", "creditAmount": 500000, "priceCents": 5000 }
  ]
}
```

## The calls

Reserve your estimate with the check as `reserve.quantity`, then settle with the real cost as the track's `quantity`, under the same `request_id`. The reservation confirms a \$2 run fits before it starts; a plain `check` asks about one unit, 1 credit.

```typescript TypeScript theme={"system"}
const CREDITS_PER_DOLLAR = 10_000;
const toCredits = (dollars: number): number => Math.ceil(dollars * CREDITS_PER_DOLLAR);

const { allowed } = await billing.checkCredits({
	customerId: team.id,
	featureId: "model_call",
	requestId: call.id,
	reserve: { quantity: toCredits(estimateCostDollars(prompt)) },
});
if (!allowed) {
	return showTopUpOffer();
}

const result = await runModel(prompt); // result.costDollars: 0.0123

await billing.trackUsage({
	customerId: team.id,
	featureId: "model_call",
	requestId: call.id,
	quantity: toCredits(result.costDollars), // 123
});
```

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

CREDITS_PER_DOLLAR = 10_000

def to_credits(dollars: float) -> int:
    return math.ceil(dollars * CREDITS_PER_DOLLAR)

decision = billing.check_credits(
    customer_id=team.id,
    feature_id="model_call",
    request_id=call.id,
    reserve={"quantity": to_credits(estimate_cost_dollars(prompt))},
)
if not decision["allowed"]:
    return show_top_up_offer()

result = run_model(prompt)  # result.cost_dollars: 0.0123

billing.track_usage(
    customer_id=team.id,
    feature_id="model_call",
    request_id=call.id,
    quantity=to_credits(result.cost_dollars),  # 123
)
```

```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": "model_call", "request_id": "call_0001", "reserve": {"quantity": 500}}'

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

The track charges 123 credits and releases the rest of the hold:

```json Response theme={"system"}
{
  "allowed": true,
  "availableCredits": 199877,
  "chargedCredits": 123,
  "overageCredits": 0,
  "overageRemainingCents": 10000,
  "request_id": "call_0001",
  "idempotent": false,
  "settled": true
}
```

Show the balance as dollars: `availableCredits / 10_000`, here \$19.99. For short calls you don't estimate, skip `reserve` and send the track's `quantity` alone. Reserve whenever a run costs you real money, so Ledger confirms the balance covers it before the work runs. [Reservations](https://docs.integrateledger.com/customers/reservations.md) has the rules.

## Per-unit prices

When each unit has a list price, such as a GPU-second or a megabyte, put the price in the feature's `creditCost` and send the units as `quantity`: Ledger multiplies them, and the rate lives in your catalog, not your code. Pick a scale where every rate is a whole number of credits. At \*\*1 credit = $0.000001**, a GPU-second at $0.000025 is `creditCost: 25` and a megabyte of egress at \$0.000004 is `creditCost: 4`; overage at cost is 1 cent per 10,000 credits.

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

// 1 credit = $0.000001, so $1 = 1,000,000 credits.
export default defineCatalog({
	features: [
		feature({ id: "gpu_second", name: "GPU second", creditCost: 25 }), // $0.000025
		feature({ id: "egress_mb", name: "Egress MB", creditCost: 4 }), // $0.000004
	],
	plans: [
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 0,
			priceCents: 5000,
			overageUnitAmountCents: 1, // 1 cent...
			overageBillingUnits: 10_000, // ...per 10,000 credits: $0.000001 a credit
		}),
	],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "gpu_second", "name": "GPU second", "creditCost": 25 },
    { "id": "egress_mb", "name": "Egress MB", "creditCost": 4 }
  ],
  "plans": [
    { "id": "pro", "name": "Pro", "monthlyCredits": 0, "priceCents": 5000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 10000 }
  ],
  "addOns": []
}
```

A 90-second run on two GPUs tracks `gpu_second` with `quantity: 180` and spends 4,500 credits (\$0.0045). Count a unit that comes in fractions, such as megapixels, in whole units rounded up, or in a smaller unit with its own `creditCost`.

## Prepaid balance only

> **Prepaid:** buy $10 or $50 of usage, spend it at cost, top up when it runs low.

Customers top up a prepaid wallet and use your product with no plan at all. A customer with top-up or pack credits can use every credits feature while their credits cover the cost ([Customers without a plan](https://docs.integrateledger.com/concepts/balances.md#customers-without-a-plan)). Nothing bills later: the balance is exactly what they can spend.

**1. Sell balance.** Let the customer top up any amount within the catalog's `topUps`: $5 to $500 here, at 10,000 credits a dollar, so \$10 buys 100,000 credits. Checkout opens by default, and the credits land when Stripe confirms the payment; `paymentMethod: "saved"` charges the saved card at once.

```typescript TypeScript theme={"system"}
const topUp = await billing.topUp({ customerId: team.id, amountCents: 1000 });
if (topUp.checkoutUrl) {
	return res.redirect(303, topUp.checkoutUrl);
}
```

```python Python theme={"system"}
top_up = billing.top_up(customer_id=team.id, amount_cents=1000)
return redirect(top_up["checkoutUrl"], code=303)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/billing/top-up \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "team_42", "amountCents": 1000}'
```

The invoice reads "Credit top-up: 100,000 credits". Fixed buttons ("$10", "$50") can be [credit packs](https://docs.integrateledger.com/pricing/credit-packs.md) instead, attached with `addOnId`.

**2. Spend it at cost.** The same check with `reserve` and track with the real cost as `quantity`, as [above](#the-calls).

**3. Offer a top-up when it runs out.** When the balance doesn't cover a reservation, `check` answers `allowed: false` with `reason: "no_plan"`:

```json Response theme={"system"}
{
  "allowed": false,
  "availableCredits": 200,
  "creditCost": 1,
  "reason": "no_plan",
  "plan": null
}
```

Show the balance, \$0.02 here, and the top-up form. A track that costs more than the balance returns `409 insufficient_credits` and charges nothing.

**4. Top up automatically when it runs low.** Save an [auto top-up](https://docs.integrateledger.com/pricing/top-ups.md#auto-top-up-per-customer) for the customer, and Ledger charges their saved card when the balance falls below the threshold: here $25 whenever it drops under $1 (10,000 credits), at most 4 times a month.

```typescript TypeScript theme={"system"}
await billing.setCustomerAutoTopUp({
	customerId: team.id,
	body: {
		autoTopUp: { enabled: true, thresholdCredits: 10_000, amountCents: 2500, maxPerPeriod: 4 },
	},
});
```

```python Python theme={"system"}
billing.set_customer_auto_top_up(
    customer_id=team.id,
    auto_top_up={"enabled": True, "thresholdCredits": 10_000, "amountCents": 2500, "maxPerPeriod": 4},
)
```

```bash cURL theme={"system"}
curl "https://api.integrateledger.com/v1/customers/auto-top-up?customerId=team_42" \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"autoTopUp": {"enabled": true, "thresholdCredits": 10000, "amountCents": 2500, "maxPerPeriod": 4}}'
```

Give each feature its own `creditCost` when some uses have a fixed price: `feature({ id: "web_search", name: "Web search", creditCost: 100 })` spends 1 cent a search from the same balance: each track sends the number of searches as `quantity`, and Ledger applies the 100 credits.

## Rules

* **Pick the scale for your cheapest use.** A credit is the smallest price, and every per-unit rate is a whole `creditCost` at that scale. At $0.0001 a credit, a $0.00002 call costs 1 credit. Rounding each use up with `ceil` adds at most one credit per use.
* **Each amount holds up to 2,147,483,647 credits,** which is $214,748.36 at this scale. That covers a feature's `creditCost`, a plan's `monthlyCredits`, a pack's `creditAmount`, a reservation, and `quantity × creditCost` on one check or track. One [balance adjustment](https://docs.integrateledger.com/customers/balance-adjustments.md) adds or removes at most 1,000,000,000 credits ($100,000). A balance can be larger: it's the sum of its grants.
* **`quantity` is a whole number** of the feature's units, 1 or more on a track without a reservation. Round each cost up to whole credits before you send it.
* **Overage on Pro.** [Overage](https://docs.integrateledger.com/pricing/overage.md) has the cap and how a period's overage rounds.
* **Invoices count credits.** Stripe lines read "Pro – overage, 15,000 credits", and Checkout describes overage per 100 credits. Name packs in dollars ("\$10 of usage") so the purchase line reads well.
* **Spend order.** [Balances](https://docs.integrateledger.com/concepts/balances.md#spend-order-for-credits) has the order a plan's balance, packs and overage are spent in.

## Related

* [AI usage in dollars](https://docs.integrateledger.com/pricing/ai-credits.md): model calls priced from their tokens, natively.
* [Credits](https://docs.integrateledger.com/pricing/credits.md): the shared balance this pattern builds on.
* [Reservations](https://docs.integrateledger.com/customers/reservations.md): hold an estimate, settle the real cost.
* [Top-ups and auto top-ups](https://docs.integrateledger.com/pricing/top-ups.md): any amount, and automatic top-ups when the balance runs low.
* [Credit packs](https://docs.integrateledger.com/pricing/credit-packs.md): selling balance in fixed amounts.
* [AI coding tool](https://docs.integrateledger.com/pricing/recipes/ai-coding-tool.md): a dollar balance across Free, Pro and Business.


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