How and why to use proxies to work with any APIs?

api

In this article we will consider how to use proxies to work with API. We will show how to add a proxy to the code to, for example, change geolocation.

Bots generated 53% of web traffic in 2025 and 27% of bot attacks were aimed at APIs, according to IT Brief's summary of the Thales 2026 Bad Bot Report. Akamai's 2026 State of the Internet report counted 113% more daily API attacks than a year earlier. That is why API providers rely on rate limits and IP allowlists. The address your requests come from, and how steadily you send them, now decide whether an integration keeps working.

What are APIs and why do you need them?

An API (application programming interface) is like a menu in a restaurant. Instead of cooking yourself, you choose from the menu and the chefs (or APIs) do all the work.

APIs allow programs to share data and functions. For example, an online store can process payments through APIs without needing a deep understanding of how payment systems work.

 

Why use proxies to work with APIs?

Proxies help in several ways:

  • Preserving anonymity. Proxies hide your IP address, which protects your personal information and allows you to change geolocation.
  • Working within limits. Some APIs limit the number of requests from a single IP or key. A proxy gives your code one stable exit address, and the limit itself is respected by pacing: when the API answers 429, wait for the time in its Retry-After header, as RFC 6585 describes. Spreading requests across addresses to get past a limit is not the answer: it can violate the provider's terms of use.
  • A fixed address for allowlists. Some APIs trust a key only when it arrives from a registered IP address. Binance.US, for example, resets API keys to read-only after 90 days without use unless they are secured by IP whitelisting, according to its Help Center page on API key safety, dated June 3, 2026. A dedicated proxy gives a laptop, a CI runner or a cloud function one static IP to register.

Steps for working with APIs and proxies

API selection and code preparation

In our example, let's take an API for real-time parsing of product data from Amazon. We took it from this library of different APIs. The site is useful; you can find APIs for any task here. Many of them are available for free.

api

How to add a proxy to the code

We will use Python and the requests library.

A proxy slows down only the opening of a connection: every request after the first one costs a single round trip on any route. The counts in the table follow from the protocols themselves (TLS 1.3, CONNECT, SOCKS5, username and password authentication) and match what we measured on a test bench in October 2026 with curl 8.5.0, requests 2.34.2, httpx 0.28.1 and Go 1.24.7. To keep the cost low, reuse connections with requests.Session() and choose a proxy near your server or near the API.

Network round trips for the first HTTPS request over TLS 1.3. The last column is calculated from the round-trip counts.

Route

Round trips to the first response on a new connection

Time on the client-to-proxy leg at 30 ms RTT

Direct, no proxy

3

not applicable

HTTP proxy (CONNECT)

4

120 ms

SOCKS5, no password

5

150 ms

SOCKS5, login and password

6

180 ms

How to write proxy data in code?

Here is how to write proxy data in code:

Proxy format

We write proxies in the format:

IP:port:login:password

For example:

181.214.117.124:3686:user94438:nyp6os.

Adding a proxy to the code

In the code, you need to add a list of proxies and a function to convert the data into a format that the requests library understands. Here are the steps to do it:

Create a list of proxies

First, create a proxy list in the following format

IP:port:login:password

For example:

proxy_list = [

    "181.214.117.124:3686:user94438:nyp6os",

    "109.196.175.126:4800:user94438:nyp6os"

]

Create a function for proxy conversion

Create a function get_proxy_dict that converts a proxy string into a dictionary suitable for use with requests. Function example:

def get_proxy_dict(proxy):

        ip, port, user, password = proxy.split(':')

    proxy_url = f"http://{user}:{password}@{ip}:{port}"

    return {

        "http": proxy_url,

        "https": proxy_url

    }

This function takes a proxy string, parses it into components, and returns a dictionary that the requests library can use to send requests through the proxy.

Both keys must use an http:// proxy URL, including the https key. The key names the scheme of the API address, and the value says how to reach the proxy. With https:// in the value, requests tries to open TLS to the proxy itself. With requests 2.34.2 and an ordinary HTTP proxy, that call fails with ProxyError: Your proxy appears to only use HTTP and not HTTPS, an error explained in the urllib3 documentation. With http:// the same call returns 200. The scheme describes only the hop to the proxy, and the request to the API is still HTTPS.

Using proxies in requests

In the main code to send requests using proxies, you need to define the URL, request parameters, and headers. The proxies are applied to each request. In a loop, use the get_proxy_dict function to get the correct format for the proxy:

for _ in range(len(proxy_list)):

        proxy = next(proxy_cycle)

        proxies = get_proxy_dict(proxy)

 

        try:

            response = requests.get(url, headers=headers, params=querystring,

                        proxies=proxies, timeout=(5, 15))

            print(response.json())

            break

        except requests.RequestException as e:

            print(f"Proxy {proxy} failed: {e}")

Here proxy_cycle is used to loop through the proxies. get_proxy_dict(proxy) converts the proxy string into a format that can be passed to the proxies parameter of the requests.get function.

The loop moves to the next proxy when a request fails, and the timeout argument makes sure a failure is noticed: Requests does not time out unless you set a timeout. Both matter because every link fails sometimes. OpenAI's services ran at about 99.76% uptime between October 2025 and February 2026, against roughly 99.99% for Stripe, according to an analysis of more than 215 status pages by Shibley Burnett, founder of API Status Check, published by Nordic APIs in March 2026. That is 21 hours of downtime a year versus less than one.

Here is a simplified code with our API and added proxies:

import requests

from itertools import cycle

 

# Proxies in the format IP:port:login:password

proxy_list = [

    "181.214.117.124:3686:user94438:nyp6os",

    "109.196.175.126:4800:user94438:nyp6os"

]

def get_proxy_dict(proxy):

        ip, port, user, password = proxy.split(':')

    proxy_url = f"http://{user}:{password}@{ip}:{port}"

    return {

        "http": proxy_url,

        "https": proxy_url

    }

proxy_cycle = cycle(proxy_list)

url = "https://real-time-amazon-data.p.rapidapi.com/search"

querystring = {"query":"Phone","page":"1","country":"US","sort_by":"RELEVANCE","product_condition":"ALL","brand":"Apple"}

headers = {

        "x-rapidapi-key": "YOUR_API_KEY",

        "x-rapidapi-host": "real-time-amazon-data.p.rapidapi.com"

}

for _ in range(len(proxy_list)):

        proxy = next(proxy_cycle)

        proxies = get_proxy_dict(proxy)

        try:

            response = requests.get(url, headers=headers, params=querystring,

                        proxies=proxies, timeout=(5, 15))

            print(response.json())

            break

        except requests.RequestException as e:

            print(f"Proxy {proxy} failed: {e}")

Here, instead of “YOUR_API_KEY” you should insert the API key (token).

Code launch

  1. Install the requests library using the pip install requests command.

    Code launch

  2. Place the code in a text file with a .py extension (e.g., parser.py).

    code

  3. Open a command prompt, navigate to the directory with the file, and run the command:

    python filename

    phyton

  4. After executing the code, get the data. You may need to filter out unnecessary information. However, this is a topic for another article.

Now you know how to add proxy data to your code. Following this algorithm, you will be able to configure a proxy to work with any API or personally written program.

PROXYS.IO issues each individual IPv4 proxy to one customer, so the address you register in an API allowlist is not shared with other users. Prices start at $1.47 per address per month, and the same proxy supports HTTPS, HTTP and SOCKS. Locations include the United States, Great Britain, Germany, Poland and the Netherlands. Shared IPv4 addresses, used by up to three customers, start at $0.67, and individual IPv6 addresses at $0.13 for APIs that accept IPv6.