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

# Free credits, then pay as you go

> Give every signup free credits that work before a card, then turn them into a paying pay-as-you-go customer billed monthly.

> **Start free:** 1,000 credits on signup, no card needed. **Then pay as you go:** 1 cent per 10 credits, billed monthly.

Ledger lets every signup use your product on free credits from the first minute, then converts them to monthly pay as you go the moment they add a card. Two pieces: a one-time grant of free credits at signup, and a \$0 [pay-as-you-go](https://docs.integrateledger.com/pricing/pay-as-you-go.md) plan the customer moves to when they add a card. A customer with no plan can spend credits on credits features ([Customers without a plan](https://docs.integrateledger.com/concepts/balances.md#customers-without-a-plan)), so the free credits work before any plan exists.

## The catalog

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

export default defineCatalog({
	features: [
		feature({ id: "search", name: "Search", creditCost: 1 }),
		feature({ id: "extract", name: "Extract a page", creditCost: 5 }),
	],
	plans: [
		plan({
			id: "payg",
			name: "Pay as you go",
			monthlyCredits: 0,
			priceCents: 0,
			overageUnitAmountCents: 1,
			overageBillingUnits: 10,
			overageCapCents: 50_000, // $500 a month until you raise it per customer
		}),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "search", "name": "Search", "creditCost": 1 },
    { "id": "extract", "name": "Extract a page", "creditCost": 5 }
  ],
  "plans": [
    { "id": "payg", "name": "Pay as you go", "monthlyCredits": 0, "priceCents": 0,
      "overageUnitAmountCents": 1, "overageBillingUnits": 10, "overageCapCents": 50000 }
  ],
  "addOns": []
}
```

## The calls

**1. On signup, grant the free credits.** A [balance adjustment](https://docs.integrateledger.com/customers/balance-adjustments.md) with no plan attached. Key it on the customer so a retried signup grants once.

```typescript TypeScript theme={"system"}
await billing.createOrGetCustomer({ customerId: user.id });
await billing.adjustCustomerBalance({
	customerId: user.id,
	body: {
		credits: 1000,
		reason: "Signup credits",
		idempotencyKey: `signup-${user.id}`,
	},
});
```

```python Python theme={"system"}
billing.create_or_get_customer(customer_id=user.id)
billing.adjust_customer_balance(
    customer_id=user.id,
    credits=1000,
    reason="Signup credits",
    idempotency_key=f"signup-{user.id}",
)
```

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

curl "https://api.integrateledger.com/v1/customers/balance-adjustments?customerId=user_123" \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"credits": 1000, "reason": "Signup credits", "idempotencyKey": "signup-user_123"}'
```

**2. Check and track as usual.** Each search spends 1 of the free credits. When they no longer cover a use, `check` answers:

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

**3. On `no_plan`, ask for a card.** Attach the pay-as-you-go plan. For a customer with no saved card, attach returns a Checkout URL that collects the card for a \$0 total:

```typescript TypeScript theme={"system"}
const result = await billing.attach({ customerId: user.id, planId: "payg" });
if ("checkoutUrl" in result) {
	return res.redirect(303, result.checkoutUrl);
}
```

```python Python theme={"system"}
result = billing.attach(customer_id=user.id, plan_id="payg")
if "checkoutUrl" in result:
    return redirect(result["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", "planId": "payg"}'
```

Once Stripe confirms, the customer spends their 3 leftover free credits, then every use bills on the monthly renewal: a month of 4,200 credits of overage bills \$4.20.

## Rules

* **Signup credits outlive the plan change.** An adjustment stands apart from plan grants, so the customer keeps it when pay as you go is attached. Add `expiresAt` for credits that should lapse, such as a 30-day trial budget.
* **For a monthly free allowance, use a free plan.** A \$0 plan with `monthlyCredits: 1000` and no overage gives 1,000 credits every month. Moving to pay as you go then ends the free plan, and its unspent credits expire when the payment is confirmed ([Free plans](https://docs.integrateledger.com/pricing/free-plans.md)).
* **Free credits spend on credits features.** Metered, held and boolean features answer `no_plan` until a plan is attached. For metered usage, attach a free plan with a metered item at signup.
* **Before the plan, free credits are the limit.** A use they don't cover gets `no_plan` from `check` and `409 insufficient_credits` from `track`.
* **Caps.** [Which cap applies](https://docs.integrateledger.com/pricing/overage.md#which-cap-applies) has the plan default and each customer's own cap.
* **Grant signup credits after email verification,** or keep them small, so throwaway accounts gain little.

## Related

* [Pay as you go](https://docs.integrateledger.com/pricing/pay-as-you-go.md): the \$0 plan with overage.
* [Balance adjustments](https://docs.integrateledger.com/customers/balance-adjustments.md): grants by hand or from code.
* [Free plans](https://docs.integrateledger.com/pricing/free-plans.md): a recurring free allowance.


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