← Blog

Claude API for Shopify Chatbot Integration

2026-10-27 · 5 min read · SubToAPI Team

If you're building a Shopify storefront chatbot, you need the Claude API to answer product questions, handle order lookups, and feel conversational without hallucinating prices or inventory. The core integration pattern is straightforward: your chatbot frontend sends customer messages to a backend route, that route pulls relevant Shopify data (product details, order status, policies), feeds it to Claude as context, and streams the response back to the widget.

This article covers the practical steps: setting up API access, structuring product context so Claude doesn't invent answers, handling order-specific queries safely, and streaming replies so the chat feels responsive. We'll also look at why a lot of teams put a thin API layer like SubToAPI in front of Claude instead of managing raw API keys and billing themselves.

Why Shopify Chatbots Need a Specific Integration Pattern

A generic chatbot wrapper around an LLM will cheerfully answer questions about products that don't exist, quote wrong prices, or promise shipping times that aren't accurate. Shopify chatbots need grounded answers, which means:

The integration isn't just "connect an API key to a chat widget." It's a data pipeline where Shopify's Storefront/Admin API and Claude's Messages API work together.

Step 1: Fetch Shopify Product Context

Before calling Claude, query the Shopify Storefront API (or your own cached product feed) for the products relevant to the customer's question. A simple approach:

async function getProductContext(query) {
  const res = await fetch(`https://${SHOP}.myshopify.com/api/2024-01/graphql.json`, {
    method: "POST",
    headers: {
      "X-Shopify-Storefront-Access-Token": process.env.SHOPIFY_TOKEN,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: `{
        products(first: 5, query: "${query}") {
          edges { node { title description priceRange { minVariantPrice { amount } } } }
        }
      }`,
    }),
  });
  const data = await res.json();
  return data.data.products.edges.map(e => e.node);
}

Turn that into a plain-text block you can inject into the Claude prompt. Keep it short — five relevant products, not your whole catalog.

Step 2: Send the Message to Claude With Context

Once you have product context, build the request. Put the context in the system prompt, and keep instructions explicit about not inventing details.

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 500,
    "system": "You are a Shopify store assistant. Only answer using the product data provided below. If the product or detail is not in the data, say you are not sure and offer to connect the customer with support.\n\nPRODUCT DATA:\n[inject fetched products here]",
    "messages": [
      {"role": "user", "content": "Do you have the blue hoodie in a medium?"}
    ]
  }'

This is the same Claude Messages API format whether you're calling Anthropic directly or through SubToAPI — the latter just gives you a sub_live_... key, usage metering per team seat, and a single dashboard instead of juggling raw provider credentials. See /docs/messages for the full request shape.

Step 3: Handle Order Status Separately

Order lookups require authentication (email + order number, or a logged-in customer token) and should not go through the same unrestricted flow as general product questions. A clean pattern:

  1. Detect intent (is this an order question?) with a lightweight check or a first Claude call with a classification-only prompt
  2. If it's an order question, require the customer to confirm order number + email
  3. Fetch the order via Shopify Admin API
  4. Pass only that order's data to Claude, scoped to that single conversation

Never let Claude fetch arbitrary order data itself in a Shopify chatbot — always resolve the data server-side first, then hand it a narrow, pre-authorized slice.

Step 4: Stream Responses to the Widget

Customers expect chat responses to appear incrementally, not all at once after a multi-second wait. Claude's streaming mode sends the response as server-sent events, which you pipe straight to your widget's UI.

const response = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "claude-3-5-sonnet-20241022",
    max_tokens: 500,
    stream: true,
    system: systemPromptWithProductContext,
    messages: conversationHistory,
  }),
});

const reader = response.body.getReader();
// pipe chunks to your chat widget as they arrive

Details on event format and reconnect handling are in /docs/streaming.

Step 5: Use Tool Calling for Live Lookups

For questions like "is this still in stock" where you don't want to pre-fetch everything, Claude's tool use lets the model call a function you define — e.g., check_inventory(product_id) — only when needed, rather than stuffing every possible product into context on every message. This keeps prompts smaller and answers fresher. See /docs/tools for the tool definition format.

Where SubToAPI Fits

Most teams building a Shopify chatbot aren't trying to manage API billing, key rotation, and usage tracking across a support team — they just want Claude responses reliably. SubToAPI sits between your chatbot backend and Claude: you get an application key (sub_live_...), per-seat usage visible in one dashboard, and the same streaming/tool-use capabilities, without negotiating a separate enterprise contract. Plans start at €9/month on Solo, with Team and Scale tiers for larger support operations — see /pricing. Setup takes about the same time as reading this article; the quickstart is at /docs/quickstart.

Checklist Before Launch

questions

Do I need Shopify's Admin API or just the Storefront API for a Claude chatbot? Storefront API is enough for product questions (catalog, pricing, availability). You need Admin API access only if the bot handles order status, cancellations, or returns, since that data isn't exposed through Storefront.

Can Claude access my Shopify inventory in real time without me fetching it first? Not directly — Claude doesn't have native access to your store. You either fetch inventory server-side and inject it into the prompt, or define a tool function Claude can call to query live inventory on demand (see /docs/tools).

Is it better to call Claude directly or through a layer like SubToAPI for a Shopify bot? Calling Claude directly works fine for a single developer prototyping. Once you have a support team, multiple environments, or need usage visibility per teammate, a layer like SubToAPI simplifies key management and billing without changing how you call the Messages API.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →