Overview
Try a primary search provider, fall back to a secondary on timeout or error, and log which provider served each request. Useful for agents that need reliable search without manual intervention when a provider goes down.
Trigger
Agent search request
Schedule
On-demand (per agent request)
Workflow Steps
Call primary provider
Send query to primary search API with a 5-second timeout.
Check response validity
Verify response contains results and status is 200.
Fallback on failure
If primary fails or times out, call secondary provider.
Log provider used
Record which provider served the request for cost tracking.
Python Implementation
import requests, os, time
H = {"x-api-key": os.environ["SCAVIO_API_KEY"]}
def search_with_fallback(query, platform="google"):
try:
r = requests.post("https://api.scavio.dev/api/v1/search",
headers=H, json={"platform": platform, "query": query}, timeout=5)
r.raise_for_status()
return {"provider": "scavio", "results": r.json()}
except Exception:
pass
# Fallback: Brave Search API
try:
r2 = requests.get("https://api.search.brave.com/res/v1/web/search",
headers={"X-Subscription-Token": os.environ["BRAVE_KEY"]},
params={"q": query}, timeout=5)
r2.raise_for_status()
return {"provider": "brave", "results": r2.json()}
except Exception:
return {"provider": "none", "results": []}
result = search_with_fallback("best CRM tools 2026")
print(f"Served by: {result['provider']}")JavaScript Implementation
const search = async (query) => {
try {
const r = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST", headers: {"x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json"},
body: JSON.stringify({platform: "google", query}), signal: AbortSignal.timeout(5000)
});
if (r.ok) return {provider: "scavio", results: await r.json()};
} catch {}
try {
const r2 = await fetch(`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(query)}`, {
headers: {"X-Subscription-Token": process.env.BRAVE_KEY}, signal: AbortSignal.timeout(5000)
});
if (r2.ok) return {provider: "brave", results: await r2.json()};
} catch {}
return {provider: "none", results: []};
};Platforms Used
Web search with knowledge graph, PAA, and AI overviews