> ## 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 coding tool

> Run Free, Pro and Business tiers for an AI product, with model usage at cost, customer-set spend limits, per-seat Business and a cap for every member.

> **Free:** $1 of model usage a month. **Pro:** $20 a month with $20 of model usage at cost, then usage at cost up to your spend limit. **Business:** $40 a seat a month, $40 of usage per member, then usage at cost up to each member's spend cap. **Annual:** Pro $200 a year, Business \$400 a seat a year, with the month's usage included every month, then usage at cost billed monthly.

Ledger runs the full tier ladder of an AI coding tool: included usage at cost, spend limits customers set themselves, per-seat teams with an allowance and cap for each member, and annual plans that include usage every month.

Model usage is a [dollar balance](https://docs.integrateledger.com/pricing/dollar-balance.md): a credits feature at **1 credit = \$0.0001**, with `creditCost: 1`, so each call sends its real cost in credits as `quantity`. Pro bills usage past its balance as overage, and the customer's spend limit is their overage cap. Business adds a [seat price](https://docs.integrateledger.com/pricing/per-seat.md) and an [entity](https://docs.integrateledger.com/customers/entities.md) per member, which holds that member's included usage and their spend cap.

## The catalog

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

// 1 credit = $0.0001, so $1 = 10,000 credits.
const AT_COST = { overageUnitAmountCents: 1, overageBillingUnits: 100 }; // 1 cent per 100 credits

export default defineCatalog({
	features: [
		feature({ id: "model_usage", name: "Model usage", creditCost: 1 }),
		feature({ id: "seats", name: "Seats", type: "held" }),
	],
	plans: [
		plan({
			id: "free",
			name: "Free",
			monthlyCredits: 10_000, // $1
			priceCents: 0,
			items: [{ featureId: "seats", unlimited: true }],
		}),
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 200_000, // $20
			priceCents: 2000,
			...AT_COST,
			overageCapCents: 10_000, // default spend limit: $100 a month
			items: [{ featureId: "seats", included: 1 }],
		}),
		plan({
			id: "pro_annual",
			name: "Pro (annual)",
			billingInterval: "year",
			resetInterval: "month",
			monthlyCredits: 200_000,
			priceCents: 20_000,
			...AT_COST, // billed each month, not at the renewal
			overageCapCents: 10_000,
			items: [{ featureId: "seats", included: 1 }],
		}),
		plan({
			id: "business",
			name: "Business",
			monthlyCredits: 0, // each member's $40 is their entity's allowance
			priceCents: 4000, // the first seat...
			...AT_COST,
			overageCapCents: 200_000, // the team's monthly ceiling: $2,000
			items: [
				// ...then $40 for each seat after it
				{ featureId: "seats", unlimited: true, price: { model: "per_unit", unitAmountCents: 4000, includedQuantity: 1 } },
			],
		}),
		plan({
			id: "business_annual",
			name: "Business (annual)",
			billingInterval: "year",
			resetInterval: "month",
			monthlyCredits: 0,
			priceCents: 40_000,
			...AT_COST,
			overageCapCents: 200_000,
			items: [
				{ featureId: "seats", unlimited: true, price: { model: "per_unit", unitAmountCents: 40_000, includedQuantity: 1 } },
			],
		}),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "model_usage", "name": "Model usage", "creditCost": 1 },
    { "id": "seats", "name": "Seats", "type": "held" }
  ],
  "plans": [
    { "id": "free", "name": "Free", "monthlyCredits": 10000, "priceCents": 0,
      "items": [{ "featureId": "seats", "unlimited": true }] },
    { "id": "pro", "name": "Pro", "monthlyCredits": 200000, "priceCents": 2000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 100, "overageCapCents": 10000,
      "items": [{ "featureId": "seats", "included": 1 }] },
    { "id": "pro_annual", "name": "Pro (annual)", "billingInterval": "year", "resetInterval": "month",
      "monthlyCredits": 200000, "priceCents": 20000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 100, "overageCapCents": 10000,
      "items": [{ "featureId": "seats", "included": 1 }] },
    { "id": "business", "name": "Business", "monthlyCredits": 0, "priceCents": 4000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 100, "overageCapCents": 200000,
      "items": [{ "featureId": "seats", "unlimited": true,
        "price": { "model": "per_unit", "unitAmountCents": 4000, "includedQuantity": 1 } }] },
    { "id": "business_annual", "name": "Business (annual)", "billingInterval": "year", "resetInterval": "month",
      "monthlyCredits": 0, "priceCents": 40000,
      "overageUnitAmountCents": 1, "overageBillingUnits": 100, "overageCapCents": 200000,
      "items": [{ "featureId": "seats", "unlimited": true,
        "price": { "model": "per_unit", "unitAmountCents": 40000, "includedQuantity": 1 } }] }
  ],
  "addOns": []
}
```

Business's price is its first seat: $40 for the plan with one seat included, then $40 for each seat after it, so it sits above Pro and moving from Pro is an upgrade.

A 5-seat team's first Business invoice is \$200:

| Line | Amount |
| - | - |
| Business, the plan with its first seat | \$40.00 |
| Business – Seats, 1 included | \$0.00 |
| Business – Seats, 4 at \$40 | \$160.00 |
| **Total** | **\$200.00** |

Each of the five members spends their own \$40 of usage, and usage past it bills at cost on the renewal invoice.

The annual plans carry the same usage at cost, with the same monthly caps. Each month's usage past the included amount bills on its own invoice as soon as the month ends ([Annual plans](https://docs.integrateledger.com/pricing/annual.md#overage-billed-monthly)).

## The calls

**Every model call: reserve, run, settle.** On Business, pass the member's `entityId` so the call spends their allowance and counts against their cap. On Free and Pro, leave it out.

```typescript TypeScript theme={"system"}
const CREDITS_PER_DOLLAR = 10_000;
const toCredits = (dollars: number): number => Math.ceil(dollars * CREDITS_PER_DOLLAR);
const entityId = workspace.plan === "business" ? member.id : undefined;

