# Subscriptions

> Create, change, pause, resume and cancel subscriptions from your own code. Each period a subscription issues an invoice its customer pays by card, and its status tells you who has paid.

Source: https://railbed.com/docs/api/subscriptions/ · Updated: 2026-11-23 · Railbed developer docs

For AI assistants: the index of every docs page, with the rules for an integration, is https://railbed.com/docs/llms.txt

## The subscription object

A subscription bills one customer again each period: a price, how often it bills and when it starts. It's the same subscription you make under [Subscriptions](https://app.railbed.io/subscriptions) in the dashboard, and it shows up there. For each period it issues an ordinary [invoice](https://railbed.com/docs/api/invoices.md) (in `latest_invoice`, and in `GET /v1/invoices?subscription=sub_…`), which Railbed can email to the customer with reminders. The customer pays it by card on the invoice's page.

Railbed stores no card, so **nothing is charged automatically**: a period counts as paid only when its invoice is paid. A customer who doesn't pay goes past due and, after the days you chose, the subscription ends. The customer's own page, `url`, shows what they pay, their invoices, and Cancel where you allow it. Subscriptions add no fee of their own. For a walkthrough, see [Recurring billing with subscriptions](https://railbed.com/docs/guides/subscriptions.md).

| Field | Type | Description |
|---|---|---|
| `id` | string | The subscription's id, `sub_…` |
| `object` | string | `"subscription"` |
| `livemode` | boolean | `false` for Test mode, `true` for Live mode |
| `name` | string | The plan's name, or the name you gave it |
| `plan` | object or null | The [plan](https://railbed.com/docs/api/subscription-plans.md) it was made from: `id` (`spl_…`) and `name`. `null` for one made without a plan |
| `status` | string | Where it stands, as the dashboard shows it. See [Statuses](#statuses) |
| `stored_status` | string | `pending`, `trialing`, `active`, `past_due`, `paused` or `canceled`. Decide access from this. See [Who to serve](#who-to-serve) |
| `customer` | object | `id` (`cus_…`, the saved [customer](https://railbed.com/docs/api/customers.md)), `name`, `email`, `company` and `phone` |
| `currency` | string | `USD`, `EUR`, `GBP`, `CAD`, `AUD`, `INR` or `SEK` |
| `lines` | array | What each period bills: each line's `description`, `quantity`, `unit_amount` and `amount` |
| `subtotal`, `discount`, `tax`, `amount` | string | Each period's invoice: the lines added up, the discount, the tax, and the total it asks for |
| `discount_percent`, `tax_percent`, `tax_label` | string or null | The discount's and tax's rates, and the tax's name |
| `mrr` | string | Its price as a monthly figure, before tax |
| `counts_in_mrr` | boolean | Whether it counts in your recurring revenue now: it has started, and is active or past due |
| `interval` | object | How often it bills: `unit` (`day`, `week`, `month` or `year`) and `count` |
| `anchor_date` | string | The first paid period's first day, `YYYY-MM-DD`. Every period is counted from it, in UTC calendar days; a monthly one started on the 31st bills on the last day of shorter months |
| `trial_days`, `trial_end` | integer | Free days before the first paid period, and when the trial ends (Unix seconds, or `null`) |
| `billing` | object | How each invoice is sent and collected. See [The billing object](https://railbed.com/docs/api/subscription-plans.md#the-billing-object) |
| `memo`, `terms`, `reference` | string or null | Printed on each invoice: your note, your terms, and your own id |
| `current_period` | object or null | The latest period billed: `index` (from `0`), `start` and `end` (the next period's start), in Unix seconds. `null` before the first invoice |
| `next_invoice` | object or null | The next invoice: `at` (when it goes out), `period_start` and `period_end`. `null` when none is scheduled |
| `latest_invoice` | object or null | The latest invoice: `id`, `number`, `status`, `period_index`, `period_start`, `period_end`, `total`, `amount_due`, `due_date`, `issued_at`, `paid_at` and `url` (the customer's page, where they pay it) |
| `paid_through` | integer or null | The end of the latest paid period, in Unix seconds: the customer has paid up to here |
| `cycles_paid` | integer | How many periods have been paid |
| `total_paid` | string | Paid toward its invoices so far, tips apart |
| `activated_at`, `last_paid_at` | integer or null | When its first paid period began, and when an invoice of it was last paid |
| `cancel_at_period_end` | boolean | It's set to end when the time paid for does |
| `ends_at` | integer or null | With `cancel_at_period_end`: when it ends |
| `canceled_at` | integer or null | When it ended |
| `cancel_reason` | string or null | `requested` (you canceled it), `customer` (they did), `unpaid` (an invoice stayed unpaid past the cancel day), `expired` (its first invoice was never paid) or `erased` (you deleted the customer's details) |
| `cancel_feedback` | string or null | The reason a customer chose when they canceled: `too_expensive`, `not_using`, `missing_features`, `switched`, `temporary` or `other` |
| `paused_at`, `pause_reason` | integer or null, string or null | When it was paused (Unix seconds), and why: `requested`, or `billing_failed` when its invoices couldn't be issued seven times in a row |
| `billing_problem` | string or null | Why the next invoice couldn't be issued, in words, such as a removed payout wallet. `null` when billing is fine |
| `url` | string | The customer's subscription page, `https://pay.railbed.io/sub/…` |
| `source` | string | Where it was made: `dashboard`, `api`, `plan_page` (a sign-up on a plan's page) or `mcp` |
| `owner` | object or null | The person on your team it belongs to: `id`, `name` and `email` |
| `version` | integer | Goes up with each [update](#update-a-subscription) by you or your team, never with billing. Send it back as `expected_version`. It doesn't order events: use the event's `created` |
| `created`, `updated` | integer | When it was made and last changed, in Unix seconds |
| `warnings` | array | On create and update only, and only when there is something to say: what the card providers' minimums mean for this amount. See [Provider minimums](https://railbed.com/docs/api/checkout-sessions.md#provider-minimums) |

Example: A subscription · response 200 OK

```json
{
  "id": "sub_Lq4nX7tR2mVc9KzW5pHd",
  "object": "subscription",
  "livemode": false,
  "name": "Pro",
  "plan": {
    "id": "spl_8Hq2mVx5RtLc3NwZb7Ks",
    "name": "Pro"
  },
  "status": "awaiting_payment",
  "stored_status": "pending",
  "customer": {
    "id": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "company": "Analytical Engines Ltd",
    "phone": null
  },
  "currency": "USD",
  "lines": [
    {
      "description": "Pro",
      "quantity": "2",
      "unit_amount": "49.00",
      "amount": "98.00"
    }
  ],
  "subtotal": "98.00",
  "discount": "0.00",
  "discount_percent": null,
  "tax": "0.00",
  "tax_percent": null,
  "tax_label": null,
  "amount": "98.00",
  "mrr": "98.00",
  "counts_in_mrr": false,
  "interval": {
    "unit": "month",
    "count": 1
  },
  "anchor_date": "2026-09-25",
  "trial_days": 0,
  "trial_end": null,
  "billing": {
    "lead_days": 7,
    "terms_days": 3,
    "cancel_after_days": 14,
    "reminders": [
      -3,
      0,
      3,
      7
    ],
    "send_emails": true,
    "email_receipts": true,
    "allow_customer_cancel": true
  },
  "memo": null,
  "terms": "Cancel any time from your subscription page.",
  "reference": "PO-1042",
  "current_period": {
    "index": 0,
    "start": 1790294400,
    "end": 1792886400
  },
  "next_invoice": null,
  "latest_invoice": {
    "id": "in_Tz6pQ3wN8kHr1VbX5mLc",
    "number": "INV-0043",
    "status": "sent",
    "period_index": 0,
    "period_start": 1790294400,
    "period_end": 1792886400,
    "total": "98.00",
    "amount_due": "98.00",
    "due_date": "2026-09-28",
    "issued_at": 1790380525,
    "paid_at": null,
    "url": "https://pay.railbed.io/i/9a3f6c2e7b1d4085c6e2f9a1b7d3c8e4"
  },
  "paid_through": null,
  "cycles_paid": 0,
  "total_paid": "0.00",
  "activated_at": null,
  "last_paid_at": null,
  "cancel_at_period_end": false,
  "ends_at": null,
  "canceled_at": null,
  "cancel_reason": null,
  "cancel_feedback": null,
  "paused_at": null,
  "pause_reason": null,
  "billing_problem": null,
  "url": "https://pay.railbed.io/sub/2d7e9b4a6c1f4e83a0b5d8c2f6e1a9b3",
  "source": "api",
  "owner": null,
  "version": 0,
  "created": 1790380525,
  "updated": 1790380525
}
```

### Statuses

`status` is the label the dashboard shows. `stored_status` is the state underneath it.

| `status` | `stored_status` | Meaning |
|---|---|---|
| `scheduled` | `pending` | Nothing to pay yet: it starts on a later date |
| `awaiting_payment` | `pending` | Its first invoice is out and unpaid. It hasn't started, so it isn't past due |
| `trialing` | `trialing` | In its free trial |
| `active` | `active` | The latest invoice is paid, or isn't due yet |
| `past_due` | `past_due` | An invoice is unpaid after its due date. It ends on the cancel day unless paid |
| `ending` | `active`, `past_due` or `trialing` | Canceled at the end of the time paid for. It's still running until `ends_at` |
| `paused` | `paused` | No invoices go out until it's resumed. One already out stays payable |
| `canceled` | `canceled` | Ended. Start a new subscription to bill the customer again |

### Who to serve

Serve a customer while `stored_status` is `trialing` or `active`, plus `past_due` if you give a grace period, or until `paid_through` (`trial_end` in a trial). Never treat `ending` as ended: the customer has paid until `ends_at`. Key access on the subscription's `id`, and read it back with [Retrieve a subscription](#retrieve-a-subscription) when you need to be sure: `version` only counts edits, so it can't tell you which of two [events](#webhooks) is newer.

## Create a subscription

`POST /v1/subscriptions`

Makes a subscription in the credential's mode, for one customer. Give a `plan`, or give its own `name`, `currency`, `lines` and `interval`. One that starts today issues its first invoice before the response comes back, in `latest_invoice`: send the customer its `url`, or let Railbed's email reach them. One with a trial or a later start date issues nothing until its first invoice is due to go out.

| Parameter | Type | Description |
|---|---|---|
| `customer` | object · required | `name` and `email` (both required), `company`, `phone` and `billing_address`. Pass `id` (`cus_…`) for a saved customer, as on [Create an invoice](https://railbed.com/docs/api/invoices.md#create-an-invoice) |
| `plan` | string | A plan id, `spl_…`. The plan decides the name, currency, line and interval, and its trial and settings are copied unless you send your own |
| `quantity` | string | With `plan`: how many (seats, units), from `"0.01"` to `"99999"`. Default `"1"` |
| `name` | string | Without `plan`: what the customer sees, up to 80 characters |
| `currency` | string | Without `plan`: `USD`, `EUR`, `GBP`, `CAD`, `AUD`, `INR` or `SEK` |
| `lines` | array | Without `plan`: what each period bills, as on [Create an invoice](https://railbed.com/docs/api/invoices.md#create-an-invoice) |
| `interval` | object | Without `plan`: `unit` and `count`, every 1–365 days, 1–52 weeks, 1–24 months or 1–3 years |
| `discount`, `tax` | object | As on an invoice, on each period's invoice |
| `memo` | string | A note on each invoice, up to 800 characters |
| `terms`, `reference` | string | Printed on each invoice |
| `start_date` | string | The first paid period's first day, `YYYY-MM-DD`, from today to 365 days ahead. Default today. Ignored with a trial, which starts today |
| `trial_days` | integer | 0–365 free days before the first paid period. Overrides the plan's |
| `billing` | object | Over the plan's, or the interval's defaults. See [The billing object](https://railbed.com/docs/api/subscription-plans.md#the-billing-object) |
| `owner_id`, `owner_email` | string | Who on your team it belongs to: an owner, manager or salesperson, by user id or sign-in email. Not both |
| `routing`, `collect`, `success_url`, `payout_wallet_id` | | As on [Create an invoice](https://railbed.com/docs/api/invoices.md#create-an-invoice), for each period's invoice |

A field subscriptions don't have is refused with `400 unknown_field`, and the message names the one you probably meant when it's a near miss. The plan's id goes in `plan`: `plan_id` is refused.

Example: cURL

```bash
curl https://pay.railbed.io/v1/subscriptions \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: signup-ada-pro" \
  -d '{
    "plan": "spl_8Hq2mVx5RtLc3NwZb7Ks",
    "quantity": "2",
    "customer": { "name": "Ada Lovelace", "email": "ada@example.com", "company": "Analytical Engines Ltd" },
    "reference": "PO-1042"
  }'
```

Example: Node\.js

```js
const sub = await fetch('https://pay.railbed.io/v1/subscriptions', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.RAILBED_SECRET_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': `signup-${user.id}-pro`,
  },
  body: JSON.stringify({
    name: 'Monthly retainer',
    currency: 'USD',
    lines: [{ description: 'Retainer', unit_amount: '1200.00' }],
    interval: { unit: 'month', count: 1 },
    start_date: '2026-12-01',
    customer: { name: 'Ada Lovelace', email: 'ada@example.com' },
  }),
}).then((r) => r.json());
```

Example: Response · response 201 Created

```json
{
  "id": "sub_Lq4nX7tR2mVc9KzW5pHd",
  "object": "subscription",
  "livemode": false,
  "name": "Pro",
  "plan": {
    "id": "spl_8Hq2mVx5RtLc3NwZb7Ks",
    "name": "Pro"
  },
  "status": "awaiting_payment",
  "stored_status": "pending",
  "customer": {
    "id": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "company": "Analytical Engines Ltd",
    "phone": null
  },
  "currency": "USD",
  "lines": [
    {
      "description": "Pro",
      "quantity": "2",
      "unit_amount": "49.00",
      "amount": "98.00"
    }
  ],
  "subtotal": "98.00",
  "discount": "0.00",
  "discount_percent": null,
  "tax": "0.00",
  "tax_percent": null,
  "tax_label": null,
  "amount": "98.00",
  "mrr": "98.00",
  "counts_in_mrr": false,
  "interval": {
    "unit": "month",
    "count": 1
  },
  "anchor_date": "2026-09-25",
  "trial_days": 0,
  "trial_end": null,
  "billing": {
    "lead_days": 7,
    "terms_days": 3,
    "cancel_after_days": 14,
    "reminders": [
      -3,
      0,
      3,
      7
    ],
    "send_emails": true,
    "email_receipts": true,
    "allow_customer_cancel": true
  },
  "memo": null,
  "terms": "Cancel any time from your subscription page.",
  "reference": "PO-1042",
  "current_period": {
    "index": 0,
    "start": 1790294400,
    "end": 1792886400
  },
  "next_invoice": null,
  "latest_invoice": {
    "id": "in_Tz6pQ3wN8kHr1VbX5mLc",
    "number": "INV-0043",
    "status": "sent",
    "period_index": 0,
    "period_start": 1790294400,
    "period_end": 1792886400,
    "total": "98.00",
    "amount_due": "98.00",
    "due_date": "2026-09-28",
    "issued_at": 1790380525,
    "paid_at": null,
    "url": "https://pay.railbed.io/i/9a3f6c2e7b1d4085c6e2f9a1b7d3c8e4"
  },
  "paid_through": null,
  "cycles_paid": 0,
  "total_paid": "0.00",
  "activated_at": null,
  "last_paid_at": null,
  "cancel_at_period_end": false,
  "ends_at": null,
  "canceled_at": null,
  "cancel_reason": null,
  "cancel_feedback": null,
  "paused_at": null,
  "pause_reason": null,
  "billing_problem": null,
  "url": "https://pay.railbed.io/sub/2d7e9b4a6c1f4e83a0b5d8c2f6e1a9b3",
  "source": "api",
  "owner": null,
  "version": 0,
  "created": 1790380525,
  "updated": 1790380525
}
```

**Retries.** Send an `Idempotency-Key` (1–120 printable ASCII characters) with every create: the same key with the same body (compared as sent, in any field order) answers the subscription it made, with `200`, for 24 hours; the same key with a different body is `409 idempotency_conflict`.

| Error | Cause |
|---|---|
| `400 unknown_field` | A field subscriptions don't have, here or inside `interval` or `billing`. `field` names it |
| `400 invalid_plan`, `409 plan_archived` | `plan` isn't one of your plans in this mode, or it's archived |
| `400 customer_required` | The customer's name or email is missing. `field` names it |
| `400 missing_name`, `400 invalid_interval`, `400 invalid_quantity` | Without a plan: no name, or an interval outside its bounds; with one, a quantity out of range |
| `400 invalid_start_date`, `400 invalid_trial` | Not a date from today to 365 days ahead, or a trial that isn't 0–365 days |
| `400 invalid_billing`, `400 invalid_reminders`, `400 invalid_value` | A `billing` value isn't one of its choices or doesn't fit the interval. `field` names it, such as `billing.terms_days` |
| `400 invalid_amount`, `400 invalid_lines`, `400 invalid_owner` and the other invoice field errors | As on [Create an invoice](https://railbed.com/docs/api/invoices.md#create-an-invoice) |
| `409 idempotency_conflict`, `409 idempotency_in_progress` | The key was used with a different body, or its first request hasn't finished: retry after `Retry-After` |
| `409 no_payout_wallet`, `409 account_review`, `409 payout_wallet_unusable` | Live mode, and the account (or the chosen wallet) can't take Live payments yet |
| `409 commerce_paused`, `403 integration_disabled` | The account has paused payments, or payment links or the API are turned off for it |

## Retrieve a subscription

`GET /v1/subscriptions/:id`

Returns one of your subscriptions in the credential's mode, brought up to date first: one whose next invoice was due to go out has it. One in the other mode is `404 not_found`, and the message says which mode it's in.

Example: cURL

```bash
curl https://pay.railbed.io/v1/subscriptions/sub_Lq4nX7tR2mVc9KzW5pHd \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
```

To see every invoice it has issued, use [List invoices](https://railbed.com/docs/api/invoices.md#list-invoices) with `subscription=sub_…`; each of them carries `subscription` with its period.

## Update a subscription

`PATCH /v1/subscriptions/:id`

Changes what each period bills, the customer's details, the collection settings and the owner. A change applies **from the next invoice issued**, never to one already out. Send only the fields you change; `customer` merges into the details it has. `name`, `customer`, `lines`, `discount`, `tax`, `memo`, `terms`, `reference`, `billing`, `owner_id` or `owner_email`, `routing`, `collect`, `success_url` and `payout_wallet_id` take the values of [Create a subscription](#create-a-subscription). Its plan, interval, start date and trial can't change (`400 unknown_field`): cancel it and start a new one.

| Parameter | Type | Description |
|---|---|---|
| `expected_version` | integer | The `version` you read. If anyone changed it since, it answers `409 subscription_changed` instead of overwriting their change |

Example: cURL

```bash
curl -X PATCH https://pay.railbed.io/v1/subscriptions/sub_Lq4nX7tR2mVc9KzW5pHd \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "lines": [{ "description": "Pro", "quantity": "3", "unit_amount": "49.00" }],
    "expected_version": 0
  }'
```

If its next invoice couldn't be issued (`billing_problem`), an update tries again at once, since the change may be what fixes it. Its `subscription.updated` event follows.

| Error | Cause |
|---|---|
| `409 subscription_changed` | Someone changed it since `expected_version`, or it kept changing while the request ran. Read it again, then retry |
| `409 subscription_canceled` | It has ended |
| `400 invalid_expected_version` | Not a whole number |
| `409 commerce_paused` | The account has paused payments |

The create errors apply to the fields you send.

## List subscriptions

`GET /v1/subscriptions`

Returns your subscriptions in the credential's mode, newest first.

| Parameter | Type | Description |
|---|---|---|
| `limit` | integer | 1–100. Default 20 |
| `starting_after` | string | A subscription id from the previous page's `next_cursor` |
| `status` | string | One [status](#statuses); or `paying` for those that count in your recurring revenue (started, and active or past due); or `open` for every one not canceled |
| `plan` | string | Only those on this plan, `spl_…` |
| `customer` | string | Only this customer's, `cus_…` |
| `owner` | string | Only those this person owns, `usr_…`, or `none` for those nobody owns |
| `q` | string | Text in the name, the customer's name, email or company, or the reference, up to 100 characters |

Example: cURL

```bash
curl "https://pay.railbed.io/v1/subscriptions?status=past_due" \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
```

Example: Response · response 200 OK

```json
{
  "data": [
    {
      "id": "sub_Lq4nX7tR2mVc9KzW5pHd",
      "object": "subscription",
      "livemode": false,
      "name": "Pro",
      "plan": {
        "id": "spl_8Hq2mVx5RtLc3NwZb7Ks",
        "name": "Pro"
      },
      "status": "awaiting_payment",
      "stored_status": "pending",
      "customer": {
        "id": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
        "name": "Ada Lovelace",
        "email": "ada@example.com",
        "company": "Analytical Engines Ltd",
        "phone": null
      },
      "currency": "USD",
      "lines": [
        {
          "description": "Pro",
          "quantity": "2",
          "unit_amount": "49.00",
          "amount": "98.00"
        }
      ],
      "subtotal": "98.00",
      "discount": "0.00",
      "discount_percent": null,
      "tax": "0.00",
      "tax_percent": null,
      "tax_label": null,
      "amount": "98.00",
      "mrr": "98.00",
      "counts_in_mrr": false,
      "interval": {
        "unit": "month",
        "count": 1
      },
      "anchor_date": "2026-09-25",
      "trial_days": 0,
      "trial_end": null,
      "billing": {
        "lead_days": 7,
        "terms_days": 3,
        "cancel_after_days": 14,
        "reminders": [
          -3,
          0,
          3,
          7
        ],
        "send_emails": true,
        "email_receipts": true,
        "allow_customer_cancel": true
      },
      "memo": null,
      "terms": "Cancel any time from your subscription page.",
      "reference": "PO-1042",
      "current_period": {
        "index": 0,
        "start": 1790294400,
        "end": 1792886400
      },
      "next_invoice": null,
      "latest_invoice": {
        "id": "in_Tz6pQ3wN8kHr1VbX5mLc",
        "number": "INV-0043",
        "status": "sent",
        "period_index": 0,
        "period_start": 1790294400,
        "period_end": 1792886400,
        "total": "98.00",
        "amount_due": "98.00",
        "due_date": "2026-09-28",
        "issued_at": 1790380525,
        "paid_at": null,
        "url": "https://pay.railbed.io/i/9a3f6c2e7b1d4085c6e2f9a1b7d3c8e4"
      },
      "paid_through": null,
      "cycles_paid": 0,
      "total_paid": "0.00",
      "activated_at": null,
      "last_paid_at": null,
      "cancel_at_period_end": false,
      "ends_at": null,
      "canceled_at": null,
      "cancel_reason": null,
      "cancel_feedback": null,
      "paused_at": null,
      "pause_reason": null,
      "billing_problem": null,
      "url": "https://pay.railbed.io/sub/2d7e9b4a6c1f4e83a0b5d8c2f6e1a9b3",
      "source": "api",
      "owner": null,
      "version": 0,
      "created": 1790380525,
      "updated": 1790380525
    }
  ],
  "has_more": false,
  "next_cursor": null
}
```

## Cancel a subscription

`POST /v1/subscriptions/:id/cancel`

Ends it. By default it ends when the time paid for does: it reads `ending`, carries on until `ends_at`, and can be [kept](#keep-a-subscription) until then. With nothing paid yet, or while paused, it ends now. An invoice already out for a later period stays payable but sends no more reminders, and the customer doesn't have to pay it: unpaid, it's voided when the subscription ends; paid, the subscription runs to the end of that period.

| Parameter | Type | Description |
|---|---|---|
| `when` | string | `period_end` (the default) or `now` |
| `keep_open_invoice` | boolean | With `when: "now"`: leave its unpaid invoice open, because the customer still owes it. Default `false`, which voids it |
| `comment` | string | Why, for its history in the dashboard, up to 500 characters. Never shown to the customer |

Example: cURL

```bash
curl -X POST https://pay.railbed.io/v1/subscriptions/sub_Lq4nX7tR2mVc9KzW5pHd/cancel \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "when": "now" }'
```

Example: Response · response 200 OK

```json
{
  "id": "sub_Lq4nX7tR2mVc9KzW5pHd",
  "object": "subscription",
  "livemode": false,
  "name": "Pro",
  "plan": {
    "id": "spl_8Hq2mVx5RtLc3NwZb7Ks",
    "name": "Pro"
  },
  "status": "canceled",
  "stored_status": "canceled",
  "customer": {
    "id": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "company": "Analytical Engines Ltd",
    "phone": null
  },
  "currency": "USD",
  "lines": [
    {
      "description": "Pro",
      "quantity": "2",
      "unit_amount": "49.00",
      "amount": "98.00"
    }
  ],
  "subtotal": "98.00",
  "discount": "0.00",
  "discount_percent": null,
  "tax": "0.00",
  "tax_percent": null,
  "tax_label": null,
  "amount": "98.00",
  "mrr": "98.00",
  "counts_in_mrr": false,
  "interval": {
    "unit": "month",
    "count": 1
  },
  "anchor_date": "2026-09-25",
  "trial_days": 0,
  "trial_end": null,
  "billing": {
    "lead_days": 7,
    "terms_days": 3,
    "cancel_after_days": 14,
    "reminders": [
      -3,
      0,
      3,
      7
    ],
    "send_emails": true,
    "email_receipts": true,
    "allow_customer_cancel": true
  },
  "memo": null,
  "terms": "Cancel any time from your subscription page.",
  "reference": "PO-1042",
  "current_period": {
    "index": 0,
    "start": 1790294400,
    "end": 1792886400
  },
  "next_invoice": null,
  "latest_invoice": {
    "id": "in_Tz6pQ3wN8kHr1VbX5mLc",
    "number": "INV-0043",
    "status": "void",
    "period_index": 0,
    "period_start": 1790294400,
    "period_end": 1792886400,
    "total": "98.00",
    "amount_due": "98.00",
    "due_date": "2026-09-28",
    "issued_at": 1790380525,
    "paid_at": null,
    "url": "https://pay.railbed.io/i/9a3f6c2e7b1d4085c6e2f9a1b7d3c8e4"
  },
  "paid_through": null,
  "cycles_paid": 0,
  "total_paid": "0.00",
  "activated_at": null,
  "last_paid_at": null,
  "cancel_at_period_end": false,
  "ends_at": null,
  "canceled_at": 1790384125,
  "cancel_reason": "requested",
  "cancel_feedback": null,
  "paused_at": null,
  "pause_reason": null,
  "billing_problem": null,
  "url": "https://pay.railbed.io/sub/2d7e9b4a6c1f4e83a0b5d8c2f6e1a9b3",
  "source": "api",
  "owner": null,
  "version": 0,
  "created": 1790380525,
  "updated": 1790384125
}
```

The body is optional. Canceling works even while the account has paused payments, since it stops invoices rather than asking for money. An end at the period's end sends `subscription.updated`; an end now sends `subscription.canceled`, and `invoice.voided` for an invoice it voids.

| Error | Cause |
|---|---|
| `409 subscription_canceled` | It has already ended |
| `400 invalid_when`, `400 invalid_keep_open_invoice` | `when` isn't `now` or `period_end`, or `keep_open_invoice` isn't `true` or `false` or came without `when: "now"` |
| `400 invalid_comment`, `400 too_long` | `comment` isn't text, or is over 500 characters |

## Keep a subscription

`POST /v1/subscriptions/:id/keep`

Takes back a cancel at the end of the paid time, whoever made it: the subscription carries on, its next invoice goes out on its day, and an invoice already out reminds again. No body is needed. One with no end set comes back as it is. It sends `subscription.updated`.

Example: cURL

```bash
curl -X POST https://pay.railbed.io/v1/subscriptions/sub_Lq4nX7tR2mVc9KzW5pHd/keep \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
```

A canceled subscription can't be kept (`409 subscription_canceled`). While the account has paused payments, keeping is refused with `409 commerce_paused`.

## Pause a subscription

`POST /v1/subscriptions/:id/pause`

Stops issuing invoices until it's [resumed](#resume-a-subscription). An invoice already out stays payable, and a cancel scheduled for the end of the paid time still ends it on that day. No body is needed, and one already paused comes back as it is. Pausing works even while the account has paused payments. It sends `subscription.paused`.

Example: cURL

```bash
curl -X POST https://pay.railbed.io/v1/subscriptions/sub_Lq4nX7tR2mVc9KzW5pHd/pause \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
```

Railbed also pauses a subscription itself when its invoices couldn't be issued seven times in a row (`pause_reason: "billing_failed"`): fix what `billing_problem` says, then resume it.

## Resume a subscription

`POST /v1/subscriptions/:id/resume`

Starts billing again. By default billing starts with the next period and the rest of the current one is free. Periods that passed entirely while paused are skipped, never billed. An unpaid invoice that went overdue while paused gets a new due date: the resume day plus the subscription's payment terms. It sends `subscription.resumed`.

| Parameter | Type | Description |
|---|---|---|
| `bill_now` | boolean | Bill the period under way now, in full. Default `false` |

Example: cURL

```bash
curl -X POST https://pay.railbed.io/v1/subscriptions/sub_Lq4nX7tR2mVc9KzW5pHd/resume \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "bill_now": true }'
```

| Error | Cause |
|---|---|
| `409 not_paused` | It isn't paused |
| `409 subscription_canceled` | It has ended |
| `400 invalid_bill_now` | Not `true` or `false` |
| `409 commerce_paused` | The account has paused payments |

## Advance a Test subscription

`POST /v1/subscriptions/:id/advance`

Test mode only: issues the next period's invoice now, so you can try a renewal without waiting. It's the dashboard's **Renew now**. No body is needed. Pay the invoice from its page and `subscription.renewed` arrives. See [Try it in Test mode](https://railbed.com/docs/guides/subscriptions.md#test-mode).

Example: cURL

```bash
curl -X POST https://pay.railbed.io/v1/subscriptions/sub_Lq4nX7tR2mVc9KzW5pHd/advance \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
```

| Error | Cause |
|---|---|
| `409 live_subscription` | It's a Live subscription: its invoices go out on their dates |
| `409 invoice_open` | Its latest invoice is still unpaid. Pay it first |
| `409 subscription_paused` | It's paused. Resume it first |
| `409 nothing_to_issue`, `409 not_billable` | It's set to end before the next period, or can't issue invoices in its state |
| `409 subscription_canceled` | It has ended |

## Retrieve subscription metrics

`GET /v1/subscription_metrics`

Returns recurring revenue in the key's mode, per currency, as **Subscriptions → Revenue** shows it: MRR and ARR, the period's movements (new, reactivation, expansion, contraction, churn, paused, resumed), churn and net retention, trials, how invoices were collected, a series and monthly cohorts. Figures are never added across currencies. They come from each subscription's own history, so editing an invoice doesn't change them.

| Parameter | Type | Description |
|---|---|---|
| `period` | string | The window the movements, rates, series and cohorts cover: `30d` (default), `90d` or `12m` |

Example: cURL

```bash
curl "https://pay.railbed.io/v1/subscription_metrics?period=90d" \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
```

Example: Response · response 200 OK

```json
{
  "object": "subscription_metrics",
  "livemode": false,
  "period": "30d",
  "as_of": 1790380525,
  "subscriptions": 14,
  "plans": 2,
  "currencies": [
    {
      "currency": "USD",
      "mrr": "637.00",
      "arr": "7644.00",
      "mrr_start": "539.00",
      "mrr_change": {
        "amount": "98.00",
        "percent": 18.2
      },
      "subscribers": {
        "paying": 12,
        "active": 11,
        "past_due": 1,
        "trialing": 1,
        "paused": 0,
        "pending": 1
      },
      "paying_start": 10,
      "movements": {
        "new": {
          "count": 3,
          "mrr": "147.00"
        },
        "reactivation": {
          "count": 0,
          "mrr": "0.00"
        },
        "expansion": {
          "count": 1,
          "mrr": "49.00"
        },
        "contraction": {
          "count": 0,
          "mrr": "0.00"
        },
        "churn": {
          "count": 1,
          "mrr": "98.00"
        },
        "paused": {
          "count": 0,
          "mrr": "0.00"
        },
        "resumed": {
          "count": 0,
          "mrr": "0.00"
        }
      },
      "net_new_mrr": "98.00",
      "subscriber_churn": 0.1,
      "revenue_churn": 0.182,
      "net_retention": 0.909,
      "arpu": "53.08",
      "ltv": "530.83",
      "trials": {
        "started": 2,
        "ended": 1,
        "converted": 1,
        "rate": 1
      },
      "collection": {
        "due": 12,
        "paid_on_time": 10,
        "paid_late": 1,
        "unpaid": 1,
        "voided": 0,
        "rate": 0.917,
        "on_time_rate": 0.833,
        "median_days_to_pay": 2,
        "collected": "588.00"
      },
      "past_due": {
        "count": 1,
        "amount": "49.00"
      },
      "upcoming": {
        "count": 4,
        "amount": "196.00"
      },
      "series": [
        {
          "at": 1787788800,
          "mrr": "539.00",
          "paying": 10
        },
        {
          "at": 1789084800,
          "mrr": "588.00",
          "paying": 11
        },
        {
          "at": 1790380525,
          "mrr": "637.00",
          "paying": 12
        }
      ],
      "cohorts": [
        {
          "month": "2026-08",
          "size": 4,
          "retained": [
            4,
            3
          ]
        },
        {
          "month": "2026-09",
          "size": 3,
          "retained": [
            3
          ]
        }
      ]
    }
  ]
}
```

Rates are fractions (0.25 is 25%) and `null` when there's nothing to divide by; `mrr_change.percent` alone is a percentage. A pause is never churn. `ltv` stays `null` until the year has enough cancellations to say. A period's invoice counts toward `collection` once it comes due.

## Webhooks

Choose the subscription events for an endpoint, in [Developers](https://app.railbed.io/developers) or with `events` on [Create a webhook endpoint](https://railbed.com/docs/api/webhook-endpoints.md#create-a-webhook-endpoint): `subscription.created`, `subscription.activated`, `subscription.invoice_issued`, `subscription.renewed`, `subscription.past_due`, `subscription.paused`, `subscription.resumed`, `subscription.updated` and `subscription.canceled`. They go only to endpoints that name them, so a receiver written before subscriptions never sees one. Each carries the subscription as `data.subscription`, in this page's shape. Each period's invoice also sends the invoice events to endpoints that chose them, and each payment toward it its `payment.*` events. Order events by the event's `created`, or read the subscription back. See [Subscription events](https://railbed.com/docs/webhooks/events.md#subscription-events).

## Access

Retrieving, listing and reading the metrics need the `payments:read` [scope](https://railbed.com/docs/api.md#scopes), which **Read only** keys have. Creating, changing, canceling, keeping, pausing, resuming and advancing need `checkouts:write`, which **Full access** keys and agents with full access have. A change made with a key is recorded on the subscription's history as the key's, under its name, never as a person's.
