The proxy string your bot should accept: one format, every token

2026-10-03 · Bazyl

Your bot needs one proxy parser, not three. Every string our residential pool hands out is http://USER-<tokens>:PASS@<gateway>:2115, with all the targeting on the username, and the two other formats our API can emit are the same four fields in a different order. Below is a parser and a builder in Python that take all of them.

The thing most people get wrong is where they look for the targeting. Nothing rides the password here. It never changes, and a parser that expects flags on it reads every string wrong.

This is the format every account created from 27 October 2026 gets. Older accounts keep the legacy format on ports 4242 and 4243, and the parser below accepts their lines too.

Four fields, and only one of them is busy

A string is a host, a port, a username and a password, and the username does all the work. Here is a sticky one with three tokens on it:

http://USER-cc-de-sess-9f2k41ab-ttl-60:[email protected]:2115

The host is one of three gateways: eu-residential2.basilproxies.com, us-residential2.basilproxies.com and ap-residential2.basilproxies.com. Same pool, three doors. Pick the one nearest the machine running the bot, because the choice is latency and nothing else. The exit country comes from the token: a server in Frankfurt exiting from US IPs still wants the eu- door.

There is one port, 2115, and it runs both session models. The username picks: no session token rotates, a new IP on every request, and a -sess- token holds one IP for as long as -ttl- says. A login in this format works on 2115 and nowhere else.

Port 2115 speaks HTTP, and https:// targets tunnel straight through. There is no SOCKS5 on this pool. Point an HTTP-proxy setting at the gateway and you are done.

Tokens are pairs in any order, so parse them as pairs

Tokens ride the username as -key-value pairs, and the gateway takes them in any order and any case. It lower-cases the username, takes everything before the first hyphen as the login, and reads the rest two segments at a time. No value contains a hyphen, which is what makes any order safe. Six keys carry the targeting:

  • -cc-de: a two-letter ISO country code. Leave it off and you get the worldwide pool.
  • -city-newyork: the code exactly as the dashboard's city picker writes it. Needs cc. Can't combine with isp.
  • -isp-7922: an ASN, digits only, no "AS". Needs cc. Can't combine with city.
  • -os-windows (or mac, ios, android): combines with anything.
  • -sess-9f2k41ab: 1 to 32 lowercase letters or digits. Present means sticky, and the same id keeps the same IP.
  • -ttl-60: minutes, 1 to 1440, no leading zero. Needs sess. Leave it off and the session holds for 15 minutes. 1,440 minutes is 24 hours, and that is the ceiling.

Each key at most once. A key the gateway doesn't know is refused with an error that names it, never ignored, so a typo can't quietly hand you the wrong country. The dashboard generator always writes one order, cc, then city or isp, then os, sess and ttl, and puts a ttl on every sticky line.

This is what every slot filled looks like, in the API's default format:

eu-residential2.basilproxies.com:2115:USER-cc-de-city-berlin-os-android-sess-9f2k41ab-ttl-60:PASS

Drop any token and the rest still parse. Shuffle them and the string means the same thing. A parser that splits the username on hyphens and walks the segments two at a time reads every string in this format, with no exception to remember.

Three output formats, one set of fields

GET /api/v1/proxies on the account API emits the same line in three formats, and your users will paste all three at you, so accept all three. The call takes product, country, session (rotating or sticky), count up to 1,000 and format:

  • host:port:user:pass, the default: eu-residential2.basilproxies.com:2115:USER-cc-us:PASS
  • user:pass@host:port: USER-cc-us:[email protected]:2115
  • url: http://USER-cc-us:[email protected]:2115
# 3 sticky US lines in url format; the key stays in an env var
curl "https://api.basilproxies.com/api/v1/proxies?product=residential&country=us&session=sticky&count=3&format=url" \
  -H "Authorization: Bearer $BASIL_API_KEY"

The endpoint builds lines from the login the account already holds, in that account's own format. Nothing is created and no data is spent, so a bot can call it on every start. The answer carries "syntax": "v2" when its lines are in the format on this page; a legacy account gets legacy lines and no such field. The dashboard generator does the same job by hand, up to 100,000 lines per generation, with the same tokens in the same order. Two sources, one parser.

