Server SDK
Subscriptions
Create and manage subscriptions server-side.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Create and manage subscriptions server-side.
const subscription = await billing.createSubscription({
customerId: "cus_123",
priceId: "price_pro_monthly",
metadata: { source: "api" },
});
| Name | Type | Required | Description |
|---|---|---|---|
customerId | string | Yes | BillingOS customer ID |
priceId | string | Yes | Price ID to subscribe to |
metadata | Record<string, any> | No | Custom key-value pairs |
const subscription = await billing.getSubscription("sub_123");
const updated = await billing.updateSubscription("sub_123", {
priceId: "price_enterprise_monthly",
cancelAtPeriodEnd: false,
});
// Cancel at end of billing period (default)
await billing.cancelSubscription("sub_123");
await billing.reactivateSubscription("sub_123");
interface Subscription {
id: string
customerId: string
stripeSubscriptionId?: string
status: "active" | "past_due" | "canceled" | "incomplete" | "trialing"
currentPeriodStart?: Date
currentPeriodEnd?: Date
cancelAtPeriodEnd: boolean
metadata?: Record<string, any>
createdAt: Date
updatedAt: Date
}