Black Friday: up to 50% off your first month on monthly plans, upgrades included. Ends Monday Nov 30, midnight PT. See the prices
Playground Sign in Start free
← All posts

Proxy Rotation API: How It Works and How to Add It to Your Scraping Stack

Your scraper pulled a few hundred pages cleanly from your laptop. Then the 429s start, then the 403s, then a page asking whether you are a robot. Your code did not change. What changed is that the site noticed one IP address asking for far more than any person would. A proxy rotation API fixes this by sending each request out through a different IP from a managed pool, or deliberately through the same IP when a workflow needs continuity. No single address carries enough traffic to stand out.

That makes "should I rotate?" the wrong question for proxy rotation for web scraping. Each request needs one of three modes: a fresh IP, the same IP as the previous step, or an IP in a particular country. Most of the engineering is choosing the right mode for each step. What follows is the request flow behind a rotation layer, Python code that shows how to rotate proxies when scraping in each of those modes, a small health tracker for juggling several providers, and the cases where running your own pool beats an API.

What proxy rotation is and why one IP gets you banned

Sites see your traffic one IP at a time. Rate limiters count requests per address. Bot scoring systems also look at the timing between requests and at the kind of network the address belongs to, because a datacenter range tells them something different from a home broadband line. One IP fetching thousands of product pages at a steady pace looks nothing like a shopper, so sooner or later it gets throttled, challenged or blocked.

Rotation spreads the same workload across many addresses so each one stays unremarkable. The site still gets thousands of requests. They just stop adding up to one suspicious visitor. (If you want the vocabulary first, gateways, pools, sticky sessions, our proxy reference page defines it.)

Rotation does not fix headers, TLS or browser fingerprints, scripted navigation patterns or CAPTCHAs. A clean IP sending an obviously automated request can still be caught. The wider picture of proxies and detection is in our guide to web scraping proxies. This post stays on routing.

The idea that shapes all the code below is that requests come in two kinds.

Some requests are independent. A product page, a category listing or a search result can be fetched by anyone at any time, and the site has no reason to expect another request from the same address afterwards. Per-request rotation fits these.

Other requests belong to a flow: a login and then a dashboard, a cart and then checkout, page three of results that only makes sense after pages one and two in the same session. Many sites tie that state to the IP that started it. Change the address halfway through and the site may re-check you, drop the session or log you out. Flows need a sticky IP.

So before writing any code, label each request in your scrape as "independent" or "part of a flow". That label picks the rotation mode.

How a proxy rotation API works under the hood

From your code's side, a rotating proxy API is a single HTTPS call. You send the target URL, the service fetches it through some exit IP and returns the result. You never hold a proxy list, never test whether an address is alive and never decide which one goes next.

Behind that call, a typical rotation layer is a gateway in front of one or more IP pools. For each incoming request it picks an exit from the pool, usually with some memory of which addresses were used recently against which site, so it does not hammer a target from the same IP twice in a row. Health checks quietly drop exits that time out or get blocked. Many layers also inspect the response and retry on a different exit when they see a block, so what reaches you is either the page or a clear failure.

Sticky sessions are the same gateway with one extra lookup. When a request carries a session key, the layer maps that key to an exit and keeps sending matching requests through it. A new key gets a new mapping; no key falls back to ordinary rotation. Geo-targeting is a filter on the pool: only exits in the requested country are eligible.

The pools themselves differ by where the IPs come from. Datacenter IPs are fast and cheap but easy to recognise as non-residential. Residential IPs belong to consumer connections and are harder to score as bots, at a higher price. ISP (static residential) IPs sit in between. Which one a target needs depends on how hard it scores IP type, and residential vs datacenter proxies goes through that trade-off in detail.

On Ujeebu's Scrape API the default is proxy_type=rotating, the standard rotating pool. It is the default and the cheapest option, at 1 credit per plain page. Billing follows outcomes: failed, blocked and timed-out requests are not charged, and a bot-check interstitial returned in place of your page counts as a failure. An HTTP 404 is billed, because it is the site's real answer. The credit table shows what each step up costs:

