Skip to main content
Browser code cannot hold a Flexprice API key. A key reads and writes your whole environment, and anything shipped to a browser is public. Two patterns give client code the data it needs without the key: Both feed the UI kit the same way: fetch, map into props, render.

Pattern 1: Fetch through a portal session

Your backend asks Flexprice for a session token for one customer. The browser then calls the /v1/customer/portal endpoints directly with that token. The token cannot see any other customer and expires after one hour.
1

Mint a session on the server

2

Call portal endpoints from the browser

/subscriptions and /invoices bind a JSON body and reject an empty one with a validation error, so send at least {}; both take page and limit. /wallets ignores the body, so the same helper works for it.
3

Render

/wallets returns an array because a customer can have several wallets or none, so pick the one to show and skip the card when it is empty. The adapt* functions are exported by the kit and map raw API responses into each component’s props. See Install the UI kit.
Portal endpoints available to the browser include the customer’s profile and usage summary, subscriptions, invoices and PDFs, wallets with transactions and top-ups, checkout sessions, and saved payment methods. See the Portal API reference for every path.
Mint the session when the customer opens the billing page, not at login. Read expires_at and mint a new one when it passes rather than storing tokens.

Pattern 2: Fetch through a backend proxy

Your backend calls Flexprice with the SDK and exposes only what the client needs, shaped for your UI. This is the right pattern for entitlement checks that gate features, because the check runs where you can trust it.
getCustomerEntitlementsByExternalID takes the external ID as a plain string. Each entry in its features array has feature, entitlement, and sources and no usage figures, so the usage summary supplies currentUsage. The usage summary accepts the same external ID as customerLookupKey. Endpoints the proxy typically wraps: The client then calls your endpoint with its normal session and renders. If the proxy returns the API response unchanged, the kit’s adapters do the mapping; if it returns your own shape, map it to the component’s props yourself and run the matching normalize* function on it first:

Which pattern should you use?

  • Start with a portal session if you are building a billing page and want to ship fast. Every read the page needs already exists under the portal.
  • Use a backend proxy when the data gates behaviour (can this user call this feature?), when you want to cache, or when the UI shows Flexprice data next to your own.
  • Mix them. A pricing page can read plans through a proxy while the account page uses a portal session.

Harden client access

Caching, fallback, and what never to expose.

Usage widgets

Prop shapes for the components above.