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

# Recurring add-ons

> Grow revenue from existing customers by selling extra credits, bigger allowances, higher limits or extra features every period, on the same invoice as their plan.

> **Pro, plus 10,000 extra credits for \$20 a month.**

Grow revenue from customers you already have: sell extra credits, a bigger allowance, a higher limit or a feature such as SSO that renews with their plan, on the bill they already pay.

A recurring add-on is a plan with `addOn: true`. Beside a paid base plan, it goes on the customer's existing Stripe bill: attaching it charges a prorated amount for the rest of the period, and from the next renewal the one invoice carries the plan and the add-on. A customer on a free plan, or on none, can buy it too: it [starts a bill of its own](#sell-an-add-on-before-a-paid-plan), which their paid plan joins later. Its credits and allowances are granted when that invoice is paid, and again at each renewal. Its features count in [check and track](https://docs.integrateledger.com/customers/check-and-track.md) beside the plan's from then on.

**Add-ons or credit packs.** An add-on recurs every period until the plan ends. A [credit pack](https://docs.integrateledger.com/pricing/credit-packs.md) is bought once, through Checkout, and its credits never expire.

## The catalog

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

export default defineCatalog({
	features: [
		feature({ id: "generate_image", name: "Generate an image", creditCost: 1 }),
		feature({ id: "messages", name: "Messages", type: "metered" }),
	],
	plans: [
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 1000,
			priceCents: 2000,
			items: [{ featureId: "messages", included: 500 }],
		}),
		plan({
			id: "extra_credits",
			name: "Extra credits",
			monthlyCredits: 10000,
			priceCents: 2000,
			addOn: true,
			maxQuantity: 5,
		}),
		plan({
			id: "more_messages",
			name: "More messages",
			monthlyCredits: 0,
			priceCents: 1000,
			addOn: true,
			items: [{ featureId: "messages", included: 1000 }],
		}),
	],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "generate_image", "name": "Generate an image", "creditCost": 1 },
    { "id": "messages", "name": "Messages", "type": "metered" }
  ],
  "plans": [
    { "id": "pro", "name": "Pro", "monthlyCredits": 1000, "priceCents": 2000,
      "items": [{ "featureId": "messages", "included": 500 }] },
    { "id": "extra_credits", "name": "Extra credits", "monthlyCredits": 10000,
      "priceCents": 2000, "addOn": true, "maxQuantity": 5 },
    { "id": "more_messages", "name": "More messages", "monthlyCredits": 0,
      "priceCents": 1000, "addOn": true,
      "items": [{ "featureId": "messages", "included": 1000 }] }
  ]
}
```

| Field | What it sets |
| - | - |
| `addOn` | `true` makes the plan an add-on: attached beside a base plan, never moved to with an upgrade or downgrade |
| `maxQuantity` | How many of the add-on one customer may hold at once. Defaults to `1` |
| `priceCents`, `billingInterval` | The price per unit, per month or year. The add-on joins the customer's bill of the same interval |
| `monthlyCredits` | Credits added to the shared pool each period, per unit held |
| `items` | Any feature: a `metered` item adds its `included` units to the allowance, a `held` item adds to the limit, and a `boolean` item turns the feature on, each per unit held |

An add-on is published, synced to Stripe and versioned like any plan, and `GET /v1/plans` lists it with `addOn` and `maxQuantity`.

## Attach it

Attach the add-on with its `planId` and an `Idempotency-Key` header, as for an [upgrade](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md). Save the key when the customer confirms, and send it again on a retry: the same key answers the same change, and charges once. `quantity` is how many to add on top of any the customer holds, 1 by default.

```typescript TypeScript theme={"system"}
const change = await billing.attach(
	{ customerId, planId: "extra_credits", quantity: 1 },
	{ headers: { "Idempotency-Key": `add_on_${purchase.id}` } }, // saved when the customer confirmed
);
if ("itemChangeId" in change && change.paymentUrl) {
	return res.redirect(303, change.paymentUrl);
}
```

```python Python theme={"system"}
change = billing.attach(
    customer_id=customer_id,
    plan_id="extra_credits",
    quantity=1,
    idempotency_key=f"add_on_{purchase.id}",  # saved when the customer confirmed
)
if "itemChangeId" in change and change.get("paymentUrl"):
    return redirect(change["paymentUrl"], code=303)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/billing/attach \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: add_on_pc_125" \
  -d '{"customerId": "user_123", "planId": "extra_credits", "quantity": 1}'
