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

> Convert new customers with free trials of any recurring paid plan, with a card that bills at the end or no card at all.

> **Pro:** \$29 a month, 1,000 credits. 14 days free, 200 credits to try it.

Let new customers try a paid plan free, with a card held to convert them automatically at the end, or with no card at all to lower the barrier to signing up.

A plan's `trial` gives new customers the plan free for a number of days. There are two kinds:

* **With a card** (the default): Checkout or the saved card holds the card, Stripe starts the subscription `trialing`, and the first period is billed when the trial ends.
* **Without a card**: the trial runs in Ledger only, with nothing in Stripe. When it ends, the customer goes back to the free plan they had, or to no plan.

Each customer gets a plan's trial once, across all its versions.

## 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: "exports", name: "Exports", type: "metered" }),
	],
	plans: [
		plan({ id: "free", name: "Free", monthlyCredits: 50, priceCents: 0 }),
		plan({
			id: "pro",
			name: "Pro",
			monthlyCredits: 1000,
			priceCents: 2900,
			trial: { days: 14, credits: 200 },
			items: [{ featureId: "exports", included: 50, trialIncluded: 10 }],
		}),
		plan({
			id: "team",
			name: "Team",
			monthlyCredits: 5000,
			priceCents: 9900,
			trial: { days: 7, cardRequired: false },
		}),
	],
	creditPacks: [],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "generate_image", "name": "Generate an image", "creditCost": 1 },
    { "id": "exports", "name": "Exports", "type": "metered" }
  ],
  "plans": [
    { "id": "free", "name": "Free", "monthlyCredits": 50, "priceCents": 0 },
    { "id": "pro", "name": "Pro", "monthlyCredits": 1000, "priceCents": 2900,
      "trial": { "days": 14, "credits": 200 },
      "items": [{ "featureId": "exports", "included": 50, "trialIncluded": 10 }] },
    { "id": "team", "name": "Team", "monthlyCredits": 5000, "priceCents": 9900,
      "trial": { "days": 7, "cardRequired": false } }
  ],
  "addOns": []
}
```

| Field | Default | What it sets |
| - | - | - |
| `trial.days` | | The trial's length: 1 to 365 days |
| `trial.cardRequired` | `true` | `true`: Stripe holds the card and bills at the end. `false`: no card, Ledger only |
| `trial.onEnd` | `bill` with a card, `revert` without | What happens at the end. A card trial bills, a no-card trial reverts |
| `trial.credits` | `monthlyCredits` | The credits granted for the whole trial |
| `items[].trialIncluded` | `included` | Metered items: the units the trial includes |

A trial's terms are part of the plan's version, so changing them publishes a [new version](https://docs.integrateledger.com/billing/plan-versions.md).

## Start a trial

Attach the plan as usual. If the plan has a trial and the customer hasn't had one of it, the trial starts.

```typescript TypeScript theme={"system"}
const result = await billing.attach({ customerId, planId: "pro" });

if ("checkoutUrl" in result) {
	return res.redirect(303, result.checkoutUrl);
}
// No checkoutUrl: the trial has started on the saved card, or without one.
```

```python Python theme={"system"}
result = billing.attach(customer_id=customer_id, plan_id="pro")

if "checkoutUrl" in result:
    return redirect(result["checkoutUrl"], code=303)
# No checkoutUrl: the trial has started on the saved card, or without one.
```

```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": "pro"}'
```

* **A card trial** attaches like any paid plan: Checkout asks for the card and charges nothing, or the saved card is used. Stripe starts the subscription `trialing` with a \$0 invoice, and Ledger grants the trial's credits and `trialIncluded` units.
* **A no-card trial** starts at once and answers `{ "subscriptionId": 43, "status": "trialing", "trialEndsAt": "2026-12-07T10:00:00.000Z" }`. If the customer was on a free plan, it stops for the trial and comes back at the end.

`trial` on attach replaces the plan's own for this customer:

* `trial: { days, cardRequired, onEnd, credits }` gives this trial, even to a customer who had one before: a sales decision.
* `trial: null` attaches the plan with no trial.

```typescript TypeScript theme={"system"}
await billing.attach({
	customerId,
	planId: "pro",
	trial: { days: 30 }, // or null for no trial
});
```

```python Python theme={"system"}
billing.attach(
    customer_id=customer_id,
    plan_id="pro",
    trial={"days": 30},  # or None for no trial
)
```

```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": "pro", "trial": {"days": 30}}'
```

## During the trial

* **Free means free.** Nothing is billed during a trial. Once the trial's credits are spent, a credit use answers `insufficient_credits`, and a metered use past `trialIncluded` `limit_reached`: a good moment to offer to start the paid plan early.
* **Cancel any time.** [Cancel at the period end](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md#cancel-at-period-end) and a card trial ends with the trial, with no charge. A no-card trial ends at its end anyway.
* **Buy early.** On a no-card trial, attach the plan with `trial: null` to charge now: the trial ends and the paid plan starts.
* **Plan changes follow conversion.** Upgrades and downgrades apply once the trial converts and the plan is `active`.

## When it ends

| Kind | At the trial's end |
| - | - |
| With a card | Stripe bills the first period. Once it's paid, the plan is `active` with its full credits and allowances, and renews from that day. A declined card makes it `past_due`, as with any [failed renewal](https://docs.integrateledger.com/billing/renewals-and-lifecycle.md#past-due). |
| Without a card | The trial ends. The free plan the customer had comes back from that day, with fresh credits, or the customer has no plan. |

## Extend or end a trial

[Change a trial](https://docs.integrateledger.com/api-reference/customers/trial.md) moves its end, or ends it now. A new end adds no credits: the trial's grant lasts until the new end.

```typescript TypeScript theme={"system"}
await billing.changeSubscriptionTrial({
	customerId,
	subscriptionId: 42,
	body: { days: 7 }, // or { trialEndsAt: "2026-12-31T00:00:00Z" }
});

