Skip to main content
This page is the exhaustive reference. For task-shaped guides start with the Quickstart and its siblings.

Backend API

Resource namespaces: creem.<namespace>.*

All methods take explicit arguments. Use them directly in your own Convex functions, or let creem.api({ resolve }) generate ready-to-export wrappers. creem.subscriptions.* Set new Creem(components.creem, { cancelMode: "scheduled" }) to make normal cancel actions end at the paid period boundary and surface subscription.scheduled_cancel. Pass revokeImmediately on an individual cancel call when you need to override that default. creem.checkouts.* creem.products.* creem.customers.* creem.orders.* creem.credits.* Entity-scoped methods are the preferred backend API. They resolve the default credit account from a trusted billing entity and keep provider account IDs out of client arguments. Do not export the raw primitives directly as public Convex actions. Composite helpers (top-level methods)

creem.api({ resolve }) convenience exports

Generates ready-to-export Convex function definitions. Each function calls your resolve callback, then delegates to the corresponding namespace method. creem.api() does not generate public credit-account creation, credit, or debit actions. Those operations must stay behind app-owned backend functions.

The resolver

Every generated function except the public products.list and products.get calls resolve(ctx, request). Only uiModel and checkouts.create accept an entityId from the browser (sent by <Subscription.Root entityId>) and pass it as request.entityId; every other call, and a widget that names no entity, passes an empty request. The value comes from the browser, so authorize it exactly like the default entity before you return it. A custom wrapper declared with checkoutCreateArgs alone rejects a call that names an entity. Resolvers written with one argument, async (ctx) => ..., keep working: they serve every call that names no entity. A call that names an entity is served for that entity or not at all. When the resolver returns a different entityId, uiModel and checkouts.create throw a ConvexError (“The resolver did not resolve the requested billing entity”) instead of reading or billing the default entity. A null result keeps its usual meaning: uiModel returns the catalog-only model and checkouts.create throws Not authenticated. See Advanced → Billing a named entity.

expectedEntityId

checkouts.create, subscriptions.update, .cancel, .resume, .pause, .cancelScheduledUpdate, plans.activate and credits.getBalance (which creates the entity’s default credits account when it has none) take an optional expectedEntityId: the entity the widget showed when the person acted. The connected widgets send it whenever they show an entity, from the model they display, captured when the action starts. They don’t when they show none yet: on Credits.Root’s first load, and on a checkout started before the billing model loaded (signed out). A checkout intent saved for sign-in carries it, so it resumes for the entity shown when it was saved; one saved before any entity was shown takes the first signed-in model’s. What it guarantees: when the entity the call bills (the resolver’s answer, or the named entityId) isn’t expectedEntityId, the call is refused with a ConvexError with code: "entity-changed" (“The billing entity changed, so nothing was sent”), and nothing is billed, changed or created. So a call never acts on another entity than the one on screen: not after the resolver’s default moved (an active organization switched in another tab) while a guard waited, and not from a part, callback or nested widget that outlived the screen it came from. A call without it bills the resolved entity as before. The check lives in the namespace methods too (creem.checkouts.create, creem.subscriptions.*, creem.appPlans.activate, creem.credits.getBalanceForEntity), and the shared arg validators (checkoutCreateArgs, subscriptionUpdateArgs, subscriptionCancelArgs, subscriptionResumeArgs, subscriptionPauseArgs, appPlanActivateArgs, creditsGetBalanceArgs) accept it. A custom wrapper built on them that spreads its args into the namespace method gets the same check. One that declares its own args has to accept expectedEntityId (spread expectedEntityArgs), or it rejects the widgets’ calls: update such wrappers in your backend together with this version. A custom credits.getBalance also has to return the resolved entityId with the balance, as the generated one does, because Credits.Root sends it back on a refresh. Without it, refreshes go unchecked. When Credits.Root gets entity-changed, it drops the balance it showed, so the next refresh loads the current entity’s. Every generated function declares a real Convex returns validator, so Convex clients infer the concrete result type instead of any. The matching TypeScript types are derived from those validators with Infer<>, which is why ConnectedBillingApi can pin each reference’s return type and reject a mis-wired export at compile time. snapshot and creem.getBillingSnapshot(...) return the backend billing snapshot:
Mental model:
  • subscriptions mirrors Creem recurring subscriptions and supports multiple simultaneous rows, such as a base subscription plus add-ons.
  • orders mirrors Creem orders. Subscription checkouts also create orders, but the snapshot only exposes one-time orders as owned one-time access.
  • appPlanAssignments stores Convex-Creem-owned current or scheduled app-owned plans such as free plans, no-card trials, and custom internal plans.
  • access is a derived read model that combines active subscriptions, paid one-time orders, and active app-plan assignments. It is not a separate table and should not be treated as the source of truth.

Infrastructure

Direct API access with creem.sdk.*

The resource namespaces above cover all billing features that stay in sync with Convex via webhooks. Some Creem API resources have no webhook support, so the component cannot mirror them in Convex DB. For these, use creem.sdk.* directly inside your own Convex actions. It is the same Creem SDK client, already configured with your API key:

Component Reference

All components share identical props across Svelte and React.
  • Import: @creem_io/convex/svelte or @creem_io/convex/react
  • CSS class prop: class in Svelte, className in React
  • Children: Svelte Snippet / React ReactNode
  • Svelte components use Svelte 5 runes and snippet rendering ({@render ...})
See the Svelte example and React example for complete integrations. The components below read the provider and talk to Convex directly. Everything under Billing state components, plus <CheckoutButton> and <PlanChoice> below, takes plain props instead.

<CreemConvexProvider>

Required context boundary for connected widgets. Render it around any Subscription, Product, BillingPortal, BillingHistory, or Credits widgets. Connected widgets no longer accept direct api={...} props. Pass the API to CreemConvexProvider once. createCreemReact / createCreemSvelte return a spreadable binding: <CreemConvexProvider {...billing}>.

<Subscription>

The subscription namespace. Subscription.Root owns billing state and actions; everything else registers a plan or renders a slot inside it. It is a plain namespace object, so render <Subscription.Root> or <Subscription.Item>, never a bare <Subscription>.

<Subscription.Root>

Container for subscription plan cards. Handles billing cycle toggle, checkout, plan switching, cancellation, and unit management. Use unstyled when composing your own pricing cards with Subscription.Grid, Subscription.ItemTitle, Subscription.ItemPrice, Subscription.ItemDescription, Subscription.ItemBadge, Subscription.ItemCTA, Subscription.ItemPriceCaption, Subscription.UnitPicker, Subscription.Cancel, Subscription.GroupSelector, or Subscription.IntervalSelector. The default generated pricing cards remain the fast styled path. Styled compound defaults use the package’s creem-base: Tailwind variant, which places library defaults in the base cascade layer. Consumer class/className utilities like font-bold, text-xl, or bg-emerald-600 therefore override the built-in defaults without tailwind-merge. UpdateBehavior controls paid subscription updates:
  • "proration-charge-immediately" prorates and charges the difference now. This is the default.
  • "proration-charge" prorates and charges on the next invoice.
  • "proration-none" skips proration; the change takes effect on the next billing cycle.
  • "period-end" keeps the current subscription active until currentPeriodEnd, then applies the target plan or unit count from a scheduled Convex job. The job sends the change to Creem with proration-none one hour before currentPeriodEnd, so the renewal bills the new plan or count; set periodEndUpdateLeadMs on new Creem(...) to change that lead time. The pending change’s effectiveAt stays the period end.
The first three values map directly to Creem’s paid subscription update behavior. updateBehavior intentionally does not include "immediate" because Creem paid-to-paid switches cannot be immediate cancellation. AppPlanUpdateBehavior controls paid-to-app-owned target switches:
  • "period-end" schedules Creem cancellation for the billing period boundary, then activates the app-owned target plan at that time. This is the default.
  • "immediate" calls Creem cancellation with mode: "immediate" and assigns the app-owned plan straight away.
Paid-to-app-owned is a cancellation flow because the target entitlement is fulfilled by your app rather than Creem. Use appPlanUpdateBehavior, not updateBehavior, when you want to choose between period-end and immediate cancellation. Until Creem supports native scheduled subscription updates, the Creem customer portal will still show the current subscription as active and will not know about pending app-side paid-to-free assignment. Use a resolver function when upgrades and downgrades should behave differently:

