You need a Commerce Engine Store ID and publishable Storefront API key from the Admin Portal. The Storefront API key is intended for storefront clients and is scoped by Commerce Engine. Do not confuse it with private admin or payment-provider credentials.
1. Install the SDK
2. Set environment variables
Use the public environment-variable prefix required by your framework:.env.example in the repository and exclude real .env files from version control.
3. Initialize the SDK
For a browser SPA:lib/storefront.ts
Next.js
App Router, Server Components, Server Actions, SSG/ISR, and cookie-backed sessions.
TanStack Start
Route loaders, prerendering, server functions, and client sessions.
Astro
Static/SSR pages, islands, middleware, and request cookies.
SvelteKit
Universal loads, server loads, actions, hooks, and cookie-backed sessions.
4. Make a public catalog request
Public reads are publishable-key-backed and do not create anonymous users or write session storage.5. Start a live session
Cart, wishlist, authentication, customer, order, and payment operations use the session accessor. You may establish the anonymous session eagerly at application startup:ensureAccessToken() before every feature request.
Create the cart with the first item—Commerce Engine does not create empty carts:
variant_id; for products without variants, pass null.
6. Add Hosted Checkout
Hosted Checkout is the recommended checkout implementation for most storefronts. It supplies the cart drawer, authentication, addresses, fulfilment, coupons, loyalty, payments, and confirmation UI.authMode: "provided" and synchronize token changes in both directions. Follow the framework-specific pattern:
Hosted Checkout overview
Architecture, package selection, and integration choices.
Configuration
Authentication modes, callbacks, methods, events, and Quick Buy.
7. Retrieve exact SDK contracts
Before implementing a feature, retrieve the current operation and schema definitions from the LLM-first reference:.md:
Direct REST integration
Use direct REST calls when you are building a non-TypeScript client, an integration that cannot use the SDK, or a custom backend façade. In that mode you are responsible for token storage, refresh, retry, and response-envelope handling.- Staging base URL:
https://staging.api.commercengine.io/api/v1/{store_id}/storefront - Production base URL:
https://prod.api.commercengine.io/api/v1/{store_id}/storefront
/auth/anonymous, login, or refresh flows. Use the generated API reference for exact per-operation security requirements.
Next steps
Production storefront
Full agent execution contract and production validation gates.
Catalog
Product, Item/SKU, variant, search, and PDP decisions.
Authentication
Anonymous, OTP, password, login, logout, and session continuity.
Cart
First-add behaviour, cart mutation, recovery, discounts, and totals.