The parser and the builder

Both functions below know the three hosts, the one port and the six keys, and nothing else. parse accepts any of the three formats and refuses a line that isn't ours. build validates each token and always writes the dashboard's order, so parse followed by build turns a hand-typed string with its tokens shuffled into the exact string the generator would have written.

import re

GATEWAYS = {
    "eu": "eu-residential2.basilproxies.com",
    "us": "us-residential2.basilproxies.com",
    "ap": "ap-residential2.basilproxies.com",
}
HOSTS = {v: k for k, v in GATEWAYS.items()}
PORT = 2115  # the only port: a -sess- token is what makes a line sticky
LEGACY_PORTS = {4242: "rotating", 4243: "sticky"}  # accounts created before 27 October 2026

# What the gateway accepts for each key, in the order the dashboard writes them.
RULES = {
    "cc": r"[a-z]{2}",
    "city": r"[a-z0-9]{1,40}",     # as the dashboard's city picker writes it
    "isp": r"\d{1,10}",            # an ASN, digits only, no "AS"
    "os": r"windows|mac|ios|android",
    "sess": r"[a-z0-9]{1,32}",
    "ttl": r"[1-9]\d{0,3}",        # 1 to 1440 minutes, no leading zero
}
ORDER = tuple(RULES)


def build(user, password, gateway="eu", fmt="url", legacy=None, **tokens):
    """Tokens ride the username in the dashboard's order; the password carries nothing."""
    if legacy:
        raise ValueError("a legacy login works only on 4242/4243: use that line as pasted")
    for key, value in tokens.items():
        if key not in RULES or not re.fullmatch(RULES[key], str(value)):
            raise ValueError(f"bad token {key}={value}")
    if "city" in tokens and "isp" in tokens:
        raise ValueError("city and isp can't share one username")
    if ("city" in tokens or "isp" in tokens) and "cc" not in tokens:
        raise ValueError("city and isp need a cc token")
    if "ttl" in tokens and "sess" not in tokens:
        raise ValueError("ttl needs a sess token")
    if int(tokens.get("ttl", 1)) > 1440:
        raise ValueError("1440 minutes (24 hours) is the ceiling")
    u = "-".join([user] + [f"{k}-{tokens[k]}" for k in ORDER if k in tokens])
    host = GATEWAYS[gateway]
    if fmt == "url":
        return f"http://{u}:{password}@{host}:{PORT}"
    if fmt == "user:pass@host:port":
        return f"{u}:{password}@{host}:{PORT}"
    return f"{host}:{PORT}:{u}:{password}"  # host:port:user:pass, the API default


def parse(line):
    """Accept host:port:user:pass, user:pass@host:port or the url form."""
    line = line.strip()
    if "://" in line and not line.startswith("http://"):
        raise ValueError("the pool speaks HTTP: use http:// or drop the scheme")
    line = line.removeprefix("http://")
    if line.split(":")[0] in HOSTS:  # host:port:user:pass
        host, port, user, password = line.split(":", 3)
    elif "@" in line:  # user:pass@host:port, or the url form minus its scheme
        creds, endpoint = line.rsplit("@", 1)
        user, password = creds.split(":", 1)
        host, port = endpoint.rsplit(":", 1)
    else:
        raise ValueError(f"not one of our residential endpoints: {line}")
    port = int(port)
    if host not in HOSTS or (port != PORT and port not in LEGACY_PORTS):
        raise ValueError(f"not one of our residential endpoints: {host}:{port}")
    if port in LEGACY_PORTS:  # legacy format: pass it through untouched
        return dict(user=user, password=password, gateway=HOSTS[host], legacy=LEGACY_PORTS[port])
    login, *segs = user.split("-")
    segs = [s.lower() for s in segs]  # the gateway ignores case
    if len(segs) % 2:
        raise ValueError("tokens come as -key-value pairs")
    tokens = dict(zip(segs[::2], segs[1::2]))
    if len(tokens) * 2 != len(segs):
        raise ValueError("each key at most once")
    for key in tokens:
        if key not in RULES:
            raise ValueError(f"unknown key: {key}")  # the gateway refuses it too
    return dict(user=login, password=password, gateway=HOSTS[host], **tokens)


