Workflow

Multi-Provider Search Rotation Workflow

Workflow that rotates search queries across multiple providers based on cost, availability, and quality. Automatic failover with budget tracking.

Overview

Running all searches through one provider is a single point of failure and often overpays for simple queries. This workflow rotates queries across Scavio ($0.005/credit), Brave ($5/1K), and free tiers based on query type, budget remaining, and provider health. Automatic failover when a provider is down.

Trigger

Every search request from the agent or application.

Schedule

On-demand

Workflow Steps

1

Classify Query Complexity

Analyze the incoming query to determine if it is simple (fact lookup), medium (comparison), or complex (multi-step research).

2

Check Provider Health

Ping each provider's status. Skip providers that are down or rate-limited.

3

Route by Cost and Complexity

Simple queries go to cheapest available provider. Complex queries go to providers with best structured data support.

4

Execute Search with Failover

Call the selected provider. If it fails or returns poor results, automatically try the next provider in the rotation.

5

Log and Track Budget

Record which provider was used, cost, result quality, and update the running monthly budget.

Python Implementation

Python
import requests, os, json, time
from pathlib import Path

API_KEY = os.environ["SCAVIO_API_KEY"]
H = {"x-api-key": API_KEY, "Content-Type": "application/json"}
BUDGET_FILE = Path("rotation_budget.json")

def load_budget() -> dict:
    if BUDGET_FILE.exists():
        return json.loads(BUDGET_FILE.read_text())
    return {"scavio": 0, "total_cost": 0.0}

def save_budget(b: dict):
    BUDGET_FILE.write_text(json.dumps(b))

def scavio_search(query: str) -> dict:
    start = time.time()
    resp = requests.post(
        "https://api.scavio.dev/api/v1/search",
        headers=H,
        json={"query": query, "country_code": "us"},
        timeout=10,
    )
    latency = time.time() - start
    if resp.status_code == 200:
        data = resp.json()
        return {"provider": "scavio", "cost": 0.005, "latency": round(latency, 2), "results": data.get("organic_results", []), "success": True}
    return {"provider": "scavio", "success": False}

def rotate_search(query: str) -> dict:
    budget = load_budget()
    # Try Scavio first (cheapest at $0.005)
    result = scavio_search(query)
    if result["success"] and len(result.get("results", [])) >= 3:
        budget["scavio"] += 1
        budget["total_cost"] += result["cost"]
        save_budget(budget)
        return result
    # Fallback: retry with simplified query
    simplified = " ".join(query.split()[:4])
    result = scavio_search(simplified)
    if result["success"]:
        budget["scavio"] += 1
        budget["total_cost"] += result["cost"]
        save_budget(budget)
        return result
    return {"provider": "none", "success": False, "results": []}

result = rotate_search("best cloud hosting provider comparison 2026")
print(f"Provider: {result['provider']}, Results: {len(result.get('results', []))}, Cost: ${result.get('cost', 0)}")

JavaScript Implementation

JavaScript
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
const fs = await import('fs');

function loadBudget() { try { return JSON.parse(fs.readFileSync('rotation_budget.json','utf8')); } catch { return {scavio:0, totalCost:0}; } }
function saveBudget(b) { fs.writeFileSync('rotation_budget.json', JSON.stringify(b)); }

async function scavioSearch(query) {
  const start = Date.now();
  const r = await fetch('https://api.scavio.dev/api/v1/search', {method:'POST', headers:H, body:JSON.stringify({query, country_code:'us'})});
  if (r.ok) { const d = await r.json(); return {provider:'scavio', cost:0.005, latency:Date.now()-start, results:d.organic_results||[], success:true}; }
  return {provider:'scavio', success:false};
}

async function rotateSearch(query) {
  const budget = loadBudget();
  let result = await scavioSearch(query);
  if (result.success && result.results.length >= 3) { budget.scavio++; budget.totalCost += result.cost; saveBudget(budget); return result; }
  result = await scavioSearch(query.split(' ').slice(0,4).join(' '));
  if (result.success) { budget.scavio++; budget.totalCost += result.cost; saveBudget(budget); return result; }
  return {provider:'none', success:false, results:[]};
}

const r = await rotateSearch('best cloud hosting provider comparison 2026');
console.log('Provider: '+r.provider+', Results: '+r.results.length+', Cost: $'+r.cost);

Platforms Used

Google

Web search with knowledge graph, PAA, and AI overviews

YouTube

Video search with transcripts and metadata

Reddit

Community, posts & threaded comments from any subreddit

Frequently Asked Questions

Running all searches through one provider is a single point of failure and often overpays for simple queries. This workflow rotates queries across Scavio ($0.005/credit), Brave ($5/1K), and free tiers based on query type, budget remaining, and provider health. Automatic failover when a provider is down.

This workflow uses a every search request from the agent or application.. On-demand.

This workflow uses the following Scavio platforms: google, youtube, reddit. Each platform is called via the same unified API endpoint.

Yes. Scavio's free tier includes 250 credits per month with no credit card required. That is enough to test and validate this workflow before scaling it.

Multi-Provider Search Rotation Workflow

Workflow that rotates search queries across multiple providers based on cost, availability, and quality. Automatic failover with budget tracking.