How to use proxies with Axios
Axios supports a proxy option, but its built-in handling does not tunnel HTTPS reliably. The dependable pattern in Node.js is to pass an https-proxy-agent instead and disable the native proxy option.
Recommended for Axios
Residential proxies — Axios jobs are usually high-volume API and HTML collection, where rotating residential IPs prevent the rate limiting a single address runs into.
See residential proxiesSetup
- 1
Install the agent
Install Axios together with the proxy agent that handles HTTPS tunnelling correctly.
npm i axios https-proxy-agent - 2
Route requests through the agent
Set httpsAgent and turn off the native proxy option, otherwise Axios tries to handle the proxy itself and the two conflict. Replace PROXY_HOST, PROXY_PORT, USERNAME and PASSWORD with the endpoint and credentials shown in your seamless dashboard.
const axios = require("axios"); const { HttpsProxyAgent } = require("https-proxy-agent"); const agent = new HttpsProxyAgent( "http://USERNAME:PASSWORD@PROXY_HOST:PROXY_PORT" ); const res = await axios.get("https://example.com", { httpsAgent: agent, proxy: false, // required: prevents Axios' own proxy handling from interfering timeout: 30000, }); - 3
Create a preconfigured instance
An Axios instance keeps the agent and headers in one place instead of repeating them at every call site.
const client = axios.create({ httpsAgent: agent, proxy: false, timeout: 30000, headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" }, }); const { data } = await client.get("https://example.com"); - 4
Rotate per request
Build a fresh agent with a new session identifier when you want each request to leave from a different IP.
const { randomUUID } = require("crypto"); function rotatingAgent() { const session = randomUUID().slice(0, 8); return new HttpsProxyAgent( `http://USERNAME-session-${session}:PASSWORD@PROXY_HOST:PROXY_PORT` ); }
Axios proxy FAQ
Why does the Axios proxy option not work for HTTPS?
Axios' built-in proxy handling does not establish a CONNECT tunnel correctly in all Node versions, which produces TLS and certificate errors. Passing an https-proxy-agent as httpsAgent and setting proxy: false is the reliable approach.
How do I authenticate a proxy in Axios?
Include the credentials in the URL you hand to HttpsProxyAgent, in the form http://username:password@host:port. The agent sets the Proxy-Authorization header for you.
Can I use one agent for all requests?
Yes, and you should when you want connection reuse. Create a separate agent per session only when you deliberately want each request to leave through a different exit IP.
Before you scale this up

How to Choose the Best Proxies for Web Scraping
Which proxy type to use, how to size your pool, how rotation and geo-targeting work, and the response-quality checks that catch silent failures.
Read guide
How to Avoid Getting Blocked When Web Scraping
The six layers a modern anti-bot system checks, in the order it checks them — and what to change at each one to stay unblocked.
Read guide
Rotating vs Sticky Proxy Sessions Explained
When to rotate IPs on every request and when to hold one — with a decision rule, session-length guidance and the bugs each choice causes.
Read guide