StoreKitdocs
SDK

Core client

createStorefrontClient() — the framework-agnostic client for any JavaScript runtime.

createStorefrontClient() from @usestorekit/sdk is the foundation the Next.js and React adapters build on. Use it directly when there's no adapter for your framework yet, or in scripts, workers, and other backends.

import { createStorefrontClient } from "@usestorekit/sdk";

const client = createStorefrontClient({
  baseURL: "https://api.your-storekit.com",
  storeKey: process.env.STOREFRONT_STORE_KEY, // server-side only!
});

const { data, error } = await client.products.list({ limit: 12 });

The core client sends the store key directly. Only run it where the key is safe — a server, a build script, an edge function — never in the browser. For browser code use the React client, which proxies through your server.

Configuration

Prop

Type

Explicit cart ids

Unlike the cookie-backed adapters, the core client is explicit about cart ids — there's no ambient cookie to track them:

const { data: cart } = await client.cart.create({ items: [{ variantId, quantity: 1 }] });
await client.cart.addItem(cart.id, { variantId: other, quantity: 1 });
await client.cart.setQuantity(cart.id, cart.items[0].id, 3);
await client.cart.get(cart.id);

Persist the returned cart.id yourself (cookie, localStorage, DB).

Sessions

By default the client uses an in-memory session (one token for the client's lifetime). After auth.verifyOtp, the token is stored automatically:

await client.auth.verifyOtp({ phone, otp }); // token stored in the session store
await client.customer.get();                  // now authenticated

For multi-user servers, give each user their own client + session so tokens don't leak across requests. See Sessions.

Interceptors

const client = createStorefrontClient({
  baseURL,
  storeKey,
  onRequest: ({ url }) => console.time(url),
  onResponse: ({ url }) => console.timeEnd(url),
  onError: (err) => report(err),
});

Escape hatches

client.$transport; // low-level typed HTTP layer: request<T>(method, path, args?)
client.$session;   // the active SessionStore
client.$storefrontUrl; // the configured storefront base URL

On this page