Claude API Shopify App Integration Guide
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:
- Your Anthropic/API key must never be exposed to the browser or theme JavaScript.
- Shopify webhooks and GraphQL Admin API responses (product data, order data) need server-side formatting before they're useful as prompt context.
- Rate limiting and retry logic are easier to manage centrally.
Common integration points:
- Admin app features: bulk-generate product descriptions, tag suggestions, SEO meta text from the Shopify Admin dashboard.
- Storefront widgets: a chat widget calling your app's
/api/chatendpoint, which proxies to Claude. - Post-purchase/support: summarizing order history or answering FAQ-style questions using order data pulled via GraphQL.
- Theme app extensions: rendering AI-generated content (e.g., size guide answers) inside the storefront, fetched from your backend.
Basic Flow: Product Description Generator
A typical merchant-facing feature: select a product, click "Generate Description," and get Claude-written copy back.
- Your app fetches the product via Shopify's Admin GraphQL API.
- Your backend builds a prompt with product title, variants, and existing metadata.
- Your backend calls Claude and streams the result to the admin UI.
- 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:
- Strip internal IDs and irrelevant metafields — they waste tokens and add noise.
- Normalize currency and variant data into plain language.
- For order/support use cases, redact PII you don't need (full addresses, payment details) unless your use case explicitly requires it and you've reviewed Shopify's data handling requirements for apps in their App Store.
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:
- Per-app API keys: issue a
sub_live_...key scoped to your Shopify app instead of sharing one Anthropic account key across environments. - Usage visibility: see token and request usage per key in one dashboard, useful if you're billing merchants based on AI usage or need to cap costs per store.
- Team access: if multiple developers work on the app, give each a seat rather than sharing credentials.
- No API format changes: requests to
/docs/messagesand/docs/streamingmatch Claude's native format, so switching is a base-URL change, not a rewrite.
Check /pricing for Solo, Team, and Scale plans, or start with a free trial at /signup.
Deployment Checklist
- Keep the Claude API call server-side; never expose keys in theme JS or client bundles.
- Cache generated content (descriptions, FAQ answers) in your app's database to avoid regenerating on every page load.
- Add a loading/streaming state in Polaris UI components so merchants see progress on longer generations.
- Log token usage per store if you plan to meter or rate-limit AI features per merchant plan tier.
- Test with Shopify's development store and a sandbox API key before going live on the App Store.
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.