How to Migrate from SerpAPI to AlterLab: Step-by-Step Guide (2026)
Tutorials

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.

4 min read
4 views

AlterLab handles this automaticallyscrape any URL with one API call. No infrastructure required.

Try it free

TL;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.

Bash
pip uninstall serpapi
pip install alterlab

For 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.

Python
# 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"))
Python
# 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 (Use min_tier to 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.

MetricSerpAPI (Typical)AlterLab
ModelMonthly SubscriptionPay-as-you-go
Minimum Monthly Cost~$50+$0
Unused CreditsExpire monthlyBalance never expires
ScalingTier-gatedAutomatic
$0.0002Per Request (AlterLab)
$0Monthly Minimum
NeverBalance Expiry

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 location or device parameters, 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_KEY is 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.

Share

Was this article helpful?

Frequently Asked Questions

The migration typically takes less than an hour. Most of the work involves replacing the client library and updating your API key in your environment variables.
Not directly, but the logic remains the same. Since AlterLab uses a standard REST API and a similar Python SDK structure, you only need to swap the client initialization and method calls.
AlterLab uses a pay-as-you-go model starting at $0.0002 per request with no monthly minimums or expiring balances, whereas SerpAPI relies on fixed monthly subscription tiers.