const { allowed, reason } = await billing.checkCredits({
	customerId: workspace.id,
	featureId: "model_usage",
	requestId: run.id,
	entityId,
	reserve: { quantity: toCredits(estimateCostDollars(run)) },
});
if (!allowed) {
	return showLimitReached(reason); // "overage_cap_reached", "entity_cap_reached", ...
}

const result = await runAgent(run);

await billing.trackUsage({
	customerId: workspace.id,
	featureId: "model_usage",
	requestId: run.id,
	entityId,
	quantity: toCredits(result.costDollars),
});
```

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

CREDITS_PER_DOLLAR = 10_000

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

entity_id = member.id if workspace.plan == "business" else None

decision = billing.check_credits(
    customer_id=workspace.id,
    feature_id="model_usage",
    request_id=run.id,
    entity_id=entity_id,
    reserve={"quantity": to_credits(estimate_cost_dollars(run))},
)
if not decision["allowed"]:
    return show_limit_reached(decision["reason"])

result = run_agent(run)

billing.track_usage(
    customer_id=workspace.id,
    feature_id="model_usage",
    request_id=run.id,
    entity_id=entity_id,
    quantity=to_credits(result.cost_dollars),
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/check \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "ws_42", "featureId": "model_usage", "request_id": "run_881", "entityId": "user_7", "reserve": {"quantity": 2500}}'

curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "ws_42", "featureId": "model_usage", "request_id": "run_881", "entityId": "user_7", "quantity": 1834}'
```

**Pro: the customer sets their spend limit.** Save it as their own overage cap. `0` stops usage past the included \$20.

```typescript TypeScript theme={"system"}
await billing.setCustomerOverageCap({ customerId: workspace.id, body: { capCents: 25_000 } }); // $250
```

```python Python theme={"system"}
billing.set_customer_overage_cap(customer_id=workspace.id, cap_cents=25_000)  # $250
```

```bash cURL theme={"system"}
curl "https://api.integrateledger.com/v1/customers/overage-cap?customerId=ws_42" \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"capCents": 25000}'
```

**Business: a member joins.** Add a seat, then give the member an entity: `allowanceCredits` is their $40 of included usage each month, and `capCredits` their spend cap past it, here $60. An admin changing a member's cap calls `upsertEntity` again with the new `capCredits`.

```typescript TypeScript theme={"system"}
await billing.trackUsage({
	customerId: workspace.id,
	featureId: "seats",
	requestId: `seat-add-${membership.id}`,
	quantity: 1,
});
await billing.upsertEntity({
	customerId: workspace.id,
	entityId: member.id,
	allowanceCredits: 400_000, // $40
	capCredits: 600_000, // $60 past it
});
```

```python Python theme={"system"}
billing.track_usage(
    customer_id=workspace.id,
    feature_id="seats",
    request_id=f"seat-add-{membership.id}",
    quantity=1,
)
billing.upsert_entity(
    customer_id=workspace.id,
    entity_id=member.id,
    allowance_credits=400_000,  # $40
    cap_credits=600_000,  # $60 past it
)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/track \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "ws_42", "featureId": "seats", "request_id": "seat-add-m_901", "quantity": 1}'

curl https://api.integrateledger.com/v1/entities \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId": "ws_42", "entityId": "user_7", "allowanceCredits": 400000, "capCredits": 600000}'
```

When a member leaves, track the seat with `quantity: -1` and delete their entity, as in [Seats with credits](https://docs.integrateledger.com/pricing/recipes/seats-with-credits.md#the-calls). Once a member's allowance and cap are spent, that member stops at their cap while the rest of the team keeps working:

```json Response theme={"system"}
{
  "allowed": false,
  "availableCredits": 0,
  "creditCost": 1,
  "reason": "entity_cap_reached",
  "plan": { "id": "business", "name": "Business", "status": "active" }
}
```

**Moving between tiers.** Attach `free` at signup. Free to Pro or Business is an [attach](https://docs.integrateledger.com/billing/checkout-and-attach.md); the team's seats, counted on Free, are billed on Business's first invoice. Pro to Business, and monthly to annual, are [upgrades](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md).

## Rules

* **Entities need a `billing:write` key,** because an allowance is credits on top of the plan. [Entities](https://docs.integrateledger.com/customers/entities.md) has how members spend.
* **Every member gets the full allowance.** A member added late in the month gets the full \$40; their seat is prorated by Stripe ([Seats with credits](https://docs.integrateledger.com/pricing/recipes/seats-with-credits.md#rules)).
* **Annual plans include usage each month.** The year's invoice grants the first month, and each later month arrives with the first call in it. Usage past it bills on a monthly invoice ([Annual plans](https://docs.integrateledger.com/pricing/annual.md)).
* **Spend limits and the team ceiling** are overage caps. [Overage](https://docs.integrateledger.com/pricing/overage.md#which-cap-applies) has which one applies.
* **Units.** [Prepaid dollar balance](https://docs.integrateledger.com/pricing/dollar-balance.md#rules) has the credit scale and its limits.

## Related

* [Prepaid dollar balance](https://docs.integrateledger.com/pricing/dollar-balance.md): usage at cost on one plan, or prepaid.
* [Seats with credits](https://docs.integrateledger.com/pricing/recipes/seats-with-credits.md): per-member allowances in full.
* [Overrides](https://docs.integrateledger.com/customers/overrides.md): a customer's own cap or rate.


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