API Reference
Core types, methods, and interfaces in Billing SDK.
createBilling
Creates a billing client with a provider adapter and plan definitions.
createBilling<Plans>(input: {
adapter: BillingAdapter;
plans: Plans;
storage?: StorageAdapter;
}): BillingClient<Plans>definePlans
Defines plan configurations with typed feature entitlements.
definePlans<Plans>(input: Plans): PlanDefinitions
// Plan shape:
{
[planId: string]: {
name: string;
prices: { id: string; amount: number; currency: string; interval?: string }[];
features: {
[featureKey: string]: { limit: number; reset?: "month" | "year" } | boolean;
};
};
}BillingClient
The main client returned by createBilling():
interface BillingClient<Plans> {
adapter: BillingAdapter;
plans: Plans;
customers: {
create(input): BillingCustomer;
get(input): BillingCustomer;
getByExternalId(input): BillingCustomer;
};
checkout: {
create(input): CheckoutSession;
};
subscriptions: {
get(input): BillingSubscription;
list(input): BillingSubscription[];
cancel(input): BillingSubscription;
};
entitlements: {
check(input): EntitlementResult;
list(input): EntitlementListItem[];
};
usage: {
report(input): UsageRecord;
get(input): UsageRecord;
};
webhooks: {
verify(input): BillingEvent;
};
portal: {
create(input): PortalSession;
};
}Error Types
BillingError — Base error classBillingConfigurationError — Missing or invalid configBillingProviderError — Provider API errorBillingWebhookError — Webhook verification failedBillingAuthenticationError — Invalid API keyBillingNotFoundError — Resource not foundBillingCapabilityError — Feature not supported by adapterBillingValidationError — Input validation failedBillingIdempotencyError — Idempotency conflict