DEV Community

BuyWhere
BuyWhere

Posted on • Originally published at buywhere.io

Build a Price Comparison Agent with BuyWhere API

Build a Price Comparison Agent with BuyWhere API

Target audience: AI agent developers | UTM: utm_source=blog&utm_medium=content&utm_campaign=dev-post-1


Price comparison is one of the most requested capabilities in AI shopping assistants — and one of the hardest to build reliably. Web scraping breaks, retailer APIs are gated or nonexistent, and maintaining freshness across dozens of merchants is a full-time engineering job.

BuyWhere solves this. We maintain a real-time product catalog covering 50+ Singapore merchants — Shopee, Lazada, Amazon SG, Courts, Challenger, Harvey Norman, and more — with over 1,000,000 active listings. Accessible through a single REST API or natively via MCP (Model Context Protocol). In this post, I will walk you through building a minimal price comparison agent in two ways: REST API with Python, and MCP with Claude.

What you will build

A price comparison agent that:

  • Accepts a product query in natural language (e.g. "Sony WH-1000XM5 headphones")
  • Searches BuyWhere for matching listings across all 50+ indexed merchants
  • Returns the top 5 results sorted by price with source links
  • Explains the price spread in plain English

Option A: REST API with Python

Prerequisites

  • Python 3.10+
  • A BuyWhere API key (free at buywhere.io/signup)
  • An Anthropic API key (or any LLM provider)

Step 1: Install dependencies

pip install anthropic httpx
Enter fullscreen mode Exit fullscreen mode

Step 2: Search the BuyWhere catalog

BuyWhere exposes a /products/search endpoint that accepts a natural language query and returns structured product listings:

import httpx

BUYWHERE_API_KEY = "your-api-key"
BASE_URL = "https://api.buywhere.io/v1"

def search_products(query: str, limit: int = 10) -> list[dict]:
    resp = httpx.get(
        f"{BASE_URL}/products/search",
        params={"q": query, "limit": limit, "currency": "SGD"},
        headers={"Authorization": f"Bearer {BUYWHERE_API_KEY}"},
    )
    resp.raise_for_status()
    return resp.json()["results"]
Enter fullscreen mode Exit fullscreen mode

Each result includes:

  • title — product name as listed by the merchant
  • price — current price in SGD (or your chosen currency)
  • merchant — e.g. shopee, lazada, amazon_sg, courts, challenger
  • url — direct product page link
  • updated_at — when this listing was last refreshed
  • availabilityin_stock, limited, out_of_stock
  • rating — merchant rating where available

Step 3: Build the agent loop

import anthropic
import json

client = anthropic.Anthropic()

def compare_prices(user_query: str) -> str:
    # 1. Fetch listings from BuyWhere
    listings = search_products(user_query, limit=10)
    in_stock = [l for l in listings if l["availability"] == "in_stock"]
    sorted_listings = sorted(in_stock, key=lambda x: x["price"])[:5]

    # 2. Format for the LLM
    context = json.dumps(sorted_listings, indent=2)

    # 3. Ask the LLM to summarise
    message = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=512,
        messages=[
            {
                "role": "user",
                "content": f"""You are a shopping assistant for Singapore. Here are the top in-stock results for "{user_query}":

{context}

Summarise the price range, highlight the cheapest option, and note any meaningful price spread. Keep it under 100 words.""",
            }
        ],
    )
    return message.content[0].text

if __name__ == "__main__":
    query = input("What are you looking for? ")
    print(compare_prices(query))
Enter fullscreen mode Exit fullscreen mode

Example output

What are you looking for? Sony WH-1000XM5 headphones

The Sony WH-1000XM5 is available from SGD 329–399 across 6 merchants.
The cheapest is currently on Lazada at SGD 329 (free shipping). Shopee
has the same unit at SGD 349 with a voucher that could bring it to
SGD 319. Courts lists at SGD 369, Harvey Norman at SGD 379. Challenger
has a bundle at SGD 399 including a carrying case. Skip the higher-
priced listings unless you need the extras.
Enter fullscreen mode Exit fullscreen mode

Option B: MCP with Claude (zero code)

If you use Claude Desktop or any MCP-compatible client, you can skip the code entirely. BuyWhere ships a production-ready MCP server with 7 tools.

Step 1: Install the MCP server

npm install @buywhere/mcp-server
# or
pip install buywhere-mcp
Enter fullscreen mode Exit fullscreen mode

Step 2: Add to Claude Desktop config

{
  "mcpServers": {
    "buywhere": {
      "command": "npx",
      "args": ["@buywhere/mcp-server"],
      "env": {
        "BUYWHERE_API_KEY": "your-api-key"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Ask Claude

Once connected, Claude can use BuyWhere tools directly:

You: Find me the cheapest Sony WH-1000XM5 in Singapore

Claude: [calls search_products then compare_prices]
The cheapest Sony WH-1000XM5 is SGD 329 on Lazada. Here is the full comparison across 6 merchants...

The MCP server exposes 7 tools: search_products, compare_prices, get_deals, find_deals, get_product, browse_categories, and get_category_products.

What just happened

In under 50 lines of Python (or zero lines with MCP), you built a working price comparison agent grounded in real Singapore merchant data from 50+ stores. No scraping, no rate limiting, no maintenance. BuyWhere handles catalog freshness — your agent focuses on the reasoning layer.

Next steps

  • Add Claude tool use for structured API access in your agent
  • Build a Telegram or Slack bot for real-time shopping queries
  • Try the MCP server with other compatible clients (ChatGPT, etc.)

Get your free API key at buywhere.io/signup. The free tier includes 100 requests/minute — enough to ship your first agent.


BuyWhere is the definitive product catalog API for AI agents. 1M+ products, 50+ Singapore merchants, real-time pricing. buywhere.io

Top comments (0)