DEV Community

BuyWhere
BuyWhere

Posted on

Give Your OpenAI Agent Live Singapore Prices in 5 Minutes

Give Your OpenAI Agent Live Singapore Prices in 5 Minutes

Most shopping agents either hallucinate prices or scrape pages that break every month.

BuyWhere fixes that: one API call returns real-time prices from Harvey Norman, Shopee, Lazada, and 20+ Singapore retailers. Here's how to wire it into an OpenAI Agents SDK agent in under 5 minutes.

Prerequisites

Install

pip install openai-agents requests
Enter fullscreen mode Exit fullscreen mode

The Agent

import os
import requests
from agents import Agent, Runner, function_tool

BUYWHERE_API_KEY = os.environ["BUYWHERE_API_KEY"]
BUYWHERE_BASE = "https://api.buywhere.ai"

@function_tool
def search_products(query: str, limit: int = 5) -> dict:
    resp = requests.get(
        f"{BUYWHERE_BASE}/v1/search",
        params={"q": query, "limit": limit},
        headers={"Authorization": f"Bearer {BUYWHERE_API_KEY}"},
        timeout=10
    )
    resp.raise_for_status()
    return resp.json()

@function_tool
def get_product_prices(product_id: str) -> dict:
    resp = requests.get(
        f"{BUYWHERE_BASE}/v1/products/{product_id}/prices",
        headers={"Authorization": f"Bearer {BUYWHERE_API_KEY}"},
        timeout=10
    )
    resp.raise_for_status()
    return resp.json()

shopping_agent = Agent(
    name="Singapore Shopping Agent",
    instructions=(
        "You are a shopping assistant for Singapore. "
        "When asked about a product, use search_products to find live prices. "
        "Always include the retailer name and exact price."
    ),
    tools=[search_products, get_product_prices]
)

import asyncio

async def main():
    result = await Runner.run(
        shopping_agent,
        "Where's the cheapest Samsung Galaxy S25 in Singapore right now?"
    )
    print(result.final_output)

asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

What You Get

When you run this, the agent will:

  1. Call search_products with "Samsung Galaxy S25"
  2. Get live prices from Shopee, Lazada, Harvey Norman, and others
  3. Return a grounded answer with actual current prices — no hallucinations

Sample output:

The Samsung Galaxy S25 (256GB) is currently cheapest on Shopee at S$1,099,
compared to S$1,199 at Harvey Norman and S$1,149 on Lazada.
Enter fullscreen mode Exit fullscreen mode

Why This Beats Scraping

  • No brittle selectors — retailers change their HTML constantly
  • Live data — prices update throughout the day
  • Structured output — product IDs, images, specs alongside price
  • Rate-limit safe — one API call, not 20 page loads

Using BuyWhere MCP Instead

If you're building with Claude or any MCP-compatible tool:

{
  "mcpServers": {
    "buywhere": {
      "command": "npx",
      "args": ["-y", "buywhere-mcp"],
      "env": {
        "BUYWHERE_API_KEY": "your_api_key_here"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The MCP server exposes search_products, get_product, get_price, and compare_prices as native MCP tools. A remote Streamable HTTP endpoint is also available at https://api.buywhere.ai/mcp — now listed on Smithery.

Next Steps

Questions? Drop a comment or email surf@buywhere.ai.

Top comments (0)