DEV Community

BuyWhere
BuyWhere

Posted on

How I Built an AI Shopping Agent That Compares Prices Across Singapore, China, and the US

In this walkthrough, I will show you how to build an AI shopping agent that searches products across Singapore, China, and the US markets — returning real-time prices, merchant links, and cross-border comparisons in under 10 minutes.

The Problem

AI agents today can chat, browse, and reason — but they cannot reliably search for real products across multiple markets. Web scraping is fragile, Amazon APIs only cover Amazon, and Google Shopping is not agent-friendly.

BuyWhere solves this: an agent-native product catalog API with one normalized schema across multiple markets.

Setup

pip install httpx
Enter fullscreen mode Exit fullscreen mode

Get a free API key from https://buywhere.ai/api-keys

import httpx

API_KEY = "bw_live_your_key"
client = httpx.Client(headers={"X-Buywhere-Key": API_KEY})
Enter fullscreen mode Exit fullscreen mode

Step 1: Search Products

def search_products(query, market="SG", max_price=None):
    params = {"q": query, "market": market}
    if max_price:
        params["max_price"] = max_price
    r = client.get("https://api.buywhere.ai/v1/search", params=params)
    return r.json()["data"]
Enter fullscreen mode Exit fullscreen mode

Step 2: Cross-Border Compare

def compare_across_markets(query, markets=["SG", "CN", "US"]):
    results = {}
    for m in markets:
        products = search_products(query, m)[:3]
        for p in products:
            key = f"{p[name]} ({m})"
            results[key] = {
                "price": f"{p[currency]} {p[price]}",
                "merchant": p["merchant"],
                "url": p.get("affiliate_link", "")
            }
    return results
Enter fullscreen mode Exit fullscreen mode

Step 3: Full Agent

from openai import OpenAI
import json

llm = OpenAI()

def search_tool(query, market, max_price=None):
    return json.dumps(search_products(query, market, max_price), indent=2)

response = llm.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Find iPhone 16 in Singapore under 1500 SGD"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "search_products",
            "description": "Search real products across markets",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string"},
                    "market": {"type": "string", "enum": ["SG", "CN", "US"]},
                    "max_price": {"type": "number"}
                }
            }
        }
    }]
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

Why This Works

  • No scraping — structured JSON, not fragile HTML
  • Multi-market — one API covers SG, CN, US
  • Agent-native — designed for function calling and MCP
  • Free to start — API key at https://buywhere.ai/api-keys

Full source: https://github.com/buywhere/buywhere-mcp


Built with BuyWhere — the product layer AI shopping agents call first.

Top comments (0)