The Problem
Pi and other coding agents hardcode a single search provider (often Tavily or SearxNG). When that provider has downtime, rate limits, or returns poor results for certain query types, the agent has no fallback and produces degraded output.
The Scavio Solution
Implement a provider abstraction layer that routes search queries to different providers based on availability and query type. Use Scavio as the primary or fallback provider. Tavily at $0.008/credit, Scavio at $0.005/credit. SearxNG is free but self-hosted and unreliable under load.
Before
Single search provider hardcoded. Provider outage means agent cannot search. No cost comparison between providers. Vendor lock-in.
After
Provider abstraction with health checks. Primary provider fails, fallback kicks in within 2 seconds. Query routing by type: Reddit queries to Scavio (native support), general to cheapest available.
Who It Is For
Coding agent developers, AI tool builders using Pi or similar agents, teams that need search reliability across providers.
Key Benefits
- Provider abstraction eliminates vendor lock-in
- Automatic failover maintains agent uptime
- Route by query type: Reddit-specific queries to Scavio
- Cost optimization: Scavio $0.005 vs Tavily $0.008 per credit
- Health check pings detect provider issues before queries fail
Python Example
import requests, os, time
PROVIDERS = {
'scavio': {'url': 'https://api.scavio.dev/api/v1/search',
'key_header': 'x-api-key', 'key': os.environ.get('SCAVIO_API_KEY')},
'tavily': {'url': 'https://api.tavily.com/search',
'key_header': 'Authorization', 'key': os.environ.get('TAVILY_API_KEY')},
}
def search(query: str, platform: str = 'google', preferred: str = 'scavio') -> dict:
provider = PROVIDERS[preferred]
try:
resp = requests.post(provider['url'],
headers={provider['key_header']: provider['key']},
json={'platform': platform, 'query': query}, timeout=10)
resp.raise_for_status()
return resp.json()
except Exception:
# Fallback to other provider
fallback = 'tavily' if preferred == 'scavio' else 'scavio'
fb = PROVIDERS[fallback]
return requests.post(fb['url'], headers={fb['key_header']: fb['key']},
json={'query': query}, timeout=10).json()JavaScript Example
async function search(query, platform = 'google', preferred = 'scavio') {
const providers = {
scavio: { url: 'https://api.scavio.dev/api/v1/search',
headers: { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' } },
tavily: { url: 'https://api.tavily.com/search',
headers: { Authorization: `Bearer ${process.env.TAVILY_API_KEY}`, 'Content-Type': 'application/json' } }
};
try {
const p = providers[preferred];
const resp = await fetch(p.url, { method: 'POST', headers: p.headers,
body: JSON.stringify({ platform, query }) });
if (!resp.ok) throw new Error(resp.status);
return resp.json();
} catch {
const fb = providers[preferred === 'scavio' ? 'tavily' : 'scavio'];
return fetch(fb.url, { method: 'POST', headers: fb.headers,
body: JSON.stringify({ query }) }).then(r => r.json());
}
}Platforms Used
Web search with knowledge graph, PAA, and AI overviews
Community, posts & threaded comments from any subreddit