ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build a SERP API Failover Stack
Tutorial

How to Build a SERP API Failover Stack

Build automatic failover between multiple SERP APIs. Primary → fallback → emergency. Production-ready Python implementation.

Get Free API KeyAPI Docs

ScrapingRobot broke against anti-bot defenses. Sonar API credits got wiped. SerpAPI has an active lawsuit. No single API is infallible. This tutorial builds automatic failover across multiple vendors.

Prerequisites

  • API keys for 2-3 SERP APIs
  • Python 3.8+

Walkthrough

Step 1: Define the vendor stack

Primary, fallback, and emergency vendors.

Python
vendors = [
    {'name': 'scavio', 'url': 'https://api.scavio.dev/api/v1/search',
     'headers': {'x-api-key': os.environ['SCAVIO_API_KEY']},
     'payload_fn': lambda q: {'platform': 'google', 'query': q}},
    {'name': 'serper', 'url': 'https://google.serper.dev/search',
     'headers': {'X-API-KEY': os.environ['SERPER_API_KEY']},
     'payload_fn': lambda q: {'q': q}},
]

Step 2: Build the failover function

Try vendors in order, fail to next on error.

Python
import requests

def search_with_failover(query):
    for vendor in vendors:
        try:
            r = requests.post(vendor['url'], headers=vendor['headers'],
                json=vendor['payload_fn'](query), timeout=15)
            if r.status_code == 200:
                return {'vendor': vendor['name'], 'data': r.json()}
        except Exception:
            continue
    raise Exception('All vendors failed')

Step 3: Normalize responses

Each vendor returns different JSON shapes. Normalize.

Python
def normalize(vendor_name, data):
    if vendor_name == 'scavio':
        return [{'title': r['title'], 'url': r['link'], 'snippet': r['snippet']}
                for r in data.get('organic_results', [])]
    elif vendor_name == 'serper':
        return [{'title': r['title'], 'url': r['link'], 'snippet': r['snippet']}
                for r in data.get('organic', [])]
    return data

Step 4: Log vendor performance

Track which vendors succeed and fail over time.

Python
import json, datetime
def log_result(vendor, success, latency):
    with open('failover_log.jsonl', 'a') as f:
        f.write(json.dumps({'ts': datetime.datetime.now().isoformat(),
            'vendor': vendor, 'success': success, 'latency': latency}) + '\n')

Python Example

Python
# Production failover: Scavio (primary) → Serper (fallback)
# Normalize output shape across vendors
# Log performance for quarterly vendor review

JavaScript Example

JavaScript
// Same failover pattern in JS with try/catch per vendor.

Expected Output

JSON
Multi-vendor SERP failover stack: primary → fallback → emergency. Normalized output, performance logging, vendor-neutral application code.

Related Tutorials

  • How to Build a Vendor-Resilient Search Stack (2026)
  • How to Benchmark SERP API Uptime and Reliability

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

API keys for 2-3 SERP APIs. Python 3.8+. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Related Resources

Solution

Multi-Vendor SERP Failover

Read more
Workflow

Multi-Vendor Search Failover Workflow

Read more
Best Of

Best Multi-Platform Search APIs for Agencies in 2026

Read more
Best Of

Best SERP API by Pricing Model in 2026

Read more
Solution

Multi-Search Backend Failover

Read more
Workflow

Search API Vendor Evaluation Pipeline

Read more

Start Building

Build automatic failover between multiple SERP APIs. Primary → fallback → emergency. Production-ready Python implementation.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy