How to Set Up a Sticky Session Through the Proxy Username
Some proxy providers let you keep the same exit IP for a while by adding a session label to the username. Here is how the idea works and how to test it safely.
9 min readUpdated Nov 13, 2026By XPASS Editorial Team

When you send traffic through a rotating proxy pool, each request may leave from a different exit IP address. That is useful for some jobs, but it breaks others. If you are testing a checkout flow on your own site, reviewing how a page looks from another region, or holding a login you are entitled to use, a changing IP in the middle of the flow can cause confusing results. A sticky session solves this by keeping the same exit IP for a short window.
This guide explains what a sticky session is, how providers commonly expose it through the proxy username, how to build and test a session label, and what limits you should expect. All examples are generic. Every provider writes its own format, so always check the instructions that come with your plan before copying a pattern. Use proxies only for lawful work that respects the terms of the sites you visit and the laws where you live.
What a sticky session actually is
A normal HTTP or SOCKS proxy sits between your application and the destination. Your client connects to the proxy address and port, authenticates, and asks the proxy to forward a request. With a single fixed proxy, every request leaves from the same IP. With a rotating pool, the provider picks an exit IP from a larger set, and that choice can change from request to request.
A sticky session is the middle ground. The provider remembers a mapping between a label you supply and one exit IP. As long as you send the same label, requests are routed to the same exit, until a timer expires or that exit becomes unavailable. The word "sticky" simply means the assignment stays attached to you for a while.
It is helpful to separate three ideas that people often mix up:
- Rotation: a new exit IP for each request or each connection.
- Sticky session: the same exit IP for a series of requests, for a limited time.
- Static IP: an address that is assigned to you for a long period, often by rental.
Sticky sessions are not the same as owning a dedicated address. They are a convenience layered on a shared pool, and the pool owner remains in control of how long the assignment lasts.

