Overview
Icon for AI Shopping Assistant

AI Shopping Assistant

Catalog-grounded AI chat for your storefront

medusa-ai-chat

An AI shopping assistant for Medusa v2 storefronts that only says what your store data says. It searches the catalog, reads prices, stock, variants and shipping rates through tools, quotes your own policy pages, streams the answer, and hands the visitor over to a human on WhatsApp (pre-filled message with a summary) whenever the question is a complaint, a refund, a negotiation, a custom order, or something it cannot answer. A sentence-level guard drops any amount the tools did not return, so an invented price never reaches the visitor.
Asisten AI untuk storefront Medusa v2 yang hanya menjawab dari data toko: cari produk, harga, stok, ongkir, kebijakan, streaming, dan oper ke WhatsApp CS dengan ringkasan obrolan. Angka yang tidak berasal dari tools tidak pernah tampil.

Screenshots

Admin → AI Assistant (demo store, example conversations) and the chat panel of a storefront (Kiln, the theme of hauskayu.com).

Overview: today's spend against the daily budget, 30-day counts Conversations: filters, cost, handover and thumbs per chat A conversation: tools called, tokens, cost, WhatsApp handover Settings: switch, budget, greeting per language, extra instructions, FAQ Storefront, phone (Indonesian): answer with a product card Storefront, desktop (English): handover to WhatsApp

Compatibility

Plugin Medusa Node Tested in CI on 0.1.x 2.19.0 or newer 2.x (Copy to clipboard^2.19.0) 20.19+ or 22.12+ Medusa 2.19.0 and 2.22.2

Model providers: Anthropic (default, Copy to clipboardclaude-haiku-5-5), any OpenAI-compatible chat-completions API, and a deterministic mock for tests. Optional integrations it detects at runtime: the Meilisearch store route of Copy to clipboard@rokmohar/medusa-plugin-meilisearch (better search), the public rate card of Copy to clipboardmedusa-fulfillment-zone-rate (shipping estimates), the Local Notification Provider on channel Copy to clipboardfeed (Admin bell on handover).

Quick start

npm install medusa-ai-chat
// medusa-config.ts
plugins: [
{
resolve: "medusa-ai-chat",
options: {
store: { name: "Haus Kayu", description: "Teak kitchenware and custom furniture from Jepara.", location: "Jepara, Indonesia" },
storefront: { url: "https://hauskayu.com", custom_path: "/custom", path_prefixes: ["", "/us"] },
assistant: { name: { id: "Asisten AI Haus Kayu", en: "Haus Kayu AI Assistant" }, locales: ["id", "en"] },
contact: { whatsapp: "6281234567890", hours: { id: "Setiap hari 08.00–21.00 WIB", en: "Every day 8 am–9 pm WIB" } },
knowledge: {
pages: {
shipping: { id: "https://hauskayu.com/shipping/markdown", en: "https://hauskayu.com/us/shipping/markdown" },
returns: { id: "https://hauskayu.com/returns/markdown", en: "https://hauskayu.com/us/returns/markdown" },
},
},
budget: { daily_usd: 1, timezone: "Asia/Jakarta" },
},
},
],
export AI_CHAT_API_KEY=... # the model API key lives in the environment, never in options
npx medusa db:migrate

Open AI Assistant in the Admin sidebar: switch, greeting, FAQ, daily budget, conversations, statistics. Storefront integration: Copy to clipboardGET /store/ai-chat/config, Copy to clipboardPOST /store/ai-chat/sessions, then stream Copy to clipboardPOST /store/ai-chat/sessions/:id/messages (server-sent events). Types and an SSE reader ship in Copy to clipboardmedusa-ai-chat/client. The Kiln theme has a ready-made glass chat panel for this plugin.

What the assistant can and cannot do

It does It never does Searches products and quotes price, stock and variants per region/currency, in the visitor's language (Translation Module) States an amount, discount, stock level or delivery date no tool returned (the guard removes the sentence and offers CS) Gives shipping services, per-kg rates and delivery estimates from the real rate card Promises anything: discounts, reservations, refunds, custom work Answers policy questions from your own pages (markdown, text or HTML) and the Admin FAQ Asks for or accepts payment details (card numbers are blocked before the model and masked in storage) Hands over to WhatsApp with greeting, summary, product links and a chat id; posts to the Admin feed Follows instructions found in customer text or catalog data (both are wrapped as data) Streams the answer sentence by sentence Sends a prompt larger than Copy to clipboardlimits.max_prompt_tokens (older turns are summarised first)