Request type Credits
Plain page 1
Page with JavaScript rendering 5
Premium proxy 8
Premium proxy with JavaScript rendering 25
Country-targeted (residential) page, no JavaScript 20
Country-targeted (residential) page, with JavaScript 30

A premium page with rendering costs 25 times a plain fetch, so escalating every target "just in case" adds up fast. Start each target on the cheapest setting that returns real content and move up only when that target's responses show blocks.

Try it yourself

Run this on your own pages

Get a free API key and make your first call in minutes. 5,000 free credits for 21 days, no card.

How to rotate proxies in Python with a scraping API

The three modes map directly onto the labels from the first section.

Mode 1: a fresh IP for every independent page

Rotation is the default, so a request without a session value already leaves through the rotating pool. In curl:

curl -X GET 'https://api.ujeebu.com/scrape?url=https://scrape.li/quotes/&proxy_type=rotating&js=false' \
  -H "ApiKey: YOUR_API_KEY"

In Python it becomes a loop, and each call can leave through a different exit IP:

import requests

API = "https://api.ujeebu.com/scrape"
HEADERS = {"ApiKey": "YOUR_API_KEY"}

urls = [
    "https://scrape.li/",
    "https://scrape.li/quotes/",
    "https://scrape.li/quotes/?page=2",
]

results = []
for url in urls:
    r = requests.get(
        API,
        headers=HEADERS,
        params={"url": url, "proxy_type": "rotating", "js": "false"},
        timeout=90,
    )
    results.append({
        "url": url,
        "status": r.status_code,
        "bytes": len(r.content),
        "credits": r.headers.get("Ujb-Credits"),
    })

for row in results:
    print(row)

The Ujb-Credits response header carries what each call cost, so the cost of every request ends up next to its status in your logs instead of in a spreadsheet estimate.

Mode 2: a sticky IP for a multi-step flow

For flows, add proxy_session. Every request from your account that carries the same session value leaves through the same IP; a new value gets a different IP, and no value means normal rotation. The Article Extractor has the same behaviour under the name session_id.

The session value is scoped to your whole account, and that causes a real bug. Hardcode checkout42 and run ten workers in parallel, and all ten share one IP, which is exactly the pattern rotation exists to avoid. Any fixed alphanumeric string works for a single workflow; the safe habit is to generate one per workflow. The parameter is typed alphanumeric, so skip hyphens and underscores. A UUID's hex form fits:

import uuid
import requests

API = "https://api.ujeebu.com/scrape"
HEADERS = {"ApiKey": "YOUR_API_KEY"}

session = uuid.uuid4().hex  # alphanumeric, unique to this workflow

steps = [
    "https://scrape.li/",                # step 1: entry or login page
    "https://scrape.li/quotes/",         # step 2: list page
    "https://scrape.li/quotes/?page=2",  # step 3: next page in the same flow
]

for url in steps:
    r = requests.get(
        API,
        headers=HEADERS,
        params={"url": url, "proxy_session": session, "js": "false"},
        timeout=90,
    )
    print(url, r.status_code)
    if r.status_code != 200:
        break  # a broken flow is not worth continuing

If the flow depends on a cookie you already hold, such as an authenticated session token, pass it with the cookies parameter on each step. A sticky IP keeps the address constant. Keeping the site's state constant is still your job.

Mode 3: an IP in a specific country

Some content changes by country: prices, availability, search results, consent walls. proxy_country sets where the page is read from. It defaults to US, which is why a plain request already looks American to the site; setting a different country code is what changes the exit. A country-targeted read goes through a residential IP in that country and is billed as residential (20 credits without JavaScript, 30 with). An unknown country code is refused with a 400 before anything is fetched or billed, and a country read never falls back to a US exit. Geo-targeting is available on paid plans and top-up packs, not on the free trial alone.

The useful pattern is reading the same page from several countries and comparing:

import requests

API = "https://api.ujeebu.com/scrape"
HEADERS = {"ApiKey": "YOUR_API_KEY"}

