← Blog

Claude API Shopify App Integration Guide

2026-11-24 · 5 min read · SubToAPI Team

Integrating the Claude API into a Shopify app means connecting your Shopify backend (an embedded app, a theme app extension, or a custom checkout/post-purchase flow) to Anthropic's models so merchants can generate product copy, answer customer questions, summarize reviews, or power an AI shopping assistant. The core work is: call Claude from your server (never from the storefront client), pass Shopify data as context, and stream the response back into your app's UI.

This guide walks through the practical pieces: where in a Shopify app architecture the Claude call belongs, how to structure the request with product/order data, handling auth and rate limits safely, and when a managed gateway like SubToAPI is worth using instead of hitting Anthropic's endpoint directly.

Where Claude Fits in a Shopify App

Shopify apps typically run as a Node/Express or Remix backend (per Shopify's app template) with a frontend embedded via Polaris and App Bridge. Claude calls should always originate server-side because:

Common integration points:

Basic Flow: Product Description Generator

A typical merchant-facing feature: select a product, click "Generate Description," and get Claude-written copy back.

  1. Your app fetches the product via Shopify's Admin GraphQL API.
  2. Your backend builds a prompt with product title, variants, and existing metadata.
  3. Your backend calls Claude and streams the result to the admin UI.
  4. The merchant reviews and saves it back via a GraphQL mutation.

Example server-side call using SubToAPI's Claude-compatible endpoint:

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-sonnet-4-5',
    max_tokens: 400,
    messages: [{
      role: 'user',
      content: `Write a concise, benefits-led product description for:
Title: ${product.title}
Variants: ${product.variants.map(v => v.title).join(', ')}
Tags: ${product.tags.join(', ')}`
    }]
  })
});

const data = await response.json();
const description = data.content[0].text;

This pattern works identically whether you're calling Anthropic's API directly or a gateway — the request shape mirrors Claude's native Messages format, so you're not locked into a proprietary SDK. See /docs/messages for the full request/response schema.

Handling Shopify-Specific Context

Claude performs better with structured, trimmed context rather than raw JSON dumps. Before sending Shopify data to Claude:

For a customer support assistant, a reasonable prompt structure looks like:

const systemPrompt = `You are a support assistant for an online store.
Answer only using the order and product data provided. If you don't know, say so.`;

const userPrompt = `Order #${order.name}, status: ${order.fulfillmentStatus}.
Items: ${order.lineItems.map(i => i.title).join(', ')}.
Customer question: ${question}`;

Streaming for a Responsive Chat Widget

If you're building an in-app chat assistant, streaming matters — merchants and shoppers expect token-by-token output, not a 5-second blank screen. Claude's streaming API (and SubToAPI's identical implementation) uses server-sent events:

const res = 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-sonnet-4-5',
    max_tokens: 500,
    stream: true,
    messages: [{ role: 'user', content: userPrompt }]
  })
});

for await (const chunk of res.body) {
  // forward chunk to your WebSocket or SSE connection with the client
}

Details on event formats are in /docs/streaming.

Tool Use for Live Shopify Lookups

If your assistant needs to check live inventory or order status rather than relying on static context, Claude's tool use lets the model call back into your app mid-conversation — e.g., a get_order_status tool that queries Shopify's API and returns structured JSON for Claude to incorporate into its answer. This avoids stuffing every possible data point into the initial prompt. See /docs/tools for the tool schema and multi-turn flow.

Why Use a Gateway Instead of Calling Anthropic Directly

You can call Anthropic's API directly from your Shopify app backend with your own Anthropic account. Where a gateway like SubToAPI helps:

Check /pricing for Solo, Team, and Scale plans, or start with a free trial at /signup.

Deployment Checklist

Questions

Do I need Shopify Plus to integrate Claude? No. Claude API integration works with any Shopify plan since it's handled in your app's backend, independent of the merchant's Shopify tier.

Can I call Claude directly from Shopify theme JavaScript? No — this exposes your API key publicly. Always route calls through your app's authenticated backend, which then calls Claude or a gateway like SubToAPI.

Does streaming work inside the Shopify admin embedded app? Yes. You stream from your backend to the embedded app frontend via SSE or WebSockets, the same pattern used for any embedded Shopify app feature; see /docs/streaming for the event format.

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 →