Airwallex logo

Add a chat app with the Assistant SDK

Put an Airwallex shopping assistant on your product pages when you do not already have a chat provider.

Copy for LLMView as Markdown

SDK package

The AI shopping assistant is an element of @airwallex/components-sdk. It is not in the latest stable release. Install a prerelease that includes aiShoppingAssistant. This page uses 1.36.0-alpha.4.

To run Airwallex runs discovery and checkout without procuring a chat provider first, install the Assistant SDK on your product pages.

The SDK stands in for the chat app and nothing else. The catalog, the create checkout API, and the Webhook are the same work either way. Listen for the same sample payload. You can replace the SDK later with a provider of your own without touching them.

Before you begin

Install the SDK

  1. Install the package:

    Shell
    1npm install @airwallex/[email protected]
  2. Initialize the element and mount it:

    JavaScript
    1import { init, createElement } from '@airwallex/components-sdk';
    2
    3await init({
    4 env: 'demo',
    5 enabledElements: ['aiShoppingAssistant'],
    6});
    7
    8const assistant = await createElement('aiShoppingAssistant', {
    9 environment: 'sandbox',
    10 backendUrl: 'https://your-backend.example.com',
    11 merchantId: 'your_merchant_id',
    12 appearance: { mode: 'light' },
    13 uiOptions: { title: 'your-chat-title', displayMode: 'panel', side: 'right' },
    14});
    15
    16assistant.mount('#assistant-chat');

This example targets sandbox. init takes env: 'demo'. The element takes environment: 'sandbox'. Those are separate options.

The SDK obtains a short-lived Bearer token from the session token endpoint you built and uses that same token for chat and for the Airwallex commerce tools. No long-lived keys reach the browser.

The SDK builds the full endpoint URL from backendUrl: it calls {backendUrl}/chat/generate_session_token. Pass the origin that serves your endpoint, such as https://your-backend.example.com, not the endpoint path itself. A trailing slash is ignored.

The element lifecycle is init, createElement, mount, on(event), then destroy. You can also call open, close, toggle, update, and unmount. Events are ready, open, close, error with { instanceId, code, message }, checkoutResult with a status of succeeded, failed, or cancelled and an optional referenceId, and event with { instanceId, name, data }.

PropertyTypeRequiredDescription
backendUrlstringYesBase URL of the backend that serves your session token endpoint. The SDK appends /chat/generate_session_token to it.
merchantIdstringNoMerchant id.
openAICompatibleUrlstringNoYour OpenAI-compatible chat completions URL.
llmTokenstringNoToken for your own chat completions endpoint.
modelstringNoModel name for your own endpoint. The Airwallex-hosted endpoint ignores it.
environment'production', 'sandbox', or 'staging'NoAssistant environment. This is separate from env on init.
appearance.mode'light' or 'dark'NoColor mode. Required when you set appearance.
appearance.variables.colorBackgroundstringNoBackground color.
appearance.variables.colorBorderstringNoBorder color.
appearance.variables.colorTextstringNoText color.
appearance.variables.colorPrimarystringNoPrimary color.
appearance.variables.colorPrimaryTextstringNoText on the primary color.
appearance.variables.fontFamilystringNoFont family.
appearance.variables.borderRadiusstringNoCorner radius.
uiOptions.logoUrlstringNoLogo image URL.
uiOptions.logoAltstringNoLogo alt text.
uiOptions.titlestringNoHeader title.
uiOptions.welcomeHeadingstringNoWelcome heading.
uiOptions.composerPlaceholderstringNoInput placeholder.
uiOptions.suggestions{ label: string, prompt: string }[]NoSuggested prompts. label is shown. prompt is sent.
uiOptions.displayMode'panel' or 'popup'NoDocked panel or floating popup.
uiOptions.panelWidthstringNoPanel width.
uiOptions.panelHeightstringNoPanel height.
uiOptions.zIndexnumberNoStacking order.
uiOptions.side'left' or 'right'NoAnchored screen edge.
uiOptions.offset.xnumberNoHorizontal offset.
uiOptions.offset.ynumberNoVertical offset.

The Assistant SDK asks your backend for a session token, then uses that Bearer token for chat completions and Airwallex commerce tools

Decide who runs the model

The assistant needs a chat completions endpoint. Both options use the same OpenAI-compatible request format.

Host it yourselfUse Airwallex's
Model choiceYoursAirwallex's
System prompt and toneYoursAirwallex's
Conversation dataStays with youPasses through Airwallex
EffortYou run inference and wire up the toolsPoint the SDK at Airwallex

Start with the Airwallex endpoint. Move to your own when you want control over the model or the prompt, or when conversations have to stay in your infrastructure. Your catalog, checkout, and payment integration does not change either way. Bring your own model is not available on the Airwallex-hosted path. If you need a specific model, host the endpoint yourself.

The Airwallex chat proxy validates the session token, forwards the completion, and executes tool calls against the Airwallex MCP server with the same Bearer token

When you use Airwallex's agent, the SDK calls https://copilot.airwallex.com/v1/chat/completions. When you run your own agent, set openAICompatibleUrl to your chat completions URL.

text
1POST /v1/chat/completions HTTP/1.1
2Host: copilot.airwallex.com
3Authorization: Bearer {{ACCESS_TOKEN}}
4Content-Type: application/json
5
6{
7 "stream": true,
8 "messages": [
9 { "role": "user", "content": "Show me running shoes under $150" }
10 ]
11}

The session token is the access_token from Expose an authentication method.

Create chat completion is the only supported operation. Models, embeddings, files, and the assistants surface are not proxied. Rate limits are applied per session by the proxy. Ask your Account Manager for the limits on your account.

You are done when the assistant mounts on a product page, answers a product question, and completes a purchase.

Next steps

Was this page helpful?