---
title: "Attach"
openapi: "openapi POST /v1/billing.attach"
---
import { DynamicParamField } from "/components/dynamic-param-field.jsx";
import { DynamicResponseField } from "/components/dynamic-response-field.jsx";
import { DynamicResponseExample } from "/components/dynamic-response-example.jsx";
The attach endpoint subscribes a customer to a plan. It handles new
subscriptions, upgrades, and downgrades automatically. For modifying an
existing subscription (like changing quantities or canceling), use
[update](/api-reference/billing/billingUpdate) instead.
### Common Use Cases
```typescript Subscribe to a plan
const response = await autumn.billing.attach({
customerId: "cus_123",
planId: "pro_plan",
});
if (response.paymentUrl) {
// Redirect customer to checkout
window.location.href = response.paymentUrl;
}
```
```typescript Custom pricing
const response = await autumn.billing.attach({
customerId: "cus_123",
planId: "enterprise_plan",
customize: {
price: {
amount: 999, // $999
interval: "month",
},
},
});
```
```typescript Attach plan with prepaid quantities
const response = await autumn.billing.attach({
customerId: "cus_123",
planId: "team_plan",
featureQuantities: [{ featureId: "seats", quantity: 5 }],
});
```
```typescript Pass metadata to Stripe subscription
const response = await autumn.billing.attach({
customerId: "cus_123",
planId: "pro_plan",
checkoutSessionParams: {
subscriptionData: {
metadata: {
userId: "internal-user-id",
source: "upgrade-flow",
},
},
},
});
```
### Stripe checkout session params
Use `checkoutSessionParams` to pass additional data to the Stripe checkout session. Values you provide are deep-merged with Autumn's internal parameters, so your fields are preserved alongside ones Autumn sets automatically (like `trial_end` or internal metadata).
This is useful for attaching custom metadata to the Stripe subscription created during checkout — for example, linking subscriptions to internal user IDs or tracking the source of the purchase.
### Body Parameters
The ID of the customer to attach the plan to.
The ID of the entity to attach the plan to.
The ID of the plan.
If this plan contains prepaid features, use this field to specify the quantity of each prepaid feature. This quantity includes the included amount and billing units defined when setting up the plan.
The ID of the feature to set quantity for.
The quantity of the feature.
Whether the customer can adjust the quantity.
The version of the plan to attach.
Customize the plan to attach. Can override the price, items, free trial, or a combination.
Base price configuration for a plan.
Base price amount for the plan.
Billing interval (e.g. 'month', 'year').
Number of intervals per billing cycle. Defaults to 1.
Override the items in the plan.
The ID of the feature to configure.
Number of free units included. Balance resets to this each interval for consumable features.
If true, customer has unlimited access to this feature.
Reset configuration for consumable features. Omit for non-consumable features like seats.
Interval at which balance resets (e.g. 'month', 'year'). For consumable features only.
Number of intervals between resets. Defaults to 1.
Pricing for usage beyond included units. Omit for free features.
Price per billing_units after included usage. Either 'amount' or 'tiers' is required.
Tiered pricing. Either 'amount' or 'tiers' is required.
Billing interval. For consumable features, should match reset.interval.
Number of intervals per billing cycle. Defaults to 1.
Units per price increment. Usage is rounded UP when billed (e.g. billing_units=100 means 101 rounds to 200).
'prepaid' for upfront payment (seats), 'usage_based' for pay-as-you-go.
Max units purchasable beyond included. E.g. included=100, max_purchase=300 allows 400 total.
Proration settings for prepaid features. Controls mid-cycle quantity change billing.
Billing behavior when quantity increases mid-cycle.
Credit behavior when quantity decreases mid-cycle.
Rollover config for unused units. If set, unused included units carry over.
Max rollover units. Omit for unlimited rollover.
Maximum rollover as a percentage (0-100) of included + prepaid grant. Mutually exclusive with max.
When rolled over units expire.
Number of periods before expiry.
Free trial configuration for a plan.
Number of duration_type periods the trial lasts.
Unit of time for the trial ('day', 'month', 'year').
If true, payment method required to start trial. Customer is charged after trial ends.
Invoice mode creates a draft or open invoice and sends it to the customer, instead of charging their card immediately. This uses Stripe's send_invoice collection method.
When true, creates an invoice and sends it to the customer instead of charging their card immediately. Uses Stripe's send_invoice collection method.
If true, enables the plan immediately even though the invoice is not paid yet.
If true, finalizes the invoice so it can be sent to the customer. If false, keeps it as a draft for manual review.
How to handle proration when updating an existing subscription. 'prorate_immediately' charges/credits prorated amounts now, 'none' skips creating any charges.
Controls when to return a checkout URL. 'always' returns a URL even if payment succeeds, 'if_required' only when payment action is needed, 'never' disables redirects.
A unique ID to identify this subscription. Can be used to target specific subscriptions in update operations when a customer has multiple products with the same plan.
List of discounts to apply. Each discount can be an Autumn reward ID, Stripe coupon ID, or Stripe promotion code.
The ID of the reward to apply as a discount.
The promotion code to apply as a discount.
URL to redirect to after successful checkout.
Only applicable when the customer has an existing Stripe subscription. If true, creates a new separate subscription instead of merging into the existing one.
Reset the billing cycle anchor immediately with 'now'.
When the plan change should take effect. 'immediate' applies now, 'end_of_cycle' schedules for the end of the current billing cycle. By default, upgrades are immediate and downgrades are scheduled.
Unix timestamp in milliseconds for when the attached plan should start. Future dates create a scheduled subscription.
Additional parameters to pass into the creation of the Stripe checkout session.
Custom line items that override the auto-generated proration invoice. Only valid for immediate plan changes (eg. upgrades or one off plans).
Amount in dollars for this line item (e.g. 10.50). Can be negative for credits.
Description for the line item.
The processor subscription ID to link. Use this to attach an existing Stripe subscription instead of creating a new one.
Whether to carry over balances from the previous plan.
Whether to carry over balances from the previous plan.
The IDs of the features to carry over balances from. If left undefined, all features will be carried over.
Whether to carry over usages from the previous plan.
Whether to carry over usages from the previous plan.
The IDs of the features to carry over usages for. If left undefined, all consumable features will be carried over.
Key-value metadata to attach to the Stripe subscription, invoice, and checkout session created during this attach flow. Keys prefixed with 'autumn_' are reserved and will be stripped.
If true, skips any billing changes for the attach operation.
If true, the customer's plan is activated immediately even when payment is deferred (invoice mode) or pending (Stripe checkout). For Stripe checkout, the customer_product is inserted before the customer completes the hosted form.
### Response
The ID of the customer.
The ID of the entity, if the plan was attached to an entity.
Invoice details if an invoice was created. Only present when a charge was made.
The status of the invoice (e.g., 'paid', 'open', 'draft').
The Stripe invoice ID.
The total amount of the invoice in cents.
The three-letter ISO currency code (e.g., 'usd').
URL to the hosted invoice page where the customer can view and pay the invoice.
URL to redirect the customer to complete payment. Null if no payment action is required.
Details about any action required to complete the payment. Present when the payment could not be processed automatically.
The type of action required to complete the payment.
A human-readable explanation of why this action is required.
```json 200
{
"customer_id": "cus_123",
"payment_url": "https://checkout.stripe.com/..."
}
```