CommerceForAI

Quickstart

From zero to a paid test order. You'll need a Stripe account and a CommerceForAI API key.

1. Get an API key

During the beta we create your store with you and connect it to your Stripe account. You'll get an API key that starts with cfa_test_. Keep it on the server, never in browser code.

.env.local
COMMERCEFORAI_API_KEY=cfa_test_...

2. Install the SDK

npm install commerceforai

3. Create a product

Use variants for sizes or colors. Omit inventory for unlimited stock.

import { Commerce } from "commerceforai";

const commerce = new Commerce(); // reads COMMERCEFORAI_API_KEY

const { data: tee, error } = await commerce.products.create({
  name: "Classic Tee",
  images: ["https://example.com/tee.png"],
  variants: [
    { name: "S", sku: "TEE-S", price: 2500, inventory: 20 },
    { name: "M", sku: "TEE-M", price: 2500, inventory: 20 },
    { name: "L", sku: "TEE-L", price: 2500, inventory: 20 },
  ],
});
if (error) throw new Error(error.message);

4. Start a checkout

This holds the stock and returns a Stripe-hosted payment page. Redirect the customer to url.

const { data: checkout, error } = await commerce.checkouts.create({
  items: [{ variant_id: tee.variants[1].id, quantity: 1 }],
  success_url: "https://example.com/thanks?session={CHECKOUT_SESSION_ID}",
  cancel_url: "https://example.com/",
  shipping_rates: [{ name: "Standard", amount: 500, min_days: 3, max_days: 7 }],
});

if (error?.type === "out_of_stock") {
  // error.available tells you how many are left
}
return Response.redirect(checkout!.url!, 303);

5. Pay and see the order

Pay with Stripe's test card 4242 4242 4242 4242. Stripe notifies CommerceForAI, which creates the order and commits the stock. There is no webhook code for you to write.

const { data: orders } = await commerce.orders.list({ status: "paid" });
// orders.data[0] → { number: 1001, status: "paid", email, shipping_address, items, total, ... }

6. Ship it

await commerce.orders.fulfill(1001, { carrier: "USPS", tracking_number: "9400..." });

Or buy the label through your EasyPost or Shippo account (shipping guide), or let a print-on-demand partner ship it (print-on-demand guide).