line = "eu-residential2.basilproxies.com:2115:USER-cc-de-city-berlin-os-android-sess-9f2k41ab-ttl-60:PASS"
p = parse(line)
print(build(**p))                                     # same string, url form
print(build(**p, fmt="host:port:user:pass") == line)  # True: the round trip is exact
print(build(**parse("USER-ttl-30-SESS-m2p8zq4r-cc-US:[email protected]:2115")))
# http://USER-cc-us-sess-m2p8zq4r-ttl-30:[email protected]:2115, the dashboard's order
print(parse("eu-residential2.basilproxies.com:4243:USER-country-de:PASS")["legacy"])  # sticky: pass it through

Two details are deliberate. Tokens are lower-cased before they're checked, the way the gateway does it, so -CC-US comes back out as -cc-us. And an unknown key raises instead of being dropped, because the gateway refuses it too: a legacy token on a new login, -country-us, gets 400 with E10 unknown key: country, and parse says the same thing before the bot ever sends it.

One branch is there for the customers you already have. Lines on 4242 and 4243 are the legacy format, which every account created before 27 October 2026 keeps, and so does every partner's customer: a different login, longer tokens in a fixed order, and the port picks the session model. Those lines keep working. parse returns them marked legacy with the username untouched, and build refuses to rebuild one, because a legacy login doesn't work on port 2115. Hand a legacy line to the HTTP client as pasted. Its grammar is in the docs' legacy section.

A refusal in the first minute is not a parse error

A brand-new login can answer 407 or 503 for its first minute or two while it reaches every gateway. That is not a wrong password and not a bad string. Retry before you touch anything.

After that, read the body. Every refusal is one line that names the problem: E53 login not ready yet is still the warm-up, E01 invalid proxy login is the login or the password, and E10 to E15 name the token that's off. An E01 that never clears is nearly always a token on the password, or a legacy login pasted onto port 2115. Regenerate the string in the dashboard and diff the two. The generator's output is the reference, not your parser's.

What this parser does not do

It does not speak SOCKS5, because the pool doesn't. A socks5:// line is not ours, and parse raises on it. It does not know the city codes, because they come from the dashboard's picker and there are too many to ship inside a bot; when a city string misbehaves, generate one in the dashboard and compare. And it does not read the legacy grammar: a legacy line passes through, and other hosts and other ports raise, by design, so a stale list from a customer's notes fails loudly instead of timing out.

Generate three lines with the curl above, run them through parse, and build the rest of the integration from the bot developers page.

Common questions

How do I make a string sticky instead of rotating?
Add a session token to the username. A login with no -sess- token rotates, a new IP on every request. Add -sess- followed by 1 to 32 lowercase letters or digits and the same id keeps the same IP; -ttl- sets how long in minutes, up to 1,440 (24 hours), and 15 when you leave it off. Port 2115 does both.
Does the password carry any targeting?
No. Every targeting token rides the username as a -key-value pair, in any order: cc, city or isp, os, sess, ttl. The password never changes.
Which gateway should my bot use?
The one nearest the machine running it: eu-, us- or ap-residential2.basilproxies.com. The gateway only decides where traffic enters the network. The exit country comes from the -cc- token on the username.
Can a bot use SOCKS5 on the residential pool?
No. Port 2115 speaks HTTP, and https:// targets tunnel through. Point an HTTP-proxy setting at the gateway and refuse socks5:// lines in your parser.
What about strings on ports 4242 and 4243?
That is the legacy format, which every account created before 27 October 2026 keeps, and so does every partner's customer: a different login, longer tokens in a fixed order, and the port picks rotating or sticky. Those lines keep working. A bot should pass them through as pasted; the docs page documents them in its Legacy format section.