← Back to blog
developersai-agentstutorialsecommerceapi

Build a Price Comparison Agent with BuyWhere API

Build a minimal AI shopping agent that searches Singapore merchants, compares prices, and explains the spread using the BuyWhere API.

BuyWhere TeamApril 15, 2026

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 Singapore merchants is a full-time engineering job.

BuyWhere solves this. We maintain a real-time product catalog covering major Singapore e-commerce platforms including Lazada, Shopee, Qoo10, and direct-retail sources, all accessible through a single REST API. In this post, we walk through building a minimal price comparison agent using the BuyWhere API and a Python-based LLM agent loop.

What you will build

A command-line agent that:

  • Accepts a product query in natural language, for example Sony WH-1000XM5 headphones
  • Searches BuyWhere for matching listings across indexed merchants
  • Returns the top 5 results sorted by price with source links
  • Explains the price spread in plain English

Prerequisites

Step 1: Install dependencies

pip install anthropic httpx

Step 2: Search the BuyWhere catalog

BuyWhere exposes a /v1/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.ai/v1"

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

Each result includes:

  • title: product name as listed by the merchant
  • price: current price in SGD
  • merchant: for example lazada, shopee, qoo10
  • url: direct product page link
  • updated_at: when the listing was last refreshed
  • availability: in_stock, limited, out_of_stock

Step 3: Build the agent loop

import anthropic
import json

client = anthropic.Anthropic()

def compare_prices(user_query: str) -> str:
    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]

    context = json.dumps(sorted_listings, indent=2)

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

{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))

Example output

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

The Sony WH-1000XM5 is available at SGD 329-399 across Lazada, Shopee,
and Qoo10. The cheapest option is currently on Lazada at SGD 329 (free
shipping). Shopee has the same unit at SGD 349 with a voucher available
that could bring it to SGD 319. Qoo10 lists at SGD 399; skip unless
you need the extended warranty bundle.

What just happened

In under 50 lines of Python, you built a working price comparison agent grounded in real Singapore merchant data. No scraping, no rate limiting, and no maintenance. BuyWhere handles catalog freshness so your agent can focus on the reasoning layer.

Next steps

  • Add tool use to give Claude structured access to the search API
  • Stream responses for a better CLI experience
  • Wrap the agent in Telegram or Slack for real-time shopping queries

Get started at buywhere.ai/api-keys-keys and review the integration guidance at buywhere.ai/integrate before publishing a production workflow.

BuyWhere is the product catalog API built for AI agents. We index Singapore merchant listings so you do not have to.