Overview
Before each search API call, the agent checks provider availability and pricing via MCP tools, then routes to the cheapest available provider. Reduces cost and avoids calls to degraded services.
Trigger
Before each agent search request
Schedule
On-demand (per request)
Workflow Steps
Check provider status
Query status MCP for each search provider availability.
Get current pricing
Fetch per-query costs from pricing MCP.
Filter available providers
Remove providers with degraded or down status.
Route to cheapest
Select the cheapest available provider and execute search.
Python Implementation
import requests, os
PROVIDERS = {
"scavio": {"url": "https://api.scavio.dev/api/v1/search", "header": "x-api-key", "key_env": "SCAVIO_API_KEY", "cost": 0.005},
"serper": {"url": "https://google.serper.dev/search", "header": "X-API-KEY", "key_env": "SERPER_KEY", "cost": 0.001},
}
def search_with_routing(query, platform="google"):
available = []
for name, cfg in PROVIDERS.items():
try:
key = os.environ.get(cfg["key_env"])
if not key:
continue
available.append((name, cfg))
except Exception:
continue
available.sort(key=lambda x: x[1]["cost"])
for name, cfg in available:
try:
r = requests.post(cfg["url"],
headers={cfg["header"]: os.environ[cfg["key_env"]], "Content-Type": "application/json"},
json={"platform": platform, "query": query} if name == "scavio" else {"q": query},
timeout=5)
if r.ok:
return {"provider": name, "cost": cfg["cost"], "data": r.json()}
except Exception:
continue
return NoneJavaScript Implementation
const providers = [
{name: "scavio", url: "https://api.scavio.dev/api/v1/search", cost: 0.005,
headers: {"x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json"},
body: (q) => JSON.stringify({platform: "google", query: q})},
];
for (const p of providers.sort((a, b) => a.cost - b.cost)) {
try {
const r = await fetch(p.url, {method: "POST", headers: p.headers, body: p.body(query)});
if (r.ok) return {provider: p.name, data: await r.json()};
} catch {}
}Platforms Used
Web search with knowledge graph, PAA, and AI overviews