
How to Migrate from SerpAPI to AlterLab: Step-by-Step Guide (2026)
Learn how to migrate from SerpAPI to AlterLab in under an hour. A practical, developer-first guide to switching to pay-as-you-go scraping with no subscriptions.
AlterLab handles this automatically — scrape any URL with one API call. No infrastructure required.
Try it freeTL;DR
To migrate from SerpAPI to AlterLab, replace the serpapi Python library with the alterlab SDK, update your API key in your .env file, and swap the GoogleSearch class for the alterlab.Client class. The migration is a direct swap of the request logic and can be completed in minutes.
Why migrate?
Many developers migrate from SerpAPI because of the rigid monthly subscription tiers that gate search volume. If you exceed your limit, you are forced into a higher tier regardless of actual need. Additionally, SerpAPI focuses primarily on search engine results, whereas AlterLab allows for full destination-page extraction and structured data parsing via Cortex AI.
Both APIs are capable—this guide is for developers prioritizing pay-as-you-go pricing and no subscription requirements. For a deeper dive into the technical differences, see our detailed SerpAPI comparison.
Prerequisites
Before you begin, ensure you have the following:
- An AlterLab account (free sign-up)
- Your AlterLab API key
- Python 3.8 or higher installed
Step 1: Install the AlterLab SDK
First, remove the old library and install the AlterLab SDK. If you are using a REST API approach instead of the SDK, you can skip the installation and move straight to configuring your requests.
pip uninstall serpapi
pip install alterlabFor more details on setting up your environment, refer to our Getting started guide.
Step 2: Replace your API calls
The core of your migration involves swapping the SerpAPI GoogleSearch object for the alterlab.Client. While SerpAPI uses a dictionary-based input for parameters, AlterLab uses a more direct method call.
Below is a side-by-side comparison of a standard search request.
# SerpAPI (before migration)
from serpapi import GoogleSearch
params = {
"q": "best technical writing tools",
"api_key": "YOUR_SERPAPI_KEY"
}
search = GoogleSearch(params)
results = search.get_dict()
print(results.get("organic_results"))# AlterLab (after migration)
import alterlab
# Initialize client with your API key
client = alterlab.Client("YOUR_ALTERLAB_API_KEY")
# Perform the scrape
# AlterLab handles the search engine logic via the URL or specific search parameters
response = client.scrape("https://www.google.com/search?q=best+technical+writing+tools")
# Access structured data
print(response.json()) Step 3: Handle response format differences
SerpAPI returns a deeply nested dictionary specifically structured for search engine components (e.g., organic_results, knowledge_graph).
AlterLab is more flexible. When you scrape a search URL, you receive the raw data, but you can also use Cortex AI to transform that data into a specific schema immediately. If you want to maintain a similar structure to your old code, you can pass a schema to the extract parameter.
If you are moving from simple search to full-page extraction, note that AlterLab returns response.text for raw content or response.json() for structured output.
Step 4: Update your error handling
SerpAPI typically raises specific exceptions for rate limits or invalid keys. AlterLab follows standard HTTP status codes:
401: Unauthorized (Check your API key)402: Insufficient balance (You need to add funds to your account)429: Rate limit exceeded (Usemin_tierto scale up)
Ensure your retry logic accounts for 402 errors by checking your AlterLab balance rather than just retrying the request.
Cost comparison
The primary driver for this migration is often the cost model. SerpAPI requires a monthly commitment to access higher volumes. AlterLab operates on a pure pay-as-you-go basis.
| Metric | SerpAPI (Typical) | AlterLab |
|---|---|---|
| Model | Monthly Subscription | Pay-as-you-go |
| Minimum Monthly Cost | ~$50+ | $0 |
| Unused Credits | Expire monthly | Balance never expires |
| Scaling | Tier-gated | Automatic |
For a full breakdown of request costs based on complexity (T1 to T5 tiers), visit our AlterLab pricing page.
Common issues and fixes
- Missing search parameters: If you were relying on SerpAPI's specific
locationordeviceparameters, you can achieve the same in AlterLab by passing those as part of the query string or using a specific proxy configuration. - JSON structure changes: If your downstream logic depends on specific SerpAPI keys like
organic_results, use AlterLab's Cortex AI to map the response to your existing schema. - Authentication errors: Ensure your
ALTERLAB_API_KEYis correctly loaded from your environment variables and not hardcoded with old SerpAPI credentials.
You're done
You have successfully migrated your search scraping logic to AlterLab. You now have access to higher-tier scraping (T1-T5), automatic anti-bot bypassing, and a cost model that scales with your actual usage.
If you run into any issues during the transition, check our API Documentation or hit reply to this post.
Was this article helpful?
Frequently Asked Questions
Related Articles

How to Scrape TechCrunch Data: Complete Guide for 2026
<meta description 150-160 chars include 'scrape techcrunch'>.
Herald Blog Service

Building RAG Pipelines: Extract Clean Markdown and JSON
Learn how to build reliable RAG pipelines by extracting clean Markdown and structured JSON from complex web pages using AlterLab's scraping API with anti-bot handling and smart rendering.
Herald Blog Service

Viator Data API: Extract Structured JSON in 2026
Learn how to build a robust travel data pipeline using a viator data api. Extract structured JSON for prices, ratings, and locations without fragile HTML parsing.
Herald Blog Service
Popular Posts
Recommended

How to Scrape AliExpress: Complete Guide for 2026

Why Your Headless Browser Gets Detected (and How to Fix It)

AlterLab vs Firecrawl: In-Depth Review with Benchmarks & Code Examples

How to Scrape Twitter/X Data: Complete Guide for 2026

How to Scrape Cloudflare-Protected Sites in 2026
Newsletter
Scraping insights and API tips. No spam.
Recommended Reading

How to Scrape AliExpress: Complete Guide for 2026

Why Your Headless Browser Gets Detected (and How to Fix It)

AlterLab vs Firecrawl: In-Depth Review with Benchmarks & Code Examples

How to Scrape Twitter/X Data: Complete Guide for 2026

How to Scrape Cloudflare-Protected Sites in 2026
Stay in the Loop
Get scraping insights, API tips, and platform updates. No spam — we only send when we have something worth reading.
Explore AlterLab
Web Scraping API Resources
Part of the Web Scraping API Documentation cluster
Complete API reference with 5-tier auto-escalation — Curl to challenge resolution.
Pillar pageConfigure Tier 4 browser rendering for SPAs and dynamic content.
Scrape pages behind login using session management.
Real success rates and cost data across all 5 tiers.
MCP Server, Python SDK, and Firecrawl-compatible API for AI agent workflows.