[{"data":1,"prerenderedAt":19},["ShallowReactive",2],{"blog:post:en:trigger-on-demand-proxy-ip-rotation-and-verify-the-change":3},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":14,"thumbnail_url":15,"translations":16,"body":17,"asset_base":18},"trigger-on-demand-proxy-ip-rotation-and-verify-the-change","en","Trigger On-Demand Proxy IP Rotation and Verify the Change","Use the session API to list proxies, force an IP rotation on demand, and confirm the exit IP changed with a short Python script.","2026-10-29",[10,11,12,13],"python","proxy-rotation","api","networking",[10,11,12,13],"https://blog-api.ro-proxy.com/api/blog/posts/trigger-on-demand-proxy-ip-rotation-and-verify-the-change/thumbnail.svg?lang=en",[5],"## Why force a rotation instead of waiting\n\nRotating 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.\n\nYou may need an immediate new IP when:\n\n- The current IP is blocked or returning CAPTCHAs.\n- You are switching between unrelated targets and want clean separation.\n- A timed interval is too long for a time-sensitive task.\n- You are debugging a scraper and need to confirm whether an IP is the problem.\n\nForcing 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.\n\n## What you need before you start\n\nYou need an active account and at least one session. Gather these values:\n\n- API_KEY: your account API key.\n- SESSION_ID: the identifier of the session you want to rotate.\n- GATEWAY_HOST and HTTP_PORT: the gateway host and HTTP port for your session.\n- USERNAME and PASSWORD: the credentials for that session.\n\nOn Pro and Business plans, you also have access to SOCKS5_PORT if you prefer SOCKS5 over HTTP.\n\nThe API uses bearer authentication. Every request to the session endpoints must include:\n\nAuthorization: Bearer API_KEY\n\n## Step 1: List your sessions\n\nBefore you can rotate a session, you need its ID. Use the list endpoint to see all sessions associated with your API key.\n\n```python\nimport requests\n\nAPI_KEY = \"API_KEY\"\nLIST_URL = \"https://backend-api.ro-proxy.com/api/session\"\n\nheaders = {\n    \"Authorization\": f\"Bearer {API_KEY}\"\n}\n\nresponse = requests.get(LIST_URL, headers=headers, timeout=30)\nresponse.raise_for_status()\n\nsessions = response.json()\nfor session in sessions:\n    print(session.get(\"id\"), session.get(\"status\"))\n```\n\nReplace 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.\n\n## Step 2: Check the current exit IP\n\nBefore rotating, record the IP address the proxy is currently using. This gives you a baseline to compare against after the rotation.\n\nConfigure the proxy in your HTTP client. For RoProxy, the HTTP proxy URL looks like this:\n\nhttp://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\n\nUse that same URL for both HTTP and HTTPS targets. Here is a short check using the standard library-friendly requests package:\n\n```python\nimport requests\n\nPROXY_URL = \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\"\nproxies = {\n    \"http\": PROXY_URL,\n    \"https\": PROXY_URL,\n}\n\nresponse = requests.get(\"https://api.ipify.org?format=json\", proxies=proxies, timeout=30)\nprint(response.json())\n```\n\nThe 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.\n\nIf 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.\n\n## Step 3: Force an IP rotation\n\nWhen you need a new IP immediately, call the rotate endpoint for that session.\n\n```python\nimport requests\n\nAPI_KEY = \"API_KEY\"\nSESSION_ID = \"SESSION_ID\"\nROTATE_URL = f\"https://backend-api.ro-proxy.com/api/session/{SESSION_ID}/rotate\"\n\nheaders = {\n    \"Authorization\": f\"Bearer {API_KEY}\"\n}\n\nresponse = requests.post(ROTATE_URL, headers=headers, timeout=30)\nresponse.raise_for_status()\n\nprint(response.status_code, response.text)\n```\n\nA 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.\n\n## Step 4: Verify the change\n\nRun the same exit-IP check again after the rotation.\n\n```python\nimport requests\n\nPROXY_URL = \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\"\nproxies = {\n    \"http\": PROXY_URL,\n    \"https\": PROXY_URL,\n}\n\nresponse = requests.get(\"https://api.ipify.org?format=json\", proxies=proxies, timeout=30)\nnew_ip = response.json().get(\"ip\")\nprint(\"New exit IP:\", new_ip)\n```\n\nCompare 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.\n\n## Putting it together: rotate and verify in one script\n\nThis script lists sessions, picks the first one, checks the IP before and after rotation, and prints the result.\n\n```python\nimport requests\nimport time\n\nAPI_KEY = \"API_KEY\"\nLIST_URL = \"https://backend-api.ro-proxy.com/api/session\"\n\nheaders = {\"Authorization\": f\"Bearer {API_KEY}\"}\n\ndef get_exit_ip(proxy_url):\n    proxies = {\"http\": proxy_url, \"https\": proxy_url}\n    r = requests.get(\"https://api.ipify.org?format=json\", proxies=proxies, timeout=30)\n    r.raise_for_status()\n    return r.json().get(\"ip\")\n\n# List sessions\nr = requests.get(LIST_URL, headers=headers, timeout=30)\nr.raise_for_status()\nsessions = r.json()\nif not sessions:\n    raise SystemExit(\"No sessions found.\")\n\nsession_id = sessions[0].get(\"id\")\nprint(f\"Using session: {session_id}\")\n\n# You must supply these from your session details\nPROXY_URL = \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\"\n\nold_ip = get_exit_ip(PROXY_URL)\nprint(\"Old IP:\", old_ip)\n\n# Rotate\nrotate_url = f\"https://backend-api.ro-proxy.com/api/session/{session_id}/rotate\"\nr = requests.post(rotate_url, headers=headers, timeout=30)\nr.raise_for_status()\nprint(\"Rotation requested.\")\n\n# Brief pause for propagation\ntime.sleep(3)\n\nnew_ip = get_exit_ip(PROXY_URL)\nprint(\"New IP:\", new_ip)\n\nif old_ip != new_ip:\n    print(\"Rotation confirmed: exit IP changed.\")\nelse:\n    print(\"Warning: exit IP did not change.\")\n```\n\nThis 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.\n\n## Handling common errors\n\n- 401 Unauthorized: your API_KEY is missing, misspelled, or revoked. Check the Authorization header.\n- 404 Not Found: the SESSION_ID does not exist or does not belong to your account.\n- 429 Too Many Requests: you are calling the rotate endpoint faster than allowed. Slow down and retry after a short pause.\n- Connection errors: verify GATEWAY_HOST and HTTP_PORT, and make sure your network allows outbound connections to that host.\n\nWhen 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.\n\n## Sticky, timed, and on-demand rotation together\n\nOn-demand rotation works best when combined with a session's default mode.\n\n- Sticky: use the session normally, then call rotate only when the IP stops working.\n- Timed: let the automatic interval handle routine changes, and call rotate when you need an immediate new IP outside the schedule.\n- Per request: available on the Business plan; you generally do not need manual rotation because every connection already uses a new IP.\n\nThink of on-demand rotation as an override, not a replacement for your session's configured mode.\n\n## Conclusion\n\nForcing 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.\n\nRoProxy provides the session gateway and API endpoints described here; sign in, create a session, and try the rotation flow with your free trial sessions.\n","https://blog-api.ro-proxy.com/api/blog/posts/trigger-on-demand-proxy-ip-rotation-and-verify-the-change/assets",1793257811290]