<Subscription.Item>

Registers a plan inside <Subscription.Root>. Without children it registers only, and the root renders the default pricing card. With children it becomes the card wrapper and provides the item context that every Subscription.Item* slot reads. Slots placed outside an item throw. Supported billing cycles: every-month, every-three-months, every-six-months, every-year.

<Subscription.Grid>

Layout wrapper for custom composed subscription cards.

<Subscription.Group>

Conditional group wrapper for custom composed subscription sections.

<Subscription.GroupSelector>

Group selector for groupSelector="external" composition.

<Subscription.IntervalSelector>

Billing-cycle selector for intervalSelector="external" composition.

<Subscription.ItemPriceCaption>

Secondary price text for inherited unit quantities, such as $30/mo × 3 units. Pair it with <Subscription.ItemPrice> when a custom card should show the total bill as the primary price and the unit calculation as supporting text.

<Subscription.ItemTitle>, <Subscription.ItemPrice>, and <Subscription.ItemDescription>

Text slots for custom subscription cards. Each resolves its value from the current Subscription.Item context. Subscription.ItemPriceCaption accepts the same class/className prop.

<Subscription.UnitPicker>

Composable quantity control for unit-based plans. Use it inside a custom <Subscription.Item> when your card owns the markup. For inactive unit plans it updates the checkout quantity; for the active unit plan it renders the change/update flow when subscription unit updates are available. Pass detailed to also show the current subscribed quantity above the change button. It returns null on switch-plan cards so the current subscribed quantity is not mistaken for a target quantity. In unstyled mode, pass class/className plus slot classes such as rowClass, labelClass, actionsClass, secondaryClass, primaryClass, and numberInputClass in Svelte. React uses the same names with Name suffixes, for example rowClassName and primaryClassName.

<Subscription.ItemCTA>

Composable subscription action button.

<Subscription.ItemBadge>

Composable badge for current/recommended/custom plan labels.

<Subscription.Cancel>

Composable cancel button for the active subscription card. It opens the same root-owned confirmation dialog as the default pricing card, and renders nothing when the card is not active or cancellation is unavailable.

<Product>

The one-time and repeating product namespace. Product.Root owns ownership tracking, upgrade transitions, and checkout; Product.Item registers a product inside it.

<Product.Root>

Container for one-time or repeating product cards. Handles ownership tracking, upgrade transitions, and checkout. Transition types:

<Product.Item>

Registers a product inside <Product.Root>.

<BillingPortal>

Button that opens the Creem customer billing portal. Auto-hides when the billing entity has no Creem customer record, or when canAccessPortal is false.

<BillingEmail>

Form that shows and changes the email address Creem sends invoices and receipts to. Auto-hides when the billing entity has no Creem customer record, when canManageBillingEmail is false, or when customers.billingEmail and customers.updateBillingEmail are not both in the connected API. Save stays disabled until the input holds a valid address that differs from the current one. A failed load shows a “Try again” button. Labels live under billingEmail in the i18n labels. The widget sends the entity it displays (uiModel.snapshot.entityId) as expectedEntityId. When the resolver has moved to another entity in the meantime, the actions answer "entity-changed" without touching Creem, and the widget reloads instead of saving one organization’s address into another. When other billing entities share the entity’s Creem customer, a save is refused with "shared-customer" and the form shows the sharedCustomer label instead of changing an address the other entities use. <BillingEmail /> is the same component as <BillingEmail.Root />. Without children it renders the default layout; with children it renders a <form> around your layout and provides the state to the parts below. Other props are forwarded to the <form>. Parts. Each part must be rendered inside BillingEmail.Root and throws otherwise. class/className is added to the part’s default classes (which sit in a lower CSS layer, so your utilities win); other props are forwarded to the element, except the ones the root wires. Text parts accept children to replace their label. To read the state in your own component, use useBillingEmail() (React) or getBillingEmailContext() (Svelte) inside the root.

<BillingHistory>

Paginated transaction history backed by Creem’s transaction search endpoint. This renders transaction rows only. Invoice and receipt documents are not included in this component. Add the generated transaction action to your connected API:

