Overview
This pipeline provides near-100% search availability for production AI agents by routing queries through multiple providers in priority order. Primary: Scavio ($0.005/query, 6 platforms, AI Overview). Secondary: Brave Search API (~$4-5/1K). Tertiary: cached results from previous successful queries. Each provider has timeout and minimum result thresholds. The agent sees a single search function regardless of which provider responds.
Trigger
On-demand (called by agent tool function)
Schedule
On-demand (triggered by agent tool calls)
Workflow Steps
Receive search request from agent
Agent calls the search tool with query and optional platform parameter.
Try primary provider (Scavio)
Send query to Scavio with 10-second timeout. Check result count meets minimum threshold (3+ results).
Try secondary provider (Brave) on failure
If Scavio fails or returns insufficient results, try Brave Search API with 8-second timeout.
Fall back to cache on double failure
If both providers fail, return cached results from the most recent successful query for the same or similar keyword.
Log provider and update cache
Record which provider served the request for cost tracking. Update cache with fresh results.
Python Implementation
import requests
import json
from pathlib import Path
SCAVIO_KEY = "your_scavio_api_key"
BRAVE_KEY = "your_brave_api_key"
CACHE_PATH = Path("search_cache.json")
def load_cache() -> dict:
return json.loads(CACHE_PATH.read_text()) if CACHE_PATH.exists() else {}
def save_cache(cache: dict):
CACHE_PATH.write_text(json.dumps(cache, indent=2))
def fallback_search(query: str, platform: str = "google") -> dict:
cache = load_cache()
# Primary: Scavio
try:
res = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": SCAVIO_KEY},
json={"platform": platform, "query": query, "ai_overview": True},
timeout=10,
)
if res.ok:
data = res.json()
if len(data.get("organic", [])) >= 3:
cache[query] = data
save_cache(cache)
return {"provider": "scavio", "data": data}
except Exception:
pass
# Secondary: Brave
try:
res = requests.get(
"https://api.search.brave.com/res/v1/web/search",
headers={"X-Subscription-Token": BRAVE_KEY},
params={"q": query},
timeout=8,
)
if res.ok:
data = res.json()
return {"provider": "brave", "data": data}
except Exception:
pass
# Tertiary: cache
if query in cache:
return {"provider": "cache", "data": cache[query]}
return {"provider": "none", "data": {}}
result = fallback_search("best search api for ai agents 2026")
print(f"Provider: {result['provider']}, Results: {len(result['data'].get('organic', []))}")JavaScript Implementation
const SCAVIO_KEY = "your_scavio_api_key";
const BRAVE_KEY = "your_brave_api_key";
const cache = new Map();
async function fallbackSearch(query, platform = "google") {
// Primary: Scavio
try {
const res = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST",
headers: { "x-api-key": SCAVIO_KEY, "content-type": "application/json" },
body: JSON.stringify({ platform, query, ai_overview: true }),
});
if (res.ok) {
const data = await res.json();
if ((data.organic ?? []).length >= 3) {
cache.set(query, data);
return { provider: "scavio", data };
}
}
} catch {}
// Secondary: Brave
try {
const res = await fetch(`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(query)}`, {
headers: { "X-Subscription-Token": BRAVE_KEY },
});
if (res.ok) return { provider: "brave", data: await res.json() };
} catch {}
// Tertiary: cache
if (cache.has(query)) return { provider: "cache", data: cache.get(query) };
return { provider: "none", data: {} };
}
const r = await fallbackSearch("best search api 2026");
console.log(`Provider: ${r.provider}`);Platforms Used
Web search with knowledge graph, PAA, and AI overviews