url = "https://scrape.li/quotes/"
countries = ["GB", "DE", "FR"]

for country in countries:
    r = requests.get(
        API,
        headers=HEADERS,
        params={"url": url, "js": "false", "proxy_country": country},
        timeout=90,
    )
    if r.status_code == 200:
        print(country, "ok", len(r.content), "bytes", r.headers.get("Ujb-Credits"))
    else:
        print(country, "failed", r.status_code, r.text[:200])

The country is respected inside a sticky session too, so a geo-specific checkout flow can send proxy_country and proxy_session together. Because country reads cost more, keep them for pages where the country actually changes the content. A product description that is identical everywhere does not need a country-specific exit.

Managing multiple proxy providers yourself

Plenty of teams run more than one proxy provider, usually for sound reasons. Pools behave differently against different targets, coverage differs by country, prices differ, and an outage at one provider should not stop the whole pipeline.

The real cost of that setup is the bookkeeping, not the contracts. For each provider and each target domain you need to know how often requests return real content, and when a route has gone bad and should be taken out of rotation. Without those numbers, a drop in data quality is a vague sense that something broke, and you end up guessing which provider caused it.

If you already pay for proxies, the Scrape API's custom_proxy, custom_proxy_username and custom_proxy_password parameters send a request through your own proxy while the API still does the fetching and rendering. Either way, the health tracking looks the same. The sketch below treats each route as an entry in a dict, tracks success per route and domain, checks that the body actually contains the data you expected (a 200 with an empty template is still a miss), and picks the cheapest healthy route:

from collections import defaultdict
from urllib.parse import urlparse
import requests

API = "https://api.ujeebu.com/scrape"
HEADERS = {"ApiKey": "YOUR_API_KEY"}

# Ordered cheapest first. Add your own provider as another entry, e.g.
# "vendorA": {"custom_proxy": "...", "custom_proxy_username": "...", "custom_proxy_password": "..."}
routes = {
    "rotating": {"proxy_type": "rotating"},
    "premium": {"proxy_type": "premium"},
}

stats = defaultdict(lambda: {"ok": 0, "fail": 0})

def healthy(route, domain, min_rate=0.5, min_samples=20):
    s = stats[(route, domain)]
    total = s["ok"] + s["fail"]
    return total < min_samples or s["ok"] / total >= min_rate

def pick_route(domain):
    for name in routes:
        if healthy(name, domain):
            return name
    return list(routes)[-1]  # everything looks bad: use the strongest route

def fetch(url, expect):
    domain = urlparse(url).netloc
    route = pick_route(domain)
    params = {"url": url, "js": "false", **routes[route]}
    r = requests.get(API, headers=HEADERS, params=params, timeout=90)
    ok = r.status_code == 200 and expect in r.text
    stats[(route, domain)]["ok" if ok else "fail"] += 1
    return route, r

route, r = fetch("https://scrape.li/quotes/", expect="quote")
print(route, r.status_code)

The thresholds in healthy are placeholders to tune against your own traffic, and expect should be a string or marker that only appears when the page rendered your data. What matters is keying the stats by route and domain together: a route that fails on one retailer can be fine everywhere else. Record these numbers from day one, because you cannot reconstruct them after something goes wrong.

Troubleshooting rotation: bans, slow IPs and session drops

When rotation seems to stop working, check things in order.

First, confirm you are looking at blocks and not a parsing problem. Bot-check pages returned instead of content come back as failed requests on the Scrape API, but a site can also serve a soft block: a 200 with a stripped-down page, an empty result list or a consent wall. The content check in the tracker above catches those. A run of genuine failures on one target means it needs a stronger setting; retrying harder on the same setting will not help.

Next, escalate one step at a time. Move from the plain rotating pool to JavaScript rendering, or to the premium tier, or to a country-targeted read, depending on what the target seems to be checking. The credit table above prices each step. Changing three settings at once leaves you unable to tell which one helped.

Session drops have their own short list of causes: a step that is missing proxy_session, a session value accidentally shared between parallel workers, or a cookie that was not passed on every step.

