All Blogs

Creating an AI Shopping Assistant with Subtotal

Adding real-world consumer purchases to an AI shopping application
Cole Wilkes
Cole Wilkes
Cofounder and CEO
Cover Image for Creating an AI Shopping Assistant with Subtotal

Introduction

Last week, we announced the Subtotal AI Toolkit—a collection of open-source packages for building seamless integrations between your favorite AI agent frameworks and the Subtotal API.

Today, we're showing developers how to build an AI-powered shopping assistant that uses itemized consumer purchase data to deliver personalized experiences for users.

Intelligent shopping experiences

The next generation of shopping will be driven by AI, and Subtotal is empowering developers to build innovative solutions in this space.

By leveraging itemized purchase data, AI-powered experiences can create value for both shoppers and retailers. Here are just a few possibilities:

  • Personalized product recommendations – AI can analyze past purchases at the SKU level to suggest complementary products or frequently repurchased items.
  • Smart budgeting and expense tracking – Automated tracking of individual purchases helps users understand their spending habits and discover ways to save.
  • Automated shopping lists – AI can anticipate when essentials need restocking and generate shopping lists accordingly.
  • Deal and discount alerts – Shopping assistants can notify users when frequently purchased products go on sale at their preferred retailers.

By combining LLMs with a rich history of itemized consumer purchases, shopping becomes smarter, more efficient, and tailored to individual needs. 🚀

How does it work?

Subtotal is a platform that makes it easy for developers to integrate full-basket purchase data into their applications.

Consumers use Merchant Link to connect merchant accounts from retailers like Walmart, Target and Sephora to apps and services they trust.

Developers then use the Subtotal API to access itemized consumer purchases for any connected account.

Building the shopping assistant

We published a step-by-step tutorial that shows developers how to use the Subtotal AI Toolkit to build a ChatGPT-like application that draws insights from a purchase history to provide personalized product recommendations.

import {SubtotalAIToolkit, Tools} from '@subtotal-inc/ai-toolkit/ai-sdk';
import {openai} from '@ai-sdk/openai';
import {streamText} from 'ai';

const subtotalAIToolkit = new SubtotalAIToolkit({
  secretKey: process.env.SUBTOTAL_API_KEY!,
  configuration: {
    tools: [
      Tools.createConnection,
      Tools.createMerchantLinkUrl,
      Tools.getPurchases,
      Tools.getPurchaseDetails,
      Tools.getMerchants,
    ]
  },
});

const model = openai('gpt-4o');

const prompt = {
  role: 'system',
  content: 'Greet the user by responding to their message. ' +
  'Then create a new connection and generate a url for the user to link their Target account.' +
  'Indicate that user should click the url and link their account to get started. ' +
  'Wait for a response from the user indicating they have linked their account. '
}

export const maxDuration = 30;

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = await streamText({
    model: model,
    tools: {...subtotalAIToolkit.getTools()},
    maxSteps: 4,
    messages: [
      prompt,
      ...messages,
    ],
  });

  return result.toDataStreamResponse();

The full source code for the shopping assistant is available on our GitHub. Developers are encouraged to clone the repository and use the code as a starting point for their own applications.

Get started today

Sign up for our dashboard and generate an API key to get started today. For additional guides and examples, check out our documentation.

👉 Create your API key: Subtotal Dashboard

👉 Check out the repository and start building: AI Shopping Assistant

We can’t wait to see what you create!


Join the Subtotal community by following us on X and LinkedIn.

Copy Link

Get started today

Sign up now to get started or contact our sales team for personalized support.