Integration · HTTP clients
How to use a proxy with Axios
Axios takes a proxy in Node.js through its proxy option: protocol, host, port and an auth object. Since Axios 1.16.1, HTTPS targets are tunnelled through CONNECT with that option alone. On older versions, use https-proxy-agent as the httpsAgent and set proxy: false.
Reviewed 30 Oct 2026
http://USERNAME _pool-arcfast _country-de:PASSWORD@ proxy.arcproxies.io:8000The short answer
- On Axios 1.16.1+,
proxy: { protocol, host, port, auth }handles HTTP and HTTPS targets. - On older versions, the
proxyoption did not tunnel HTTPS properly;httpsAgent: new HttpsProxyAgent(url)withproxy: falseis the safe route. proxyis Node-only; Axios in the browser ignores it.- A rejected tunnel comes back as
error.response.status === 407; do not retry it.
Setup
Set up Axios with a proxy, step by step
- 01
Install Axios and check the version
The version decides which setup to use.
https-proxy-agentandsocks-proxy-agentare only needed for older Axios and for SOCKS5.shell4 linesnpm i axiosnpm ls axios # 1.16.1 or later: the proxy option is enoughnpm i https-proxy-agent # only for older Axiosnpm i socks-proxy-agent # only for SOCKS5 - 02
Use the proxy option and check the exit
Host, port and credentials are separate fields. The echo service returns the exit the target sees.
check-exit.mjs12 linesimport axios from 'axios';const res = await axios.get('https://api.ipify.org?format=json', { proxy: { protocol: 'http', host: 'proxy.arcproxies.io', port: 8000, auth: { username: 'USERNAME_pool-arcfast_country-de', password: 'PASSWORD' }, }, timeout: 30_000,});console.log(res.data); // { ip: '…' } - 03
On Axios before 1.16.1: https-proxy-agent
Hand the tunnelling to an agent and switch Axios' own proxy handling off, including the environment variables it would otherwise read.
legacy.mjs10 linesimport axios from 'axios';import { HttpsProxyAgent } from 'https-proxy-agent';const agent = new HttpsProxyAgent('http://USERNAME_pool-arcfast_country-de:PASSWORD@proxy.arcproxies.io:8000');const res = await axios.get('https://api.ipify.org?format=json', { httpsAgent: agent, proxy: false, timeout: 30_000,});console.log(res.data); - 04
One Axios instance per sticky session
axios.create()bakes the proxy into an instance. A task that should keep one exit gets an instance with its own_session-handle.sticky.mjs24 linesimport axios from 'axios';import { randomBytes } from 'node:crypto';function stickyClient(minutes = 10) { const handle = randomBytes(4).toString('hex'); return axios.create({ timeout: 30_000, proxy: { protocol: 'http', host: 'proxy.arcproxies.io', port: 8000, auth: { username: `USERNAME_pool-arcfast_country-de_session-${handle}_sesstime-${minutes}`, password: 'PASSWORD', }, }, });}const client = stickyClient();for (let page = 1; page <= 3; page++) { const { status } = await client.get('https://example.com/search', { params: { q: 'lamp', page } }); console.log(page, status);} - 05
Geo-target per request
Country and city are username tokens, so a per-request
proxywith a different username switches market. Cities come from the published list, lowercased without spaces.geo.mjs13 linesconst MARKETS = { 'us-chicago': 'USERNAME_pool-arcfast_country-us_city-chicago', 'br': 'USERNAME_pool-arcfast_country-br', 'de': 'USERNAME_pool-arcfast_country-de',};for (const [market, username] of Object.entries(MARKETS)) { const { status } = await axios.get('https://example.com/pricing', { proxy: { protocol: 'http', host: 'proxy.arcproxies.io', port: 8000, auth: { username, password: 'PASSWORD' } }, timeout: 30_000, }); console.log(market, status);} - 06
Retry the right errors
Stop on 407. Retry 429, 5xx and timeouts with backoff, each attempt on a new handle so a bad exit is not reused.
fetch.mjs24 linesimport axios from 'axios';import { randomBytes } from 'node:crypto';import { setTimeout as sleep } from 'node:timers/promises';async function fetchWithRetry(url, attempts = 4) { for (let attempt = 0; attempt < attempts; attempt++) { const username = `USERNAME_pool-arcfast_country-de_session-${randomBytes(4).toString('hex')}_sesstime-5`; try { return await axios.get(url, { proxy: { protocol: 'http', host: 'proxy.arcproxies.io', port: 8000, auth: { username, password: 'PASSWORD' } }, timeout: 30_000, }); } catch (err) { if (!axios.isAxiosError(err)) throw err; const status = err.response?.status; if (status === 407) throw new Error('proxy rejected the credentials'); const retryable = status === 429 || status >= 500 || ['ECONNABORTED', 'ETIMEDOUT', 'ECONNRESET'].includes(err.code); if (!retryable) throw err; await sleep(1000 * 2 ** attempt); } } throw new Error(`gave up on ${url}`);}
Which Axios proxy setup for which version
| Axios version | HTTPS targets via `proxy` option | Recommended setup |
|---|---|---|
| 1.16.1 and later | Tunnelled through CONNECT, TLS end to end | proxy: { protocol, host, port, auth } |
| Earlier 1.x and 0.x | Not tunnelled correctly | httpsAgent: new HttpsProxyAgent(url) plus proxy: false |
| Any, with SOCKS5 | Not applicable | httpAgent/httpsAgent: new SocksProxyAgent('socks5h://…') plus proxy: false |
Axios' own docs now state that for https:// targets it "establishes a CONNECT tunnel through the proxy and performs TLS end-to-end with the origin", sends Proxy-Authorization only on the CONNECT request, and leaves tunnelling to an HttpsProxyAgent if you supply one. The 1.16.1 release notes record the fix for HTTPS data reaching an HTTP proxy in cleartext under some configurations, a good reason to upgrade rather than work around it.
Rotating vs sticky with Axios
A rotating username lets each new connection take a new exit. Node's agents keep connections alive, and an HTTPS request runs in a CONNECT tunnel that stays on one exit, so consecutive requests may share an IP. Use a fresh _session- handle when you need a new IP, and a fixed one when you need to keep it; rotating vs sticky sessions has the decision guide.
SOCKS5 with Axios
Axios has no SOCKS support of its own. socks-proxy-agent provides it: create new SocksProxyAgent('socks5h://{{USER}}:{{PASS}}@{{GATEWAY}}'), pass it as both httpAgent and httpsAgent, and set proxy: false. socks5h resolves hostnames at the gateway. Same port and credentials as HTTP; see SOCKS5 for when it is worth it.
The problem
Common pitfalls
Environment variables winning silently
Axios reads http_proxy and https_proxy by default. If your code sets httpsAgent without proxy: false, a stray variable can still interfere.
Expecting proxy to work in the browser
The proxy option is Node-only. Browser code goes through the browser's own network stack and proxy settings.
Credentials in host
host is just the hostname. Credentials belong in auth, port in port as a number.
Retrying 407
A generic "retry on any error" interceptor will hammer the gateway with bad credentials. Exclude 407 explicitly.
FAQ
Questions
Something not covered? Write to contact@arcproxies.io.
How do I use a proxy with authentication in Axios?
Pass proxy: { protocol: 'http', host, port, auth: { username, password } } in the request config or in axios.create(). On Axios 1.16.1 and later this works for HTTPS targets too.
Why do HTTPS requests through a proxy fail with older Axios?
Before 1.16.1, Axios' proxy option did not tunnel HTTPS targets the way most proxies expect. Upgrade, or use httpsAgent: new HttpsProxyAgent('http://user:pass@host:port') together with proxy: false.
Does Axios support SOCKS5 proxies?
Not directly. Use socks-proxy-agent: pass new SocksProxyAgent('socks5h://user:pass@host:port') as httpAgent and httpsAgent, and set proxy: false.
How do I get a new IP for each Axios request?
Give each request its own _session- handle in the proxy username. Without one, rotation happens per new connection, and kept-alive connections can reuse the same exit.
Sources & review
Last reviewed by the ARC Proxies team. Prices are read from the live catalog at build time.
- [1]Axios: Request config: proxy
- [2]axios/axios: Release v1.16.1
- [3]GitHub, TooTallNate/proxy-agents: https-proxy-agent README
- [4]GitHub, TooTallNate/proxy-agents: socks-proxy-agent README
Next
What people build with it
Integrations
Other http clients
Get started
Get credentials and paste them in.
Sign up, buy a gigabyte, generate a username in the dashboard. Code WELCOME15 takes 15% off your first purchase; bandwidth never expires.