Concurrency is the last thing to check. Rotation spreads load across IPs, but the target still sees the total, and a hundred requests in one second from a hundred addresses can look like exactly what it is. Throttle per target domain, not only globally. Your plan sets the ceiling on parallel calls: 20 concurrent requests on Starter, 50 on Growth, 100 on Pro and 300 on Business. A pre-flight call to the account endpoint shows your limit and balance:

import requests

HEADERS = {"ApiKey": "YOUR_API_KEY"}

acct = requests.get("https://api.ujeebu.com/account", headers=HEADERS, timeout=30).json()
print(acct["plan"], acct["concurrent_requests"], acct["balance"], acct["used"])

That endpoint allows 10 calls per minute, so call it before and after a run rather than inside your loop. The difference in used is the total cost of the run.

If responses are slow, start with the timeout settings. Set timeout, and js_timeout when rendering, per target instead of letting every site inherit the same defaults.

Proxy rotation API or your own proxy pool?

Running your own pool is sometimes the right call. If you already hold provider contracts and have engineers to maintain them, if you need tight control over exactly which IPs touch a target, or if most of your volume goes to one site with weak defences, a raw pool you manage can be the cheapest and simplest setup. A rotation layer adds little when the target never blocks you.

An API earns its keep in the opposite situation: varied targets, frequent block pages, and no appetite for maintaining the health tracker above across every provider. For scale, a plain scrape on Ujeebu costs from $0.16 per 1,000 requests on Starter down to $0.07 on Business, and a JavaScript-rendered scrape from $0.82 down to $0.33. Price your own pool honestly by counting the engineering hours alongside the bandwidth. If you are comparing APIs rather than deciding whether to use one, our comparison of web scraping APIs is the place to start.

Whichever way you go, the design stays the same: label your requests, give independent pages a fresh IP, give each flow its own session value, and pay for a country only when the country changes the page.

To try the three modes against your own targets, the plans and top-up packs are on the pricing page; the free trial (5,000 credits for 21 days, no card) covers rotation and sticky sessions, and failed requests are not billed.

FAQ

What is a proxy rotation API and how does it work?

It is an API that fetches pages for you through a managed pool of IP addresses. You send one request with the target URL, the service picks an exit IP, fetches the page and returns it. Rotation, health checks and exit selection happen behind the call, so your code never manages a proxy list.

What is the difference between rotating proxies and sticky sessions?

Rotating proxies give each request a fresh IP, which suits independent pages. A sticky session keeps the same IP across several requests, which suits logins, carts and paginated flows where the site ties state to an address. On the Scrape API, rotation is the default and you get a sticky IP by sending the same proxy_session value on each request.

How do I rotate proxies in Python for web scraping?

With a rotating proxy API, loop over your URLs and call the endpoint for each one with requests, without a session value; each call can leave through a different exit. For multi-step flows, generate one alphanumeric value per workflow (for example uuid.uuid4().hex) and pass it as proxy_session on every step.

Does proxy rotation prevent IP bans completely?

No. Rotation keeps any single IP from standing out, but sites also check headers, fingerprints, behaviour and bursts of traffic across addresses. Pair rotation with per-domain throttling, rendering where a site needs it, a stronger proxy tier for targets that score IP type, and a content check on every response.

When should I use residential proxies instead of datacenter proxies for rotation?

When a target keeps blocking the default pool and the blocks look like IP scoring rather than missing rendering or headers. Residential IPs cost more per request, so escalate target by target rather than for the whole crawl. Residential vs datacenter proxies covers the trade-off in depth.

How do I add geo-targeting to a rotating proxy request?

Add proxy_country with a country code such as GB or DE. The default is US, so you only need it to read from somewhere else. The page is fetched through a residential IP in that country and billed as residential, an unknown code returns a 400 without being billed, and geo-targeting needs a paid plan or a top-up pack.

Try it yourself

Run this on your own pages

Get a free API key and make your first call in minutes. 5,000 free credits for 21 days, no card.

← Back to blog Read the docs →