Why the username carries the session label
Proxy authentication in the HTTP world is defined around a username and password sent with each connection or request. See the description of proxy authentication in MDN's overview of proxy servers and tunneling and the semantics in RFC 9110. SOCKS5 has its own username and password method, described in RFC 1928 and its related documents.
Because every client library already supports a username field, providers use that field as a free-form channel. They read extra keywords from the username, strip them off, and use them as instructions. The password still proves who you are; the extra keywords tell the gateway how to behave. Common instructions include the country of the exit, the length of a session, and the session label itself.
That design has a big advantage: you do not need special code. Anything that can set a proxy username can ask for a sticky session. It also has a risk: the username is now a small configuration string, so a typing mistake changes the behaviour without raising an obvious error.
Anatomy of a session label
Providers differ, so treat the following as an illustration and not as the format of any specific service. A typical pattern looks like this:
BASE_USERNAME-session-a1b2c3
or, with extra options:
BASE_USERNAME-country-us-session-a1b2c3-duration-10
Read it as three parts:
- The base username: the account name your provider gave you.
- Option keywords: words like a country code or duration that the gateway understands.
- The session label: a short string you invent, such as a random six-character ID. Each unique label maps to one exit IP.
The exact separators (hyphen, underscore, colon), the keyword names and the way durations are expressed are all provider specific. Some providers put options in the password instead of the username. Others use a separate port for each sticky exit. Your provider's documentation or the plan page is the authority; this article only explains the idea behind it.
Good labels are short, use only letters and digits, and are unique per logical task. Avoid spaces and symbols that a URL or shell could treat specially, because proxy credentials are often embedded in a URL such as http://user:pass@host:port.
Step by step: build and test a sticky session
The easiest way to learn the behaviour is to test it from a command line before you wire it into an application. You will need the gateway host, the port, your base username and password, and the documented option format.
Step 1: collect the connection details
Open your plan details and write down the gateway host, port, protocol (HTTP or SOCKS5), and the documented way to add a session label. If the format is not shown, ask the provider's support instead of guessing.
Step 2: invent a label
Choose a random label, for example t20261130a. One label equals one session. Do not reuse the same label for unrelated jobs, or those jobs will share one exit IP.
Step 3: send repeated requests
Use any tool that lets you pass proxy credentials. With curl it looks like this, where the placeholders stand for your own values:
curl -x "http://BASE_USERNAME-session-t20261130a:PASSWORD@GATEWAY_HOST:PORT" https://api.ipify.org
Run the command three times in a row. If the label is accepted, the printed IP should be the same each time. The address echo service in the example is only one option; any service that returns the caller's public IP will do. Our guide on checking the public IP after a proxy connection lists more ways to confirm what the outside world sees.
Step 4: change the label
Repeat with a new label such as t20261130b. The IP should now differ from the first one, although occasionally two labels can land on the same exit by chance in a small pool. Try a third label if the first change looks identical.
Step 5: record what you learned
Write down how long the session held, whether any request failed, and what an error looks like. These notes become the basis of your retry logic later.
Putting the label into an application
Once the command-line test works, move the same string into your code or tool. The principle is to keep the label as a single configuration value, not scattered across the program.
- Generate the label once per task. If a task is "log in, open the orders page, download the report", create one label at the start and reuse it for all three steps.
- Store it next to the proxy settings. A small configuration object that holds host, port, base username, password and session label keeps things readable.
- Build the username in one place. A helper function that joins the base username and label avoids typos spread through the code.
- Log the label, never the password. When something goes wrong, the label helps the provider's support team find the session. Passwords should never appear in logs.
If you also change the exit country between tasks, build the country option in the same helper. The article on changing the proxy country without rewriting the app shows how to keep that kind of choice in configuration so code stays untouched.
A plain example in pseudo-code:
label = random_id(6)
username = base_username + "-session-" + label
client = http_client(proxy = host:port, user = username, pass = password)
client.get(login_url)
client.get(orders_url)
client.get(report_url)
All three requests carry the same username, so they should share the same exit IP while the session lasts. When the task ends, drop the label. The next task creates a new one.
Limits and what to watch for
Sticky sessions are helpful, but they come with limits that you should plan for rather than discover in production.
Sessions expire. Providers set a maximum lifetime, and some let you request a shorter one. After that the label may be assigned a new IP. Your code should treat a session as a hint, not a promise.
Exits can disappear. In a shared pool the underlying device or line can go offline at any time, and the gateway will then give you a different IP even if your timer has not run out. Build in a retry that re-checks the IP when a long flow fails halfway.
A label is not a secret. Anyone who knows your credentials and label could use the same exit, so never put credentials in shared documents. Treat the base username and password as secrets.
The format is easy to mistype. A missing hyphen may silently turn a sticky request into a rotating one. This is why the repeated-request test in the steps above is worth running whenever you change the string.
Sticky does not mean permanent. If you need an address to stay with you for weeks, a rotating pool with sticky labels is not the right tool. Look at products that assign an address for a rental period instead.
Respect the target. A stable IP does not entitle you to ignore a website's terms, rate limits or robots rules. Use it for lawful testing, quality assurance and work you are permitted to do, and follow local law.
Timeouts and connection errors can look like sticky-session problems when they are really network or configuration issues. If requests hang, read what a proxy timeout means and the basic fixes before you change the label format.
A quick comparison
| Need | Rotating pool | Sticky session | Rented static IP |
|---|---|---|---|
| New IP on every request | Yes | No | No |
| Same IP across a short flow | No | Yes, for a limited time | Yes |
| Same IP for weeks | No | No | Usually yes |
| Extra code needed | None | A session label in the username | None |
| Best for | Wide, independent requests | Multi-step tasks and consistent testing | Long-term allow-listing |
Use the table as a rule of thumb. Check the plan page for which of these options your plan includes.
Troubleshooting checklist
If the IP keeps changing even though you use a label, work through this list in order:
- Compare the username character by character with the documented format, including hyphens and case.
- Confirm that you are using the host and port intended for sticky use, if your provider separates them.
- Check that your client does not open a new connection with a different username on each request.
- Make sure a library or framework is not retrying through another proxy setting, such as a system-wide one.
- Run the three-request test from a plain command line to rule out application code.
- Ask support whether the session lifetime is shorter than you assumed.
If the IP stays the same but requests fail, the problem is probably not stickiness. Look at the port, the protocol and your credentials instead.
Summary
A sticky session keeps the same exit IP for a series of requests for a limited time. Providers commonly let you request it by adding a session label to the proxy username, but the exact pattern is theirs to define, so follow the documentation. Build the label in one place, test it with repeated requests and a changed label, and plan for expiry and dropped exits. Use it for lawful, permitted work that respects the sites you visit. When you are ready to see what is offered, the XPASS Proxy page explains the options in more detail.
Frequently asked questions
What is a sticky session in a proxy?
A sticky session is a setting where a series of requests keeps leaving through the same exit IP address for a period of time, instead of the IP changing on every request. A provider usually lets you choose it by adding a session label to the username.
Where do I put the session label?
In most setups it is part of the proxy username, for example a base username followed by a keyword and a short ID you invent. The exact format differs by provider, so copy the pattern from your provider's own documentation or plan page.
Does a sticky session last forever?
No. A sticky session ends after a time limit set by the provider, or sooner if the exit IP goes offline. Your application should be ready to receive a different IP at any moment.
How do I know the sticky session works?
Send two or three requests with the same label to an IP-echo address and compare the results. If the IP stays the same, the label is working. Then change the label and confirm that the IP changes.
Is it fine to use sticky sessions for any website?
Only for lawful use that respects the target site's terms and local law. A sticky session is a technical convenience for consistent testing and logins you are allowed to perform. It is not a way around a site's rules.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Need a proxy for this?
XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.
See proxy plansKeep reading

Proxy Guides
How to Change Proxy Country Without Rewriting Your App
Keep the country choice out of your code. This guide shows how to switch proxy country through configuration, environment variables and endpoint settings, then verify the result.
9 min read

Proxy Guides
What a Proxy Timeout Means and How to Fix It
A timeout does not tell you what failed, only that no answer arrived in time. This guide shows how to narrow down the cause and apply basic fixes in order.
9 min read

Proxy Guides
How to See Your Public IP After Connecting to a Proxy
A practical guide to reading your public IP after a proxy connection: browser checks, command line checks, what the result means and why it sometimes looks wrong.
9 min read