Skip to content
Get Started
G2G2
4.7/5
Excellent
Trustpilot

How to use a proxy with Axios

Add a proxy object to the request or instance config: { protocol: "http", host: "HOST", port: PORT, auth: { username: "USERNAME", password: "PASSWORD" } }. From axios 1.16.1, https:// URLs go through a CONNECT tunnel automatically; for SOCKS5, set proxy: false and pass a socks-proxy-agent as httpAgent and httpsAgent.

  • Session Control
  • High Speed
  • Privacy First

What you need

Axios powers a lot of Node.js scrapers, API integrations and backend jobs. Its proxy option only works in Node.js (browsers ignore it), it also reads http_proxy and https_proxy from the environment, and its handling of https:// targets changed in 1.16.1, so the version you run decides which setup is right.

Your credential line

From the dashboard's proxy manager: host (or IP), port, username and password. Convert lists with the proxy list formatter.

Axios ready

  • Node.js with npm install axios (1.16.1 or later for the built-in HTTPS tunnel; run npm ls axios to check).
  • For SOCKS5: npm install socks-proxy-agent.

Which proxy fits Axios?

Both products use the same setup in Axios. What changes is how long an IP stays with you.

An ISP line is one dedicated US IP that stays yours all month, so an axios instance bound to one line always calls from the same address. Keep one instance per account or API key, and use the interceptor only for bulk work where any of your IPs will do.

starting from$0.75/IP

Dedicated static IPs registered to US and Canadian ISPs. The address stays the same for as long as you hold it, with unlimited bandwidth and HTTP(S) or SOCKS5 access.

A rotating line gives each new connection a fresh residential IP from the 50M+ pool, so consecutive calls usually leave from different addresses. Use a sticky line (5 to 60 minutes or 24 hours) for logins and multi-step flows that must keep one IP.

starting from$0.63/GB

Residential IPs in 190+ countries with country, state and city targeting. Rotate on every request or hold a sticky session for up to 90 minutes; GB never expire.

credentials

Your CleanProxies credentials

Every product connects over HTTP(S); static ISP and ISP subnet proxies also run SOCKS5 and IP whitelisting. This is what the dashboard gives you to paste into Axios.

Static ISP and ISP subnetHTTP(S)SOCKS5IP whitelist
IP:PORT:USER:PASS

One line per dedicated IP. With IP whitelisting on, the line is just IP:PORT and no password is sent.

Rotating residential and mobileHTTP(S)User:pass
HOST:PORT:USER:PASS

Generated in the proxy manager. The username carries the location and session you pick, so generate a new list to change them.

As a URL, for code and most toolshttp://USERNAME:PASSWORD@HOST:PORTsocks5://USERNAME:PASSWORD@HOST:PORT

Use http:// even for HTTPS websites; the TLS session still runs end to end. The socks5:// form is for static ISP and ISP subnet proxies.

How to set up CleanProxies in Axios

Four steps, then check the exit IP with the free proxy checker.

  1. 1

    Check your axios version

    Run npm ls axios. On anything older than 1.16.1, run npm install axios@latest before you send HTTPS traffic through a proxy.

  2. 2

    Build the proxy object

    Split your dashboard line into host, port, and auth.username / auth.password. Keep protocol: "http".

  3. 3

    Attach it to an instance

    Pass it to axios.create({ proxy }) so every request from that instance uses the same proxy.

  4. 4

    Check the exit IP

    Request https://api.ipify.org?format=json and log data.ip.

copy & paste

Axios proxy examples

Replace the highlighted placeholders with the values from your dashboard. Pick an example to see its code.

Axios + CleanProxies

Axios proxy config on an instance

axios.create with a proxyJavaScript
import axios from "axios";

const client = axios.create({
  proxy: {
    protocol: "http",
    host: "HOST",
    port: PORT,
    auth: { username: "USERNAME", password: "PASSWORD" },
  },
  timeout: 30_000,
});

const { data } = await client.get("https://api.ipify.org?format=json");
console.log("Exit IP:", data.ip);
  • proxy: false turns proxying off for a request or instance, environment variables included. Keep protocol: "http": https there means TLS to the proxy itself, not to the website. The proxy option belongs to the Node.js http adapter, so it's ignored if you switch to adapter: "fetch".
fix it fast

Troubleshooting Axios proxy errors

Verify your exit IP

The first example logs the exit IP: it should match your ISP line, or be a residential IP in the location you generated. Request https://httpbin.org/headers through the same instance to see the headers the website receives.

Open What is my IP? through the proxy to see the address and headers a website receives, or paste up to ten lines into the free proxy checker to test connectivity, latency and exit IP.

Still stuck? Our 24/7 support team answers fast: contact us with the error and the line you used (leave the password out).

Axios error fixes
  • AxiosError: Request failed with status code 407Why: Missing or wrong auth, or a password with special characters inside a proxy URL in an environment variable.Copy the line again and use the auth object; in URLs, percent-encode @ as %40 and : as %3A.
  • EPROTO or "wrong version number" on HTTPS requestsWhy: protocol: "https" pointed at an HTTP proxy port.Set protocol: "http". The website connection is still TLS end to end inside the tunnel.
  • The proxy is ignored in the browserWhy: The proxy option only exists in Node.js; browsers use the system or extension proxy.Run the request from Node.js (or your backend), or set the proxy in the browser itself.
  • Your real IP comes back with a SOCKS agentWhy: proxy: false is missing, so an https_proxy variable or the proxy option is used instead of the agent.Pass proxy: false together with httpAgent and httpsAgent.
  • HTTPS requests fail or reset on an older axiosWhy: Releases before 1.16.1 could send HTTPS requests to an HTTP proxy without a CONNECT tunnel.Upgrade to 1.16.1 or later, or use https-proxy-agent with proxy: false.

Axios proxy guides

Setup guides and best practices from the CleanProxies blog.

Get the latest insightsAll Blogs

More integrations

Setup guides for tools people run next to Axios.

All integrations

Axios proxy FAQs

Straight answers about running CleanProxies in Axios.

Yes, in Node.js. Set the proxy option with protocol, host, port and auth, or export http_proxy and https_proxy. In the browser, axios can't choose a proxy; the browser's own settings apply.

Got more questions?All FAQs