Who this is for
Developers building AI chat interfaces where users can buy physical products across Amazon, Shopify, and beyond. We’ll use the Vercel AI SDK for tool-calling, Stripe Elements for card collection, and Universal Checkout API for submitting orders via Checkout Intents.What you’ll build
A minimal Next.js app with a streaming chat. The assistant can:- Search Amazon (and the wider web) to surface real product URLs.
- Show a Buy button next to results.
- Open a modal that collects buyer identity (name, email, phone) and creates a Checkout Intent with Rye.
- Collect card details using Stripe Card Element and tokenize on the client.
- Confirm the Checkout Intent by sending the Stripe token to Rye, which places the order on the third‑party site.
See Rye in Action
Watch a complete order flow — from product URL to purchase confirmation — all without leaving your app.
You can follow along step-by-step, or clone the demo repo to run the example.
Assumptions
- Next.js App Router on Node 18+.
- You have a Rye API key and will start in staging.
- You have Rye’s Stripe publishable key
- Staging:
pk_test_51LgDhrHGDlstla3fdqlULAne0rAf4Ho6aBV2cobkYQ4m863Sy0W8DNu2HOnUeYTQzQnE4DZGyzvCB8Yzl1r38isl00H9sVKEMu
- Staging:
- We’ll use the AI SDK’s tool-calling with OpenAI, but you can use a different LLM provider if you’d like.
Project structure
This is the general structure of the application and how we’ll organize our files.app/actions.tsx
.
Setup
Create the starter template:Add dependencies
First, install libraries for working with LLMs:Set environment variables
Create a.env
file with these environment variables set.
OPENAI_API_KEY | https://platform.openai.com/settings/organization/api-keys |
RYE_API_KEY | https://staging.console.rye.com/account |
RYE_API_BASE | Either https://staging.console.rye.com/account or https://console.rye.com/account |
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY | Use Rye’s Stripe Publishable Key. |
At this point, you should be able to run
npm run dev
and load the starter app in the browser.1. Create a basic AI Chat app
We’ll build this chat-based storefront incrementally, starting with a basic AI chat interface that we’ll progressively enhance with commerce capabilities. This approach allows us to establish the core conversational flow first, then layer on product search tools, checkout flows, and payment processing. By the end, you’ll have a complete chat experience where users can discover products through natural conversation, review detailed offers with real-time shipping and tax calculations, and complete purchases seamlessly—all powered by Rye’s commerce infrastructure.Set up minimal layout
Before we dive into chat components, let’s set up a minimal layout.Set up the chat API endpoint
To connect our chat interface to an AI model, we need to set up a server-side API route that handles streaming responses from OpenAI’s GPT-5. This endpoint will process incoming messages, send them to the language model, and stream back responses that our client-side chat components can display in real-time. While we’re starting with basic chat functionality, this foundation is designed to easily accommodate tools for product search and other enhanced features later.app/api/chat/route.ts
Build the chat interface
The chat components handle user input, display responses, and provide the foundation for our upcoming product search and checkout features. For now, they manage basic messaging—we’ll add search results, Buy buttons, and checkout modals next.The Chat component will eventually manage our Checkout Modal and rendering fulfillment messages, but to start it’ll contain a stream of messages.The
useChat
hook allows us to connect to the Next.js server endpoint that calls the LLM provider.app/components/Chat.tsx
Restart your server with
npm run dev
and you should be able to load the basic
chat app, send a test message, and see a from the LLM streamed to your browser.2. Surface products in the chat UI
Next, we’ll add product search to transform our chat from a simple conversation into an interactive shopping experience. The Universal Checkout API needs product URLs to generate offers, so we’ll build a tool that finds products and returns their URLs as tool results. When users express shopping intent, the LLM can search for relevant items and display them with buy buttons in chat.Add product search tools
We’ll create a product search tool that allows the LLM to find products on Amazon, enabling discovery and purchase within the chat interface.You might consider integrating with a search engine API like catalog.ai, velou.com, trychannel3.com, etc.
First, let’s define a
ShoppingProduct
interface that we’ll use throughout the app to represent product data from search results, ensuring consistent typing across our tool responses, UI components, and checkout flows.app/lib/types.ts
Build product gallery message types for the UI
We’ll add a new message type that renders product search results as an interactive gallery with buy buttons.The
ProductGalleryMessage
component displays product search results as an interactive gallery within the chat interface. When the LLM searches for products, we render structured product data with images, prices, and ratings instead of plain text. This creates a richer user experience and a way to trigger our checkout flow.We could display products as text descriptions and handle purchases through chat messages, but payment collection requires secure UI elements like Stripe components. The product gallery provides a better user experience while enabling secure checkout outside the chat interface.app/components/messages/ProductGalleryMessage.tsx
3. Initiate checkout
When a user clicks “Buy” on a product in chat, we already have the product URL, but we still need their identity and shipping details before creating a Checkout Intent with Rye. Collecting this information first ensures Rye can return accurate shipping costs, taxes, and availability so the user sees a complete offer before confirming. We’ll open a modal to gather the buyer’s name, email, phone, and shipping address. Once submitted, that data—together with the product URL—is sent to Rye’s API to create a Checkout Intent, which retrieves live pricing and availability from the merchant.Setup the checkout API endpoints
To initiate the checkout process, we’ll create two API endpoints for managing our Rye Checkout Intents:- One to create a Checkout Intent with the product URL and the buyer identity information
- One to retrieve the Checkout Intent after it’s created so that we can pull and check the state of the Checkout Intent
lib/types.ts
Build the checkout interface
Now we’ll create a checkout modal to manage the purchase flow: first collecting buyer identity and shipping information, then creating a Checkout Intent with Rye to fetch live pricing details including shipping costs and taxes, and finally displaying the complete order summary for user confirmation.app/lib/types.ts
4. Collect card details and confirm checkout
Once the Checkout Intent is created and the offer is fetched, the Checkout Intent enters theawaiting_confirmation
state.
At this point, we can collect payment details using Stripe’s Card Element to tokenize the card information, then send that token to our server to confirm the Checkout Intent with Rye, which will place the order on the third-party merchant site.
Using Stripe payment method tokenization keeps raw credit card details off your servers (reducing PCI scope) while providing Rye with a secure, single-use token to process the payment.
Setup the confirm intent API endpoint
This server-side route receives the tokenized card details and confirms the Checkout Intent with Rye.app/api/checkout/confirm-intent/route.ts
Setup Stripe Card Element for payment collection
On the client side, we’ll use React Stripe.js to collect and tokenize payment details securely. Stripe has several web and mobile SDKs for securely tokenizing card details.Now we’ll set up the Stripe integration to securely collect payment details:
- loadStripe: Initializes the Stripe.js library with your publishable key, creating a Stripe instance that handles secure communication with Stripe’s servers
- Elements Provider: Wraps our checkout form to provide Stripe context, enabling secure tokenization of payment data without it touching your servers
- CardElement: Renders Stripe’s secure card input fields that automatically handle validation, formatting, and PCI compliance
- Form Submission: When the user submits payment, we use Stripe’s
createToken
method to securely tokenize the card details, then send that token (not the raw card data) to Rye for payment processing
The Universal Checkout API expects legacy Stripe tokens that start with
tok_
not the newer Stripe Payment Method IDs beginning with pm_
.app/components/CheckoutModal.tsx
5. Try it out
- Run the app:
npm run dev
- Ask:
“Find a stainless steel water bottle on Amazon under $30.”
- Click Buy on one result.
- Enter your test identity and card details (Stripe test numbers, e.g.,
4242 4242 4242 4242
). - Submit and you should see Order submitted! when the Rye confirmation returns 200.
View test orders in the Rye console.
Next steps
Store buyer identity (optional)
If your app authenticates users and stores account information, consider storing buyer identity so that you can prepopulate the buyer information during checkout.Handle edge cases
- Out-of-stock / price changed: show a “refresh price/stock” button that re-queries.
- Create a new Checkout Intent if the buyer identity changes to fetch a new offer with updated shipping and tax details.
Security
- Keep the
RYE_API_KEY
andOPENAI_API_KEY
server-side only. - Do not log card data; tokens are safe to log sparingly in staging only.
- Serve over HTTPS in production.
FAQ
- Do I need a Stripe account? Not when using the Rye confirmation flow, in this setup, Rye’s Stripe account is used when charging the end customer and paying out the third party merchant.
- Do I need a Stripe secret key? Not for basic tokenization via Card Element. You only need the Rye publishable key on the client.
Recap
You now have:- A streaming chat with tool-calling.
- A basic Amazon search tool that returns real product URLs.
- A buyer identity modal that creates a Checkout Intent.
- Stripe Card Element to tokenize
- Rye Universal Checkout API to confirm and place the order.