// End it now. A card trial bills at once, so send an Idempotency-Key.
await billing.changeSubscriptionTrial({
	customerId,
	subscriptionId: 42,
	idempotencyKey: `end-trial-${customerId}`,
	body: { end: "now" },
});
```

```python Python theme={"system"}
billing.change_subscription_trial(
    customer_id=customer_id,
    subscription_id=42,
    days=7,  # or trial_ends_at="2026-12-31T00:00:00Z"
)

# End it now. A card trial bills at once, so send an idempotency key.
billing.change_subscription_trial(
    customer_id=customer_id,
    subscription_id=42,
    end_now=True,
    idempotency_key=f"end-trial-{customer_id}",
)
```

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

`days` counts from now: `7` on day 10 of a 14-day trial ends it 7 days from today. Ending a card trial now bills and grants the first period; ending a no-card trial now brings the earlier plan back.

## Read it

[Get a customer](https://docs.integrateledger.com/api-reference/customers/get.md) shows the trial on `currentPlan`:

```json Response theme={"system"}
{
  "currentPlan": {
    "id": "pro",
    "name": "Pro",
    "status": "trialing",
    "trialEndsAt": "2026-12-07T10:00:00.000Z",
    "trialOnEnd": "bill"
  }
}
```

`trialOnEnd` is `bill` (the card is charged) or `revert` (back to the free plan, or none). Both are `null` once the plan isn't trialing.

## Webhooks

The [subscription events](https://docs.integrateledger.com/webhooks.md#events) carry every trial change:

| When | Event |
| - | - |
| A trial starts | `subscription.created`, with `status: "trialing"`. A free plan it replaces sends `subscription.canceled` |
| A trial's end moves | `subscription.updated`, with the earlier `trialEndsAt` in `previousAttributes` |
| A card trial converts | `subscription.updated`, with `previousAttributes.status: "trialing"`, then `invoice.paid` |
| A no-card trial ends | `subscription.canceled` for the trial, then `subscription.created` for the free plan it goes back to |

## Errors

| Status | `error` | When |
| - | - | - |
| `422` | `trial_not_supported` | A trial on a lifetime plan |
| `422` | `trial_on_end_unsupported` | A card trial with `onEnd: "revert"`, or a no-card trial with `onEnd: "bill"` |
| `409` | `subscription_not_trialing` | Changing the trial of a subscription that isn't trialing |
| `422` | `invalid_trial_end` | A new trial end that isn't after now |
| `400` | `idempotency_key_required` | Ending a card trial now without an `Idempotency-Key` |

## Rules

* **Trials go on recurring paid plans.** A [lifetime plan](https://docs.integrateledger.com/pricing/lifetime.md) takes no `trial` (`trial_not_supported`).
* **`onEnd` matches the card.** A card trial bills at the end and a no-card trial reverts (`trial_on_end_unsupported`).
* **Once per plan.** Each customer gets a plan's trial once, across all its versions; a `trial` on attach gives another.
* **Ending a card trial now takes an `Idempotency-Key`,** since it bills at once (`idempotency_key_required`).

## Related

* [Free plans](https://docs.integrateledger.com/pricing/free-plans.md): what a no-card trial goes back to.
* [Checkout and attach](https://docs.integrateledger.com/billing/checkout-and-attach.md): how a paid plan starts.
* [Renewals and lifecycle](https://docs.integrateledger.com/billing/renewals-and-lifecycle.md): the `trialing` status and what follows it.


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