BuyWhere Agent Integration Examples
Working examples showing how to integrate the BuyWhere product catalog API with popular AI agent frameworks.
Prerequisites
# Set your BuyWhere API key
export BUYWHERE_API_KEY="bw_live_xxxxx"
Get an API key at buywhere.ai (or use your existing key).
Examples
LangChain (langchain_tool.py)
Wrap BuyWhere as LangChain tools with search, product lookup, and price comparison.
pip install -r langchain_requirements.txt
python langchain_tool.py "find me a good ergonomic chair under SGD 500"
Tools exposed:
search_products(query, limit)— Full-text search across the Singapore catalogget_product_details(product_id)— Get a specific product by IDcompare_price(product_name)— Find the cheapest listing across all retailers
CrewAI (crewai_agent.py)
A two-agent crew: one researcher that searches and compares prices, one advisor that synthesizes recommendations.
pip install -r crewai_requirements.txt
python crewai_agent.py "wireless headphones under SGD 300"
Tools exposed:
BuyWhere Product Search— Search the catalogBuyWhere Price Comparison— Find best price across platforms
AutoGen (autogen_agent.py)
AutoGen agent with BuyWhere function calling for conversational shopping assistance.
pip install -r autogen_requirements.txt
python autogen_agent.py "find me a good laptop under SGD 1500 in Singapore"
Tools exposed:
search_buywhere_products(query, limit)— Search the catalogget_buywhere_product(product_id)— Get product detailscompare_buywhere_prices(product_name)— Find best price
Using the Python SDK
All examples use the official buywhere Python SDK if available. It falls back to importing from ../buywhere-py in development:
try:
from buywhere import BuyWhereClient
except ImportError:
from buywhere_py.buywhere import BuyWhereClient
The SDK supports:
client.search(query, limit=20, offset=0, category=..., min_price=..., max_price=..., source=...)— Search productsclient.get_product(product_id)— Get a single product by ID
API Reference
All examples connect to https://api.buywhere.ai/v1 by default (configure via BUYWHERE_API_BASE_URL env var if needed).
Key endpoints used:
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/search | Full-text product search |
| GET | /v1/products/{id} | Get product by ID |
| GET | /v1/products/best-price | Cheapest listing across platforms |
Rate Limits
The BuyWhere API applies rate limits per API key. All examples respect standard limits. For production use, consider caching results and adding retry logic with exponential backoff.
Testing Without an API Key
To test locally without a live API key, you can mock the client:
from unittest.mock import MagicMock
client = MagicMock()
client.search.return_value = SearchResult(total=0, limit=20, offset=0, items=[])