```

```json Response theme={"system"}
{
  "itemChangeId": 31,
  "status": "applied",
  "paymentUrl": null,
  "item": { "planId": "extra_credits", "quantity": 1 }
}
```

| `status` | What it means |
| - | - |
| `applied` | Paid. The add-on and its prorated grants are the customer's; `item.quantity` is how many they hold now |
| `pending_payment` | The card was declined or needs the customer. Send them to `paymentUrl`; nothing changes until it's paid, for up to 23 hours |
| `processing` | Stripe hasn't settled the invoice. Retry with the same key |
| `closed` | It was never paid (declined and expired, or replaced). Nothing changed |

Attaching the same add-on again raises its quantity, up to `maxQuantity`.

## How it bills and grants

* **One bill.** The add-on is an item on the customer's existing Stripe subscription, not a second subscription. Attaching it charges one invoice at once, to the saved card.
* **Prorated now.** That invoice charges the add-on's price for the unused share of the current period. A raise in quantity charges only for the units added.
* **Granted when paid.** Once the invoice is paid, Ledger grants the added units' credits and allowances, times the unused share of the period, rounded down. Halfway through the month, Extra credits charges about \$10 and grants 5,000 credits.
* **Full at renewal.** Each renewal invoice bills the plan and the add-on together, and grants the add-on's credits and allowances in full, per unit held, beside the plan's.
* **Unpaid renewals.** If a renewal isn't paid, the add-on's grants for that period end with the plan's, and come back if it's paid later. A refund or dispute of an add-on's invoice is recorded on the customer, as a plan's is.

## Sell an add-on before a paid plan

A customer on your free plan, or on no plan, can buy an add-on straight away: SSO for the free tier, or extra credits before they commit to Pro. With no paid plan billed at the add-on's interval, the attach starts a bill of its own holding only the add-on, paid as a first paid plan is:

| Reply | What it means |
| - | - |
| `{ checkoutUrl, subscriptionId }` | Send the customer to Checkout. The add-on is theirs when it's paid |
| `{ subscriptionId, status: "active" }` | The saved card was charged and the add-on is the customer's |

* **Granted in full.** The bill's first invoice bills the add-on alone and grants its whole period, then each renewal bills and grants it again. A free plan the customer holds stays beside it and renews on its own.
* **The paid plan joins it.** A paid plan billed at the bill's interval, attached later with an `Idempotency-Key`, becomes that bill's base plan, so the customer keeps one invoice. It's a prorated change on the bill, answered like an add-on attach (`{ itemChangeId, status, paymentUrl, item }`). Once it's paid, the plan's credits and metered allowances are granted for the rest of the period, prorated, and the customer's free plan in the plan's group closes. From the next renewal one invoice bills the plan and its add-ons. A plan priced per seat joins with its seats.
* **Another interval, another bill.** A paid plan billed at another interval starts its own bill, as an annual plan beside a monthly add-on does.
* **Listed like any bill.** [List customer subscriptions](https://docs.integrateledger.com/api-reference/customers/subscriptions.md) shows it with `planId: null` and its items, and its `subscription.*` [webhooks](https://docs.integrateledger.com/webhooks.md) carry a null `planId`.
* **It ends with its last add-on.** Cancelling the bill's last add-on ends the bill.

## How it counts in check and track

`check`, `track` and reservations read the customer's plan and every add-on they hold together:

* **Booleans.** A feature is on when the plan or any add-on has it. Sell SSO as an add-on, and `check` on `sso` turns allowed once it's paid.
* **Allowances and limits add up.** Each add-on's `included` counts times its quantity, on top of the plan's. With 3 projects on Pro, a Projects add-on of 5 lifts the limit to 8, and 13 at quantity 2.
* **New features.** An add-on can bring a metered or held feature the plan doesn't have; `track` spends the add-on's grant.
* **Unlimited wins.** An unlimited item on the plan or an add-on makes the feature unlimited.
* **Overage stays the plan's.** Usage past the combined allowance bills at the base plan's overage terms.

## Show what the customer holds

Your billing page reads every add-on the customer holds from the calls it already makes:

* [`GET /v1/customers`](https://docs.integrateledger.com/api-reference/customers/get) lists `plans`: the base plan (`kind: "plan"`) and each recurring add-on (`kind: "add_on"`), with its `group`, `quantity` and `status` (`active`, or `canceling` until the period end). Each feature lists `sources`: the plan and add-ons it comes from, each with its `planId`, `kind` and `included`.
* [List customer subscriptions](https://docs.integrateledger.com/api-reference/customers/subscriptions.md) gives each subscription its `items`, oldest first, with `id`, `planId`, `kind`, `group`, `quantity`, `status` and `endsAt` (set while it's `canceling`). An item's `id` is what cancelling takes.

## Cancel an add-on

Let customers drop an add-on on their own, while their plan carries on. [Cancel a subscription item](https://docs.integrateledger.com/api-reference/customers/cancel-subscription-item.md) ends one add-on, at the period end by default or now:

```typescript TypeScript theme={"system"}
const cancelled = await billing.cancelSubscriptionItem({
	customerId: "user_123",
	itemId: 7, // an id from the subscription's items
	idempotencyKey: `cancel_${request.id}`, // saved when the customer confirmed
	body: { timing: "period_end" },
});
```

```python Python theme={"system"}
cancelled = billing.cancel_subscription_item(
    customer_id="user_123",
    item_id=7,  # an id from the subscription's items
    idempotency_key=f"cancel_{request.id}",  # saved when the customer confirmed
    timing="period_end",
)
```

```bash cURL theme={"system"}
curl "https://api.integrateledger.com/v1/customers/subscription-items/7/cancellation?customerId=user_123" \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Idempotency-Key: cancel_sso_123" \
  -H "Content-Type: application/json" \
  -d '{"timing": "period_end"}'
