> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bachs.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Money is always a decimal string at the currency's precision (for example "29.00"), paired with an ISO 4217 currency field. Never use minor units.
> Build against the sandbox first: base URL https://sandbox-api.bachs.io with sk_sandbox_ keys. Production is https://api.bachs.io with sk_live_ keys; going live is a key swap.
> Treat webhooks (for example collection.succeeded) as the source of truth for fulfilment, never client-side events or redirects.
> Subscriptions are created by completing a checkout for a recurring product. There is no direct create-subscription endpoint.
> IDs carry resource prefixes (cust_, prod_, sub_, chk_, inv_, ref_) and timestamps are ISO 8601 UTC.

# Change or cancel a subscription

> Change the plan or the seat count, move a trial, or cancel, using the API or your dashboard.

Once a subscription exists you can change it over its lifetime. Every change is available through the [Update Subscription](https://docs.bachs.io/api-reference/subscriptions/update-subscription.md) endpoint (and cancellation through [Cancel Subscription](https://docs.bachs.io/api-reference/subscriptions/cancel-subscription.md)), or from your dashboard.&#x20;

> [!NOTE]
>
> **One change per request.** Each update carries exactly one intent: change the plan, *or* the seat count, *or* the payment method, *or* the trial, *or* the metadata. Combining them in a single request returns `400`.

Fetch the current state first with [Get Subscription](https://docs.bachs.io/api-reference/subscriptions/get-subscription.md); every update returns the full, updated subscription object.

***

## Change the plan

Move a subscriber to a different plan by sending the target `product_id`. Bachs resolves the price from that product for the subscription's currency, so you name the plan and the plan owns the price. Include a [`proration_behavior`](https://docs.bachs.io/guides/subscriptions/proration) to say how the price difference is settled.

```bash theme={"dark"}
PATCH /v1/subscriptions/sub_1a2b3c4d5e6f
```

```json theme={"dark"}
{
  "product_id": "prod_premium",
  "proration_behavior": "invoice_now"
}
```

* `invoice_now`: apply now and settle the difference immediately (upgrade charged, downgrade credited).
* `next_cycle`: apply now, roll the difference into the next renewal.
* `none`: change the terms with no proration.

The target product must have a price in the subscription's currency, otherwise the request returns `400`. A product on a different billing cycle, for example monthly to annual, is not applied now. It is staged in `pending_update` and takes effect at the next renewal. This works only on a subscription with one item, because every item bills on the subscription's one cycle. On a subscription with more than one item, a billing cycle change returns `400`. A downgrade's credit goes to the customer's [credit balance](https://docs.bachs.io/guides/subscriptions/proration.md#customer-credit) and is applied to future invoices automatically. See [How proration works](https://docs.bachs.io/guides/subscriptions/proration.md) for the full model.

***

## Change the seat count

If you charge per user, the plan's price is the price of one seat. Send the new total as `seats`.

```bash theme={"dark"}
PATCH /v1/subscriptions/sub_1a2b3c4d5e6f
```

```json theme={"dark"}
{
  "seats": 5,
  "proration_behavior": "invoice_now"
}
```

`seats` is the new total, not the number to add. To go from 3 seats to 5, send `5`.

* **Adding seats** charges the difference for the rest of the current period. `proration_behavior` decides when: now (`invoice_now`, the default), on the next renewal (`next_cycle`), or not at all (`none`). Every renewal after that bills the new count.
* **Removing seats** gives the customer a prorated credit, whatever `proration_behavior` you send. The credit is used on their next invoices.

For example, a plan costs $10 per seat each month. Halfway through the month the customer goes from 3 seats to 5. With `invoice_now` they pay $10 now: 2 extra seats for half a month. Their next renewal is \$50.

The response shows the count as `seats` on the subscription and on each item. `quantity` is the same number.

A subscription with more than one priced item needs `subscription_item_id` to say which item to change. Without it the request returns `400` and lists the item IDs. On those subscriptions the top-level `seats` is `null`, so read each item's `seats` instead.

> [!NOTE]
>
> `seats` must be 1 or more. The subscription must be `active`, `trialing` or `past_due`.

***

## Manage the trial

Add, extend, or end a trial by setting `trial_end`. A future timestamp adds or extends the trial (nothing is charged); a past-or-now timestamp ends it and bills the first cycle immediately. On an `active` subscription, the trial must end after `current_period_end`, because the customer has already paid until then.

```json theme={"dark"}
{ "trial_end": "2026-08-10T12:00:00Z" }
```

Full details, including ending a trial early, are on the [Trials](https://docs.bachs.io/guides/subscriptions/trials.md#adding-extending-or-ending-a-trial) page.

***

## Update the metadata

Merge into the subscription's key-value `metadata` (up to 20 keys). Sent keys are added or overwritten and any keys you don't mention are left untouched. To remove one key, send it with an empty-string value; to clear everything, send `""`.

```json theme={"dark"}
{ "metadata": { "plan_tier": "pro", "crm_id": "cust_8842" } }
```

```json theme={"dark"}
{ "metadata": { "crm_id": "" } }   // removes crm_id, keeps the rest
```

Metadata is first attached at the [checkout session](https://docs.bachs.io/guides/checkout/checkout-sessions.md) that starts the subscription and copied onto it on success; this endpoint lets you change it afterward. The system-managed `checkout_id` key is preserved and can't be overwritten.

***

## Cancel a subscription

Cancel with the [Cancel Subscription](https://docs.bachs.io/api-reference/subscriptions/cancel-subscription.md) endpoint. You choose *when* the cancellation takes effect with `cancel_at_period_end`.

```bash theme={"dark"}
DELETE /v1/subscriptions/sub_1a2b3c4d5e6f
```

> [tab] Cancel at period end
>
> The subscription keeps working until `current_period_end` (the customer paid for that period), then transitions to `canceled`. Bachs sets `cancel_at_period_end: true` and emits `customer.subscription.updated`.
>
> ```json Request body theme={"dark"}
> { "cancel_at_period_end": true, "reason": "Customer requested" }
> ```
>
> ```ts Node.js theme={"dark"}
> await bachs.subscriptions.cancel("sub_1a2b3c4d5e6f", {
>   cancel_at_period_end: true,
>   reason: "Customer requested",
> });
> ```
>
> ```python Python theme={"dark"}
> bachs.subscriptions.cancel(
>     "sub_1a2b3c4d5e6f",
>     cancel_at_period_end=True,
>     reason="Customer requested",
> )
> ```
>
> This is the gentler option: no partial refund, no interruption, access continues to the date they already paid for.

> [tab] Cancel immediately
>
> The subscription moves to `canceled` right now. Bachs sets `canceled_at`, clears the next billing date, and emits `customer.subscription.deleted`. This is terminal.
>
> ```json Request body theme={"dark"}
> { "cancel_at_period_end": false, "reason": "Fraud" }
> ```
>
> ```ts Node.js theme={"dark"}
> await bachs.subscriptions.cancel("sub_1a2b3c4d5e6f", {
>   cancel_at_period_end: false,
>   reason: "Fraud",
> });
> ```
>
> ```python Python theme={"dark"}
> bachs.subscriptions.cancel(
>     "sub_1a2b3c4d5e6f",
>     cancel_at_period_end=False,
>     reason="Fraud",
> )
> ```
>
> There's no automatic refund; if you owe one, issue it separately.

`reason` is optional (max 255 characters) and is stored on the subscription. Canceling an already-canceled subscription returns `400`.

### What makes a subscription `canceled`

A subscription reaches the terminal `canceled` status in exactly three ways:

1. **Immediate cancel**: a `DELETE` with `cancel_at_period_end: false`.
2. **Scheduled cancel reaching the period end**: after a `DELETE` with `cancel_at_period_end: true`, when `current_period_end` passes.
3. **Payment recovery exhausted**: a subscription in [recovery](https://docs.bachs.io/guides/subscriptions/failed-payments.md#when-recovery-is-exhausted) runs out of retries and your account is set to *cancel* (the default). The cancellation reason is `payment_failed`.

Once `canceled`, a subscription is terminal; a later payment can't revive it. The customer must start a new subscription.

***

## What customers can do themselves

When a payment fails, the customer receives an email with a hosted link to update their card. Completing it charges the outstanding invoice and reactivates the subscription, with no action needed from you. See [Recover failed payments](https://docs.bachs.io/guides/subscriptions/failed-payments.md#the-recovery-link).

***

## Related

> [card] [Proration](https://docs.bachs.io/guides/subscriptions/proration.md)
>
> How plan and seat changes are settled.

> [card] [Subscriptions API](https://docs.bachs.io/api-reference/subscriptions/list-subscriptions.md)
>
> List, retrieve, update, and cancel subscriptions programmatically.


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