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

# Credit packs

> Sell credits as a one-time purchase that never expires, to customers on any plan or none.

> **Need more?** 500 credits for \$10, any time. They never expire.

Credit packs let a customer who runs out buy more through Stripe Checkout and keep working, whether they're on a plan or not.

A credit pack is a one-time purchase: a fixed `creditAmount` for a `priceCents`. Customers buy one when they run out before their plan renews, or instead of a plan. Pack credits never expire. A pack adds to the shared credit pool and pays for every [credits](https://docs.integrateledger.com/pricing/credits.md) feature.

**Packs or top-ups.** A pack is a fixed amount at a fixed price, the button that says "500 credits for \$10". To let customers enter any amount, or to buy automatically with their saved card when the balance runs low, use [top-ups and auto top-ups](https://docs.integrateledger.com/pricing/top-ups.md). An auto top-up can buy one of your packs.

**One thing, two names.** In `ledger.config.ts`, packs go in `creditPacks`. The JSON file and the API call them *add-ons*: `addOns`, each with `type: "credit_pack"`, served at `/v1/add-ons` and sold with `addOnId`. The TypeScript config also accepts `addOns`; use one of the two names in a file.

## The catalog

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

export default defineCatalog({
	features: [feature({ id: "generate_image", name: "Generate an image", creditCost: 1 })],
	plans: [plan({ id: "pro", name: "Pro", monthlyCredits: 1000, priceCents: 2000 })],
	creditPacks: [
		creditPack({ id: "credits_500", name: "Top-up", creditAmount: 500, priceCents: 1000 }),
	],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [{ "id": "generate_image", "name": "Generate an image", "creditCost": 1 }],
  "plans": [{ "id": "pro", "name": "Pro", "monthlyCredits": 1000, "priceCents": 2000 }],
  "addOns": [
    { "id": "credits_500", "name": "Top-up", "type": "credit_pack", "creditAmount": 500, "priceCents": 1000 }
  ]
}
```

Ledger prices each pack's Checkout when it opens, so a pack needs no Stripe product synced ahead of time.

## Sell it

Offer the pack when `check` returns `allowed: false` with `reason: "insufficient_credits"`, or `track` returns `409 insufficient_credits`. To offer it before they run out, listen for the [`balance.low`](https://docs.integrateledger.com/webhooks#low-and-depleted-balances) webhook: it fires when a use takes the balance to or below your threshold. Customers on any plan, or none, can buy one. Attach it with `addOnId` and redirect to Checkout:

```typescript TypeScript theme={"system"}
const purchase = await billing.attach({ customerId, addOnId: "credits_500" });
if ("checkoutUrl" in purchase) {
	return res.redirect(303, purchase.checkoutUrl);
}
```

```python Python theme={"system"}
purchase = billing.attach(customer_id=customer_id, add_on_id="credits_500")
return redirect(purchase["checkoutUrl"], 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" \
  -d '{"customerId": "user_123", "addOnId": "credits_500"}'
```

The response is `{ checkoutUrl, addOnPurchaseId }`. Ledger grants the credits when Stripe's signed `checkout.session.completed` event confirms the payment; Stripe also sends the customer an invoice with a line such as "Top-up – 500 credits". The next `check` shows them in `availableCredits`. `GET /v1/customers/purchases` lists the purchase history. [Checkout and attach](https://docs.integrateledger.com/billing/checkout-and-attach.md) covers redirects and testing.

Packs can also be managed in the dashboard under **Add-ons**, or with the [add-on endpoints](https://docs.integrateledger.com/api-reference/add-ons/create.md).

## Rules

* **`creditAmount` is a whole number above 0,** and `priceCents` is above 0.
* **Fixed, through Checkout.** A pack sells its `creditAmount` for its `priceCents`, and each attach opens a Stripe Checkout. An [auto top-up](https://docs.integrateledger.com/pricing/top-ups.md#auto-top-up-per-customer) buys a pack with the saved card instead.
* **Spend order.** [Balances](https://docs.integrateledger.com/concepts/balances.md#spend-order-for-credits) says when pack credits are spent.
* **One open pack Checkout at a time.** Attaching the same pack returns the same URL. Attaching a different pack expires the unpaid Checkout and opens a new one, and returns `409 purchase_pending` while the first one is being paid. Stripe expires an unpaid Checkout after 24 hours.
* **Prices lock while a Checkout is open.** Changing the pack's `creditAmount` or `priceCents` returns `409 purchase_pending` until it completes or expires. Renaming is fine.
* **Removing a pack from the file archives it.** It stops new sales, and a Checkout already open can still complete.
* **Refunds happen in Stripe.** A full refund expires the pack's unused credits; credits already spent stay spent, so the balance never goes negative. A partial refund leaves the credits as they are. A lost dispute expires the unused credits as a full refund does. See [Renewals and lifecycle](https://docs.integrateledger.com/billing/renewals-and-lifecycle.md).

## Related

* [Credits](https://docs.integrateledger.com/pricing/credits.md): the features packs pay for.
* [Top-ups and auto top-ups](https://docs.integrateledger.com/pricing/top-ups.md): any amount, or bought automatically when the balance runs low.
* [Overage](https://docs.integrateledger.com/pricing/overage.md): bill extra credits later instead of selling them up front.
* [Lifetime plans](https://docs.integrateledger.com/pricing/lifetime.md): credits that never expire, sold as a plan.


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