Store API

Route Purpose Copy to clipboardGET /store/ai-chat/config?lang= Copy to clipboardenabled, Copy to clipboardover_budget, name, greeting, CS hours, WhatsApp number, privacy path, limits Copy to clipboardPOST /store/ai-chat/sessions Copy to clipboard{ locale, country_code?, region_id?, currency_code?, path_prefix?, page?, consent: true } → Copy to clipboard{ session: { id, token, turns_left } } Copy to clipboardPOST /store/ai-chat/sessions/:id/messages Copy to clipboard{ token, message, page? } → SSE: Copy to clipboardstart, Copy to clipboarddelta, Copy to clipboardproducts, Copy to clipboardhandoff, Copy to clipboardnotice, Copy to clipboarddone, or Copy to clipboarderror Copy to clipboardPOST /store/ai-chat/sessions/:id/handoff Copy to clipboard{ token } → the WhatsApp link for the "Chat with CS" button (summary of the conversation) Copy to clipboardPOST /store/ai-chat/messages/:id/feedback Copy to clipboard{ token, session_id, value: 1 | -1 | 0 }

Every call carries the storefront's publishable key; the tools call your own Store API with the same key, so the assistant sees exactly the products, prices and stock that storefront sees. The session token is random and only its hash is stored; the IP address is stored as a salted hash for rate limiting only.

Admin API

Copy to clipboardGET/POST /admin/ai-chat/settings, Copy to clipboardGET /admin/ai-chat/config, Copy to clipboardGET /admin/ai-chat/stats?days=, Copy to clipboardGET /admin/ai-chat/sessions (filters Copy to clipboardhandoff, Copy to clipboardfeedback, Copy to clipboardflagged, Copy to clipboardlang, Copy to clipboardq), Copy to clipboardGET|DELETE /admin/ai-chat/sessions/:id.

Options

Option Default Notes Copy to clipboardprovider.id Copy to clipboard"anthropic" Copy to clipboard"openai" for any OpenAI-compatible API (Copy to clipboardprovider.base_url, Copy to clipboardprovider.model required), Copy to clipboard"mock" for tests Copy to clipboardprovider.model Copy to clipboard"claude-haiku-5-5" Copy to clipboardprovider.api_key_env Copy to clipboard"AI_CHAT_API_KEY" Name of the environment variable holding the key Copy to clipboardprovider.effort Copy to clipboard"low" Anthropic effort level Copy to clipboardpricing known for Anthropic models USD per million tokens Copy to clipboard{ input, output, cache_read, cache_write }; needed for cost tracking of other models Copy to clipboardstore.name / Copy to clipboarddescription / Copy to clipboardlocation Facts for the model and the WhatsApp greeting Copy to clipboardstorefront.url Base of product links; Copy to clipboardproduct_path default Copy to clipboard/products/{handle}; Copy to clipboardcustom_path (made-to-order page) ; Copy to clipboardprivacy_path default Copy to clipboard/privacy; Copy to clipboardpath_prefixes accepted market prefixes Copy to clipboardassistant.name / Copy to clipboardgreeting Per locale; the Admin greeting overrides Copy to clipboardassistant.locales Copy to clipboard["en"] Locales the storefront may request; the first is the fallback Copy to clipboardassistant.instructions Developer text appended to the system prompt (tone etc.) Copy to clipboardcontact.whatsapp International number without Copy to clipboard+; without it there is no handoff tool Copy to clipboardcontact.hours Per locale; shown next to the CS button and told to the model Copy to clipboardknowledge.pages Copy to clipboard{} topic → locale → URL of a page the Copy to clipboardget_policy tool may read (cached Copy to clipboardcache_seconds, cut at Copy to clipboardmax_chars) Copy to clipboardcatalog.hide_when_metadata Copy to clipboard["secret","hidden"] Products with such metadata set to true are never shown Copy to clipboardcatalog.language first locale Language the catalog is written in; the model retries a failed search with words in it Copy to clipboardcatalog.translation_locales derived Medusa translation locale per assistant locale (Copy to clipboard{ en: "en-US" }); default Copy to clipboard<locale>-<COUNTRY> of the market Copy to clipboardcatalog.fallback_scan Copy to clipboard100 When a search finds nothing, this many products are listed and matched by words (title, description, categories, metadata); Copy to clipboard0 disables Copy to clipboardshipping.enabled Copy to clipboardtrue Copy to clipboardshipping_estimate tool; switches itself off when the zone-rate route is missing Copy to clipboardlimits see below Copy to clipboardmax_message_chars 1000, Copy to clipboardmax_turns 20, Copy to clipboardhistory_messages 12, Copy to clipboardsummarize_after_tokens 8000, Copy to clipboardmax_prompt_tokens 30000, Copy to clipboardmax_output_tokens 700, Copy to clipboardmax_tool_rounds 4, Copy to clipboardper_ip.hour 30, Copy to clipboardper_ip.day 100, Copy to clipboardper_session_minute 6 Copy to clipboardbudget.daily_usd Copy to clipboard1 Spend cap per calendar day in Copy to clipboardbudget.timezone (default UTC); the Admin setting overrides. Over the cap, visitors get the WhatsApp button only Copy to clipboardretention_days Copy to clipboard30 Conversations are deleted by a nightly job Copy to clipboardfeed Copy to clipboard{ enabled: true, channel: "feed", template: "admin-ui" } Admin bell on handover; Copy to clipboardadmin_url for the link Copy to clipboardbackend_url Copy to clipboardhttp://127.0.0.1:$PORT Where the tools reach this server's Store API Copy to clipboardshowCredit Copy to clipboardfalse Small plugin credit under the Admin page

