AI News Hub Logo

AI News Hub

Build a Price Comparison Agent with BuyWhere API

DEV Community
BuyWhere

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. 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 Python 3.10+ A BuyWhere API key (free at buywhere.io/signup) An Anthropic API key (or any LLM provider) pip install anthropic httpx 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"] 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 availability — in_stock, limited, out_of_stock rating — merchant rating where available 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)) 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. 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. npm install @buywhere/mcp-server # or pip install buywhere-mcp { "mcpServers": { "buywhere": { "command": "npx", "args": ["@buywhere/mcp-server"], "env": { "BUYWHERE_API_KEY": "your-api-key" } } } } 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 MCP server exposes 7 tools: search_products, compare_prices, get_deals, find_deals, get_product, browse_categories, and get_category_products. 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. 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