## TL;DR
To migrate from Scrapfly to AlterLab, install the `alterlab` Python SDK, replace the `ScrapflyClient` with `alterlab.Client`, and update your API key in your environment variables. Because both services use similar REST API structures, your existing scraping logic and URL targets require zero modification.

## Why migrate?
Many developers find Scrapfly's credit-based subscription plans restrictive, particularly as credits are consumed at different rates depending on the tier used. This often leads to overpaying for unused credits or running out of balance mid-project.

AlterLab solves this by removing the subscription requirement entirely. You pay only for what you use, your balance never expires, and there are no monthly minimums. Both APIs are capable, but this guide is for developers prioritizing pay-as-you-go pricing and no subscription requirements. For a deeper dive, see our [detailed Scrapfly comparison](/vs/scrapfly).

## Prerequisites
Before starting, ensure you have the following:
*   An AlterLab account (create one for [free at alterlab.io/signup](/signup))
*   Your AlterLab API key from the dashboard
*   5 minutes of development time

## Step 1: Install the AlterLab SDK
If you are using Python, you can use our lightweight SDK. If you prefer raw HTTP requests, you can use the REST API directly via `curl` or `requests`.

```bash title="Terminal — Install AlterLab"
pip install alterlab
```

For a more comprehensive setup, refer to our [Getting started guide](/docs/quickstart/installation).

<div data-infographic="steps">
  <div data-step data-number="1" data-title="Install SDK" data-description="pip install alterlab"></div>
  <div data-step data-number="2" data-title="Replace API calls" data-description="Swap Scrapfly client for alterlab.Client"></div>
  <div data-step data-number="3" data-title="Update API key" data-description="Replace Scrapfly key with AlterLab key in .env"></div>
  <div data-step data-number="4" data-title="Test and deploy" data-description="Run your existing tests — same response format"></div>
</div>

## Step 2: Replace your API calls
The transition is a straightforward swap of the client initialization and the scrape method. AlterLab simplifies the request process by removing the need for a separate configuration object for basic scrapes.

### Python SDK Migration
Compare the two implementations below. Note how the `ScrapeConfig` is replaced by direct parameters in the `scrape` method.

```python title="before_scrapfly.py"
from scrapfly import ScrapflyClient, ScrapeConfig

client = ScrapflyClient("SF_API_KEY")
config = ScrapeConfig(
    url="https://example.com",
    asp=True,
    render_js=True
)
response = client.scrape(config)
print(response.content)
```

```python title="after_alterlab.py" {4-6}
import alterlab

client = alterlab.Client("ALTERLAB_API_KEY")
# Use min_tier=3 for JavaScript rendering (equivalent to render_js=True)
response = client.scrape("https://example.com", min_tier=3)
print(response.text)
```

### REST API Migration
If you are using `curl` or a generic HTTP client, you only need to change the endpoint and the parameter names.

**Scrapfly Endpoint:**
`https://api.scrapfly.io/scrape?key=KEY&url=URL&asp=true`

**AlterLab Endpoint:**
`https://api.alterlab.io/scrape?api_key=KEY&url=URL`

## Step 3: Handle response format differences
Both services return the page content, but the object attributes differ slightly.

*   **Scrapfly**: Uses `.content` for the HTML body.
*   **AlterLab**: Uses `.text` for the HTML body.

If you are using AlterLab's **Formats** feature, you can request `json`, `markdown`, or `text` directly in the API call, which eliminates the need for manual cleaning in your post-processing pipeline.

## Step 4: Update your error handling
AlterLab uses standard HTTP status codes. If you have a retry loop based on Scrapfly's specific error codes, update them to handle standard 4xx and 5xx responses.

Common status codes to monitor:
*   `401`: Invalid API key.
*   `402`: Insufficient balance.
*   `429`: Rate limit reached.

## Cost comparison
The primary driver for this migration is the billing model. Scrapfly requires a monthly commitment to maintain certain tiers. AlterLab removes the monthly overhead.

Example: 10,000 standard requests.

<div data-infographic="stats">
  <div data-stat data-value="$0.0002" data-label="Per Request (AlterLab)"></div>
  <div data-stat data-value="$0" data-label="Monthly Minimum"></div>
  <div data-stat data-value="Never" data-label="Balance Expiry"></div>
</div>

For a full breakdown of costs per tier, visit [AlterLab pricing](/pricing).

## Common issues and fixes
*   **JS Rendering not working**: If a page requires JavaScript, ensure you set `min_tier=3`. This tells the engine to skip basic curl and go straight to a headless browser.
*   **Timeout errors**: If you are scraping heavy pages, increase your client timeout. AlterLab's automatic escalation can take a few extra seconds to find the optimal proxy.
*   **Response encoding**: AlterLab returns UTF-8 by default. If you see encoding issues, ensure your environment is set to handle UTF-8 strings.

## You're done
Your migration is complete. You can now run your scrapers without worrying about monthly credit expiration or tiered consumption rates.

For more advanced features like **Cortex AI** for structured data extraction or **Webhooks** for push notifications, check our documentation.

Hit reply if you have questions.

AlterLab // Web Data, Simplified.