got proxy setup with hpagent agents
To use a got proxy, you configure an hpagent HttpProxyAgent or SocksProxyAgent with the gateway host, port, and your proxy user credentials. All targeting and session options are passed through the username string, following our specific grammar.
- Use hpagent's HttpProxyAgent for port 7070 and SocksProxyAgent for port 7071.
- Build the full username with options like net.res_cc.us_city.new-york.
- Verify the exit IP with a simple GET request to ipify.
- Handle 407 errors by checking the username and password format.
got proxy setup overview
Integrating RotatingProxy with the got HTTP client involves creating an agent from the hpagent package. This agent handles the connection to our gateway at gw.rotatingproxy.cc on either port 7070 (HTTP/HTTPS) or port 7071 (SOCKS5). The agent is then passed into got's request options. Your proxy authentication, desired network, geographic targeting, and session settings are all encoded into the username field of the proxy URL. This guide covers the exact code for current versions of got and hpagent, common pitfalls, and strategies for running at scale in projects like web scraping or price monitoring.
Installing got and hpagent
First, ensure you have both packages installed in your Node.js project. Hpagent is the recommended agent library for got as it supports both HTTP and SOCKS5 proxies with authentication. Run npm install got hpagent to get the latest versions. Check the current docs if you encounter compatibility issues, as minor version updates can sometimes change agent initialization. For a comparison of proxy types you might use with got, see our guide on rotating vs static proxies.
Building the proxy username string
The username is your proxy user's login, followed by underscores and key.value options. You create proxy users in your dashboard, as explained in how to create a proxy user. For example, to use the residential network in the United States, your username might be USERNAME_net.res_cc.us. You can add US state targeting with st.ca, city targeting with a token like city.chicago, and session control with sid.abc123 and ttl.30. Use our proxy URL builder tool to generate these strings correctly. Use the password you created for that particular proxy user.
HTTP and HTTPS setup on port 7070
For HTTP and HTTPS traffic (using the CONNECT method), you will use port 7070 with the HttpProxyAgent from hpagent. Construct the proxy URL with the http:// scheme, your formatted username, password, host, and port. Then create the agent and pass it to got. Here is a complete example targeting German residential IPs:
const got = require('got');
const { HttpProxyAgent } = require('hpagent');
const proxyAgent = new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
proxy: 'http://USERNAME_net.res_cc.de:PASSWORD@gw.rotatingproxy.cc:7070'
});
(async () => {
try {
const response = await got('https://httpbin.org/ip', {
agent: {
http: proxyAgent,
https: proxyAgent
}
});
console.log('Response:', response.body);
} catch (error) {
console.error('Request failed:', error);
}
})();
The agent is set for both http and https keys in the got options. The keepAlive and socket settings help performance for multiple requests. This setup is ideal for accessing most websites, including Google search or Amazon.
SOCKS5 setup on port 7071
If your toolchain or target works better with SOCKS5, use port 7071 with the SocksProxyAgent. The setup is very similar, but note the different scheme in the proxy URL and the agent class. This example uses a sticky session on the mobile network in Japan:
const got = require('got');
const { SocksProxyAgent } = require('hpagent');
const proxyAgent = new SocksProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
proxy: 'socks://USERNAME_net.mob_cc.jp_sid.my9k3s_ttl.60:PASSWORD@gw.rotatingproxy.cc:7071'
});
(async () => {
try {
const response = await got('https://api.ipify.org?format=json', {
agent: {
http: proxyAgent,
https: proxyAgent
}
});
console.log('IP:', response.body);
} catch (error) {
console.error('Request failed:', error);
}
})();
The SOCKS5 agent also handles HTTPS traffic transparently. For a discussion on when to choose each port, read which port to use, 7070 or 7071.
Verifying the exit IP and location
After setting up the proxy, confirm it's working by checking the IP address that the target site sees. Simple services like https://api.ipify.org or https://ipinfo.io/json are perfect for this. Run a GET request through your proxy configuration and log the response body. The returned IP should match the country or city you targeted. If the IP shown is yours, the proxy connection is not active. If the location is wrong, double-check the country code and city token in your username. Our checking the exit IP and location guide has more details.
Common errors and fixes
A 407 Proxy Authentication Required error means the gateway rejected your login details. Verify your proxy user is active (not paused), the login and password are correct, and the username string is properly formatted with no typos. Ensure the password is URL-encoded if it contains special characters. For more, see proxy error 407 authentication required.
Timeouts or slow responses can occur due to network latency or the exit node's performance. Increase got's default timeout options (timeout.request, timeout.connect). Implement a retry strategy with exponential backoff.
TLS/SSL errors sometimes happen if the agent configuration interferes with HTTPS negotiation. Using the correct agent for the port (HttpProxyAgent for 7070, SocksProxyAgent for 7071) is crucial. You can try setting rejectUnauthorized: false in got's https options for debugging, but do not use this in production.
Targeting countries, states, and cities
Geo-targeting is specified entirely within the username. Use cc.us for the United States, cc.de for Germany, and so on. For US states, add st.ca for California or st.ny for New York. City targeting uses lowercase tokens with hyphens for spaces, like city.los-angeles or city.new-york. This precision is valuable for localization testing and real estate data collection.
Using sticky sessions for login flows
To maintain the same IP across multiple requests, essential for tasks like managing social media accounts or checking logged-in content, use a session ID. Append sid.abc123 to your username, where the ID is 6 to 16 alphanumeric characters. You can also set a custom time-to-live with ttl.45 (1 to 120 minutes). The IP will stick for that session duration. For example, proxies for social media management often require sticky sessions.
Tips for running at scale
When making thousands of requests, efficiency matters. Reuse agent instances across requests to benefit from connection keep-alive. Configure the maxSockets and maxFreeSockets appropriately for your concurrency needs. Implement a solid retry logic for transient network or proxy errors. Distribute traffic across multiple proxy users (you can have up to 25) to isolate issues and apply individual monthly GB caps. Monitor your usage and costs with our dashboard; understand how monthly volume rates are applied to keep costs predictable. For large-scale scraping, review planning concurrency for crawlers.
Switching between proxy networks
You can switch networks on the fly by changing the net. option in the username. Use net.res for residential, net.mob for mobile, net.dc for datacenter, and net.isp for ISP proxies. Each has different characteristics, costs, and country coverage. For instance, mobile proxies (87 countries) are excellent for mobile app testing, while datacenter proxies (16 countries) offer speed for financial data collection. Compare them in our guide on residential vs datacenter rotating proxies.
Related integrations and next steps
If you are building a larger scraping system, you might also use Puppeteer proxy or Playwright Node.js proxy for browser automation. For simpler HTTP tasks, the axios proxy setup is similar. Always ensure your activities comply with our acceptable use policy. To get started, you'll need to top up your balance with at least $40. Then, create a proxy user, build your username, and start coding with the examples above.
Questions
Can I use the 'got' proxy with TypeScript?
Yes, the setup is identical. Install the type definitions for got and hpagent if available, or use the libraries with TypeScript's standard type inference. The agent configuration objects are plain JavaScript objects.
Why is my got request ignoring the proxy agent?
This happens if the agent is not correctly attached to the request options. Ensure you are passing the agent object as `agent: { http: proxyAgent, https: proxyAgent }` and not overwriting it elsewhere in your got configuration. Also, verify you are not using a tunnel agent for HTTPS incorrectly.
How can I get a new IP for each request using got?
Simply omit the `sid` option from your username. Each new gateway connection will get a different IP from your selected network and area. For advanced rotation patterns, you can programmatically generate new username strings for each request or batch of requests.
My target site returns a 403 through the proxy. What can I do?
A 403 indicates the target site is blocking the proxy IP. This is common on heavily protected sites. Try switching to a different network (e.g., from datacenter to residential), adding realistic headers (User-Agent, Accept-Language), and introducing delays between requests. Read our guide on how to avoid getting blocked.
Does the hpagent SOCKS5 agent support UDP?
No, and neither does our gateway. The SOCKS5 proxy on port 7071 supports TCP traffic only. UDP proxying is not available.
How can I see how much traffic my got requests are using?
Check the "Usage" section in your dashboard. It shows consumption per network per day. You can also use the REST API to programmatically fetch usage data. Traffic is metered as upload plus download bytes through the gateway.
Start with one top-up, use any network
Create an account in a minute, add $40 or more, and the same balance pays for residential, mobile, datacenter and ISP traffic.