```

```json Response theme={"system"}
{
  "itemChangeId": 12,
  "timing": "period_end",
  "status": "scheduled",
  "item": { "id": 7, "planId": "sso_addon", "kind": "add_on", "group": "default",
    "quantity": 1, "status": "canceling", "endsAt": "2026-12-07T07:40:38.000Z" }
}
```

* **At the period end** (`timing: "period_end"`, the default): the item turns `canceling`, its features and credits last until `endsAt`, and the renewal bills the plan without it. The subscription's discounts carry on to the renewal.
* **Now** (`timing: "immediately"`): the item ends at once, with its credits and features, and Stripe stops billing it. Nothing is refunded or credited.
* **Safe to retry.** The same `Idempotency-Key` answers the same cancellation, and cancelling an add-on already `canceling` returns that cancellation.

## Change the base plan

Customers holding add-ons upgrade and downgrade their base plan as usual: the add-ons stay on the bill with their grants and discounts, and only the base plan is prorated. See [With add-ons](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md#with-add-ons).

## When the plan ends

An add-on runs as long as the bill it's on. When the plan ends, by [cancelling now](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md#cancel-now), at the end of the period, or when Stripe's retries give up, the add-on ends with it: its credits and allowances end with the plan's, and its features stop counting in check and track. While the plan is set to cancel at the period end, the add-on runs to that end.

## Rules

* **An add-on bills at its interval.** It joins the customer's paid bill billed at that interval, a monthly add-on beside a monthly plan and a yearly one beside an annual plan, or starts its own bill when there's none.
* **One bill per add-on.** More of an add-on the customer holds goes on the bill that holds it (`409 add_on_needs_paid_bill`).
* **One purchase at a time.** While another Checkout or a new add-on bill is being paid for, the attach waits for it (`409 purchase_pending`).
* **Add-ons are the customer's.** An attach with `entityId` is refused (`400 invalid_request`).
* **A base plan joins an add-on bill that has none.** A bill with a base plan, or a customer holding a paid plan, trial or lifetime plan in the plan's group, answers `409 subscription_exists`; a plan with [seat licenses](https://docs.integrateledger.com/pricing/seat-licenses.md) answers `400 license_attach_unavailable`.
* **A ready card for a change on a bill.** The customer has a saved card in Stripe, a zero Stripe balance and no pending invoice items (`400 ineligible_stripe_adjustment`).
* **A yearly add-on resets yearly.** One that bills yearly and resets monthly is refused at attach (`400 add_on_attach_unavailable`); set `resetInterval: "year"`.
* **Overage lives on the base plan.** An add-on's credits and items carry no overage prices (`add_on_overage_unsupported`).
* **It recurs.** An add-on bills each month or year; a push refuses `billingInterval: "one_off"` (`add_on_must_recur`). Sell a one-time purchase as a [credit pack](https://docs.integrateledger.com/pricing/credit-packs.md).
* **`maxQuantity` is for add-ons.** A push refuses it on a base plan (`max_quantity_add_ons_only`), and a base plan attach takes only `quantity: 1`.
* **Up to `maxQuantity`.** An attach that would take the customer past it is refused (`409 add_on_limit_reached`).
* **One change at a time.** While an add-on change waits for payment, the bill takes no upgrade, downgrade or other add-on change, and while an add-on is canceling at the period end, it takes an upgrade only (`409 subscription_change_pending`).
* **Cancelling is for add-ons.** The base plan's item is cancelled with [Stop or resume renewal](https://docs.integrateledger.com/api-reference/customers/cancellation.md) (`400 item_not_cancellable`), and a bill with a downgrade scheduled takes an item cancellation once the downgrade is cancelled (`409 downgrade_scheduled`).
* **Attach an add-on without a promotion code.** It bills on the existing bill rather than through Checkout, so `promotionCode` returns `400 invalid_request` and `allowPromotionCodes` has no effect.
* **Add-ons are attached, never upgraded or downgraded to** (`400 add_on_attach_unavailable`).
* **A base plan with seats, licenses or prepaid units moves on a bill without add-ons** (`400 ineligible_stripe_subscription`).

## Errors

| Status | `error` | Meaning and fix |
| - | - | - |
| `400` | `idempotency_key_required`, `invalid_idempotency_key` | Send an `Idempotency-Key` header: printable ASCII without spaces, up to 255 characters. |
| `400` | `add_on_attach_unavailable` | The add-on bills yearly and resets monthly, or an upgrade or downgrade targets an add-on. |
| `400` | `ineligible_stripe_adjustment` | Stripe needs a saved card, a zero balance and no pending invoice items to charge the add-on. |
| `400` | `ineligible_stripe_subscription` | Stripe has a schedule, a pause or a billing setting on the subscription that Ledger didn't set, or an item at another interval: clear it in Stripe, then try again. Or a base plan with seats, licenses or prepaid units is moving beside an add-on: remove the add-on, then try again. |
| `400` | `stripe_plan_mismatch` | Stripe's subscription holds a different quantity of the add-on than Ledger does. |
| `400` | `invalid_request` | An add-on was sent with `entityId`. Attach it for the customer. |
| `400` | `item_not_cancellable` | The item is the base plan. Stop its renewal with [Stop or resume renewal](https://docs.integrateledger.com/api-reference/customers/cancellation.md). |
| `404` | `customer_not_found`, `plan_not_found` | No such customer, or no add-on with this `planId` in this environment. |
| `404` | `item_not_found` | No subscription item with this `id` belongs to the customer. |
| `409` | `item_ended` | The item has already ended. |
| `409` | `add_on_needs_paid_bill` | The customer holds this add-on on another bill. Raise or cancel it on the bill that holds it. |
| `409` | `purchase_pending` | Another Checkout or a new add-on bill is still being paid for. Retry once it completes. |
| `409` | `subscription_exists` | The add-on bill already has a base plan, or the customer holds a paid plan, trial or lifetime plan in the plan's group. Upgrade instead. |
| `409` | `add_on_limit_reached` | The customer would hold more than `maxQuantity`. |
| `409` | `subscription_change_pending` | Another change on the bill is waiting. Retry once it's paid or closed. |
| `409` | `downgrade_scheduled`, `cancellation_scheduled` | The plan is set to downgrade or cancel at the period end. |
| `409` | `plan_not_synced` | The add-on is still syncing to Stripe. Retry once the plan shows **Synced**. |
| `409` | `idempotency_key_mismatch` | This key was used for a different attach in the last 24 hours. Use a new key. |
| `502` | `stripe_item_change_failed` | Stripe was unavailable or refused. Retry with the same key. |
| `503` | `item_change_reconciliation_required` | Retry with the same key. Includes `itemChangeId`. |

Every attach error is in [Errors](https://docs.integrateledger.com/errors.md#billing).

## Related

* [Credit packs](https://docs.integrateledger.com/pricing/credit-packs.md): extra credits bought once.
* [Plans and items](https://docs.integrateledger.com/concepts/plans-and-items.md): every plan field.
* [Upgrades and downgrades](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md): moving between base plans.


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