Trigger On-Demand Proxy IP Rotation and Verify the Change
October 29, 2026
Why force a rotation instead of waiting
Rotating proxy services usually change your IP automatically based on a mode you select: sticky keeps the same address until it fails or you rotate it, timed changes after an interval you set, and per request gives a new address for every connection. Automatic rotation works well for steady traffic, but it does not cover every situation.
You may need an immediate new IP when:
- The current IP is blocked or returning CAPTCHAs.
- You are switching between unrelated targets and want clean separation.
- A timed interval is too long for a time-sensitive task.
- You are debugging a scraper and need to confirm whether an IP is the problem.
Forcing a rotation through the API gives you control without destroying the session. The session keeps its username, password, and gateway connection details; only the exit IP changes.
What you need before you start
You need an active account and at least one session. Gather these values:
- API_KEY: your account API key.
- SESSION_ID: the identifier of the session you want to rotate.
- GATEWAY_HOST and HTTP_PORT: the gateway host and HTTP port for your session.
- USERNAME and PASSWORD: the credentials for that session.
On Pro and Business plans, you also have access to SOCKS5_PORT if you prefer SOCKS5 over HTTP.
The API uses bearer authentication. Every request to the session endpoints must include:
Authorization: Bearer API_KEY
Step 1: List your sessions
Before you can rotate a session, you need its ID. Use the list endpoint to see all sessions associated with your API key.
import requests
API_KEY = "API_KEY"
LIST_URL = "https://backend-api.ro-proxy.com/api/session"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
response = requests.get(LIST_URL, headers=headers, timeout=30)
response.raise_for_status()
sessions = response.json()
for session in sessions:
print(session.get("id"), session.get("status"))
Replace API_KEY with your actual key. The response is a list of session objects. Look for the id field; that is your SESSION_ID. If the list is empty, create a session in your account dashboard or through whatever provisioning method your plan provides before continuing.
Step 2: Check the current exit IP
Before rotating, record the IP address the proxy is currently using. This gives you a baseline to compare against after the rotation.
Configure the proxy in your HTTP client. For RoProxy, the HTTP proxy URL looks like this:
http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT
Use that same URL for both HTTP and HTTPS targets. Here is a short check using the standard library-friendly requests package:
import requests
PROXY_URL = "http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT"
proxies = {
"http": PROXY_URL,
"https": PROXY_URL,
}
response = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
print(response.json())
The output shows the exit IP seen by the target service. Save this value. If the request fails, verify your gateway host, port, username, and password before proceeding.
If your plan includes SOCKS5 access, you can use the SOCKS5 port instead. The scheme for SOCKS5 over a proxy is typically socks5h://USERNAME:PASSWORD@GATEWAY_HOST:SOCKS5_PORT, where the h means DNS resolution happens through the proxy.
Step 3: Force an IP rotation
When you need a new IP immediately, call the rotate endpoint for that session.
import requests
API_KEY = "API_KEY"
SESSION_ID = "SESSION_ID"
ROTATE_URL = f"https://backend-api.ro-proxy.com/api/session/{SESSION_ID}/rotate"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
response = requests.post(ROTATE_URL, headers=headers, timeout=30)
response.raise_for_status()
print(response.status_code, response.text)
A successful response means the session has been assigned a new exit IP. The session itself stays alive; you do not need to re-authenticate or reconfigure your proxy URL. The same USERNAME, PASSWORD, GATEWAY_HOST, and HTTP_PORT continue to work.
Step 4: Verify the change
Run the same exit-IP check again after the rotation.
import requests
PROXY_URL = "http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT"
proxies = {
"http": PROXY_URL,
"https": PROXY_URL,
}
response = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
new_ip = response.json().get("ip")
print("New exit IP:", new_ip)
Compare new_ip with the baseline you saved earlier. If they differ, the rotation worked. If they are the same, wait a few seconds and check again; some gateways propagate the change with a short delay.
Putting it together: rotate and verify in one script
This script lists sessions, picks the first one, checks the IP before and after rotation, and prints the result.
import requests
import time
API_KEY = "API_KEY"
LIST_URL = "https://backend-api.ro-proxy.com/api/session"
headers = {"Authorization": f"Bearer {API_KEY}"}
def get_exit_ip(proxy_url):
proxies = {"http": proxy_url, "https": proxy_url}
r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
r.raise_for_status()
return r.json().get("ip")
# List sessions
r = requests.get(LIST_URL, headers=headers, timeout=30)
r.raise_for_status()
sessions = r.json()
if not sessions:
raise SystemExit("No sessions found.")
session_id = sessions[0].get("id")
print(f"Using session: {session_id}")
# You must supply these from your session details
PROXY_URL = "http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT"
old_ip = get_exit_ip(PROXY_URL)
print("Old IP:", old_ip)
# Rotate
rotate_url = f"https://backend-api.ro-proxy.com/api/session/{session_id}/rotate"
r = requests.post(rotate_url, headers=headers, timeout=30)
r.raise_for_status()
print("Rotation requested.")
# Brief pause for propagation
time.sleep(3)
new_ip = get_exit_ip(PROXY_URL)
print("New IP:", new_ip)
if old_ip != new_ip:
print("Rotation confirmed: exit IP changed.")
else:
print("Warning: exit IP did not change.")
This example uses the requests package, which is widely used and easy to read. If you cannot install third-party packages, replace requests with urllib.request from the Python standard library; the request flow and endpoints remain the same.
Handling common errors
- 401 Unauthorized: your API_KEY is missing, misspelled, or revoked. Check the Authorization header.
- 404 Not Found: the SESSION_ID does not exist or does not belong to your account.
- 429 Too Many Requests: you are calling the rotate endpoint faster than allowed. Slow down and retry after a short pause.
- Connection errors: verify GATEWAY_HOST and HTTP_PORT, and make sure your network allows outbound connections to that host.
When a rotation fails, do not retry blindly in a tight loop. Back off for a few seconds, then try once more. Repeated failed rotations can trigger rate limits on the API side.
Sticky, timed, and on-demand rotation together
On-demand rotation works best when combined with a session's default mode.
- Sticky: use the session normally, then call rotate only when the IP stops working.
- Timed: let the automatic interval handle routine changes, and call rotate when you need an immediate new IP outside the schedule.
- Per request: available on the Business plan; you generally do not need manual rotation because every connection already uses a new IP.
Think of on-demand rotation as an override, not a replacement for your session's configured mode.
Conclusion
Forcing an IP rotation through the API gives you precise control over when your exit address changes, without dropping the session or reconfiguring your client. List your sessions, call the rotate endpoint, and verify the result with a simple IP check. This pattern is useful for scraping, automation, and any workflow where a blocked IP should not stop your work.
RoProxy provides the session gateway and API endpoints described here; sign in, create a session, and try the rotation flow with your free trial sessions.