Cost

With Claude Haiku 5.5 the stable prompt (rules + tools, ≈2,500 tokens) is read from the prompt cache after the first call of a 5-minute window; a typical turn with one tool call costs about $0.0005–0.001, a six-turn conversation $0.003–0.006. Cache writes, cache reads, input and output are all counted against the daily budget.

Other model calls on the same budget

Other features of the store that call a model with the same key (a search rewrite, a description helper) can share the assistant's daily budget, Admin statistics, rate limiter and price list through Copy to clipboardmedusa-ai-chat/budget, the only public server API of the package (everything else is internal):

import { budgetStatus, clientIp, ipHash, rateLimits, recordUsage, takeRateLimit } from "medusa-ai-chat/budget"
// in an API route
const status = await budgetStatus(req.scope, { feature: "search", share: 0.3 })
if (status.over_budget) return res.json({ terms: [] }) // the assistant keeps the other 70 %
const { per_ip } = rateLimits(req.scope)
const ip = ipHash(req.scope, clientIp(req))
if (!(await takeRateLimit(req.scope, `search:h:${ip}`, per_ip.hour, 3600))) return res.status(429).end()
const message = await anthropic.messages.create({ /* … */ })
await recordUsage(req.scope, {
model: "claude-haiku-5-5",
feature: "search",
usage: { input_tokens: message.usage.input_tokens, output_tokens: message.usage.output_tokens },
})

Export Copy to clipboardbudgetStatus(container, { feature?, share? }) Today's cap, total spend, the feature's spend and cap, Copy to clipboardover_budget (total reached the cap, or the feature its Copy to clipboardshare of it) Copy to clipboardrecordUsage(container, { usage, model?, feature? }) Adds a call to today's usage row and the feature counter; returns the cost in USD Copy to clipboardpricingFor(container, model?) / Copy to clipboardcostOf(usage, pricing) USD per million tokens (the Copy to clipboardpricing option for the assistant's model, else published prices) and the cost of one call Copy to clipboardrateLimits(container) / Copy to clipboardtakeRateLimit(container, key, max, windowSeconds) The assistant's per-IP limits and a fixed-window counter through the Cache Module, namespaced apart from the assistant's own Copy to clipboardclientIp(req) / Copy to clipboardipHash(container, ip) The visitor's address (Cloudflare header first) and its salted hash for rate-limit keys

Feature counters live in the Cache Module (Redis when the store has it) for two days; the daily total is the persistent usage row the assistant itself reads.

Privacy

Tell your visitors that chat messages are processed by the model provider (Anthropic, or the API you configured) and kept for Copy to clipboardretention_days. The storefront must show a consent notice before the first message and send Copy to clipboardconsent: true; the plugin refuses sessions without it. Card numbers are blocked and masked; IPs are hashed; the Admin can delete any conversation.

Development

See CONTRIBUTING.md. Copy to clipboardnpm run eval -- <storefront base url> sends a red-team prompt set to a running store and prints the answers and guard notices (needs the real provider; costs a few cents).

MIT © Haus Kayu

You may also like

Browse all integrations

Build your own

Develop your own custom integration

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?