<Credits>

The customer-credits namespace. Credits.Root loads the balance and provides context; the remaining pieces are display slots you compose inside it.

<Credits.Root>

Credit balance widget backed by the provider’s credits.getBalance action.

<Credits.Title>

<Credits.Amount>

<Credits.Refresh>

<Credits.Error> and <Credits.Status>

Display credit API errors or loading/status text. Both accept class/className.

Billing state components

Fed from the billing snapshot rather than the provider. Use them to surface lifecycle states anywhere in your app, including outside CreemConvexProvider.

<BillingGate>

Conditionally renders children based on available billing actions.

<CheckoutSuccessSummary>

Displays a success banner after checkout. Parses Creem query params automatically. React also exports a useCheckoutSuccessParams() hook that returns the parsed params directly.

<ScheduledChangeBanner>

Shows a scheduled cancellation or app-side period-end update notice. In Svelte, inside a connected provider, pass subscriptionId and the widget derives the current period, scheduled update, target label, undo/resume handlers, and i18n from the billing model; without onResume or onUndoUpdate it calls the generated subscriptions.resume and subscriptions.cancelScheduledUpdate itself. Inside a Subscription.Root, those derived handlers follow the root: none while it doesn’t allow resume, and they send through its billing gate. Inside a root that names an entity, the banner renders nothing, in both frameworks. The React component reads no provider: it takes its state and handlers as props.

<PaymentWarningBanner>

Shows a warning for pending, refunded, or partially refunded payments.

<TrialLimitBanner>

Page-level notice that the entity is on a trial. Subscription.Root already shows a countdown badge on the active plan card, so use this banner where no pricing card renders, such as an app shell or dashboard header. Renders nothing when no subscription is trialing.

<CheckoutButton>

Standalone checkout button for places that have no pricing card: a nav bar, a marketing page, an in-app upsell. It reads no provider context, so it works anywhere; you supply the product and handle the checkout call.
Marketing page
Inside a Subscription.Root or Product.Root, use Subscription.ItemCTA or let the default cards render instead. Those are wired to the root’s checkout flow, including the guards and permission flags.

<PlanChoice>

The plans as one single choice: a radio list, each option with its title, description (rendered as Markdown) and price, and one checkout button for the plan chosen. It is what <Subscription.Root layout="choice"> renders in place of the card grid; render it yourself for a layout of your own. Like <CheckoutButton>, it reads no provider context and calls nothing: you pass the plans and handle the checkout in onCheckout. It offers the plans with a Creem product for exactly selectedCycle, and leaves out free, trial and enterprise plans. Unlike the cards, it never offers a plan with another cycle’s product. Without selectedCycle it offers one-time products (the catalog’s custom key). A plan any of subscribedProductIds belongs to, at any of its cycles, shows the current-plan badge and can’t be chosen, so the choice never sells a subscribed tier again. The plan chosen first is defaultPlanId, else the recommended plan, else the first one, always among the plans offered and never the current one; when the chosen plan is no longer offered (another cycle, a new subscription), the choice falls back the same way. A purchase here always starts a new checkout, never a plan switch. For a unit-based plan the price shown is per unit, and the checkout sends units. The button is disabled while disableCheckout is set, while nothing can be chosen, without onCheckout, and while the promise onCheckout returns is pending. When onCheckout throws or rejects, the button unlocks and the error is logged with a [creem] prefix; show errors to the person from inside onCheckout, as Subscription.Root does. React also exports its props type, PlanChoiceProps. Labels: subscription.continueToCheckout (“Continue to checkout”, the button), subscription.choosePlan (“Choose a plan”, the radio group’s accessible name), subscription.currentPlan (the current-plan badge) and checkout.loading (the button while onCheckout is pending). The first two are optional in BillingLabels, so a complete label object written without them still type-checks and gets the English defaults. Styling hooks: the options are Ark UI’s radio group, so its parts carry data-scope="radio-group" and data-part="root", "item", "item-control" or "item-text"; each item, control and text carries data-state="checked" or "unchecked", and an option that can’t be chosen carries data-disabled. The price carries data-part="price" and the button data-part="checkout".

Troubleshooting