Skip to content

How to Calculate Proxy Traffic from API Responses in Data Collection Jobs

Proxy traffic is measured in bytes, not requests. This guide shows how to measure API responses, add overhead and retries, and build a realistic traffic estimate.

9 min readUpdated Nov 14, 2026By XPASS Editorial Team

How to Calculate Proxy Traffic from API Responses in Data Collection Jobs

When people plan a data collection job that runs through a proxy, the first number they usually think about is the request count. That is understandable, because request counts are easy to see in a log. But traffic is typically billed and limited in bytes, and the number of bytes per request can vary enormously between one API endpoint and another. A job that makes ten thousand small calls can use less traffic than a job that makes five hundred calls to an endpoint returning large documents. If you want a budget you can trust, you need to calculate traffic from the actual API responses, not from a guess based on request counts.

This guide walks through a practical method. You will learn what counts as traffic, how to measure response size in your own code, how to add headers and retries, how to run a small pilot, and how to turn the result into a monthly estimate. The method works for any HTTP-based API and does not depend on a particular programming language. Throughout, we assume you are collecting publicly available data lawfully, respecting the terms of the target site and applicable local law.

What counts as traffic

When you send a request through a proxy, several pieces of data cross the connection. The exact accounting depends on the provider, so always read the plan page of the service you use. In general terms, the following items can contribute:

  • The request line and request headers that your client sends, including cookies and authorization headers.
  • The request body, if you send one (for example a JSON payload in a POST).
  • The response headers returned by the server.
  • The response body, which is usually the largest part.
  • Connection overhead, such as the TLS handshake for HTTPS and the CONNECT request used to open a tunnel through an HTTP proxy.

HTTP semantics are defined in RFC 9110, and the way a client asks a proxy to open a tunnel is described in the MDN article on proxy servers and tunneling. You do not need to memorize either, but it helps to know that an HTTPS request through an HTTP proxy is not just "one request": the tunnel setup and the encrypted exchange all move bytes through the proxy.

Because the body dominates, most of your estimate will come from response size. The rest can be handled with a margin, which we will discuss below.

Measure the response size in your code

The most reliable way to learn how large a response is, is to measure it where you receive it. Most HTTP libraries expose enough information to do this in a few lines.

  1. Read the Content-Length header when it is present. It tells you the size of the body as sent on the wire (after any compression), but many servers omit it when they use chunked transfer.
  2. Measure the length of the raw bytes you actually received. This is the size of the body before your code parses it.
  3. If your library automatically decompresses gzip or brotli content, remember that the decoded length is larger than the bytes that crossed the network. Some libraries let you read the raw stream; others give you only the decoded text.
  4. Record the size of the headers too. A simple approach is to add up the length of each header name and value plus a few bytes of separators.

Write the measurements into a log line or a small table: URL pattern, status code, body bytes, header bytes, and whether the response was compressed. After a few dozen calls you will already see a pattern, such as one endpoint that returns a small object and another that returns a long list.

A good habit is to group results by endpoint, not by individual URL. Endpoints that return a list usually have a large variance, because the number of items changes. For these, record both the average and the largest size you see.

Add headers, handshakes and overhead

Body size alone understates real traffic. To keep the estimate honest, add an overhead allowance. There is no single correct percentage, because it depends on how many cookies you send, how many headers the server returns, and whether you reuse connections. Instead of inventing a universal number, measure your own case:

  • Compare the total bytes you measure at the application layer with any usage figure your provider's dashboard shows after a pilot. The gap between the two is your overhead for that workload.
  • If you cannot see provider-side usage yet, start with a conservative margin and tighten it after you collect real data.
  • Reusing connections (keep-alive) reduces handshake overhead per request. Opening a new connection for every call increases it.

For small responses, overhead is a large share of the total. For a response that is only a few hundred bytes, headers and handshakes can be a meaningful part of the cost. For large JSON documents, the overhead is a small share and the body dominates.

Account for retries, redirects and errors

Retries are the part of traffic planning that people forget most often. Every retry sends the request again and usually downloads another response, even if that response is an error page. Redirects work the same way: a request that is redirected twice before reaching the final resource moves three sets of headers through the proxy.

Collect these numbers in your pilot:

  • The share of requests that return a non-success status code.
  • The average number of attempts per successful result.
  • The average size of an error response, which is often smaller than a success response but not zero.
  • The number of redirects per request on each endpoint.

Then compute an effective multiplier. If your pilot shows that, on average, each useful record needs 1.2 attempts, multiply your baseline by 1.2. The figure here is only an illustration; your own pilot will give your own number.

It also pays to design retries carefully. Use exponential backoff, cap the number of attempts, and stop retrying on responses that will never succeed, such as a not-found status. This keeps both your traffic and the load on the target service under control. If your job runs inside short-lived functions, the article on using a proxy with serverless functions without timeouts explains how timeouts and retries interact.

Run a small pilot

Before you estimate anything, run a pilot. The pilot should be small enough to stay light on traffic but large enough to show a pattern. A few dozen requests per endpoint is a reasonable starting point for a first look; a few hundred gives a steadier average if the endpoint is variable.

Follow these steps:

  1. List the endpoints your job will call and how many times each one will be called per run.
  2. For each endpoint, send a pilot batch through the same proxy configuration you plan to use in production.
  3. Log body bytes, header bytes, status code, number of attempts and whether compression was used.
  4. Compute the average and the 90th percentile response size per endpoint.
  5. Compare the total you measured with the usage shown in your provider's dashboard, if available.
  6. Save the pilot results in a file so you can compare them after the API changes.

Respect the target's rules while you do this. Check its terms of use and its robots.txt file (the Robots Exclusion Protocol is described in RFC 9309), keep your request rate polite, and prefer an official API over scraping HTML whenever one exists.

Turn measurements into a traffic estimate

Once you have per-endpoint averages, the arithmetic is simple. Here is a plain example with invented numbers, only to show the method.

Suppose a job calls two endpoints each day:

Item Endpoint A (product list) Endpoint B (product detail)
Calls per run 200 2,000
Average body size 60 KB 8 KB
Average header size 2 KB 2 KB
Attempts per success 1.1 1.3

Endpoint A: 200 calls x 62 KB x 1.1 = about 13,640 KB per run. Endpoint B: 2,000 calls x 10 KB x 1.3 = 26,000 KB per run.

The total is roughly 39,640 KB, or just under 40 MB per run. Add a safety margin for handshakes and unexpected growth, for example another 15 to 25 percent, and you get a planning figure of roughly 46 to 50 MB per run. If you run daily, multiply by the number of days in the period to get a monthly estimate.

Notice what the table reveals. Endpoint B has ten times more calls, but because its responses are small, it contributes only about twice the traffic. If you needed to reduce usage, the first place to look would be the large product list responses, not the number of detail calls.

Ways to reduce traffic

After you know where the bytes go, you can reduce them without changing what you collect:

  • Ask only for the fields you need. Many APIs support field selection or smaller response profiles.
  • Use pagination parameters that match your needs instead of downloading the maximum page size.
  • Send an Accept-Encoding header so the server can compress responses, and confirm that your client handles it.
  • Use conditional requests with ETag or Last-Modified so that unchanged resources return a short not-modified response. These headers are defined in RFC 9110.
  • Cache results locally and avoid fetching the same resource twice within a short period.
  • Skip assets you do not need. If you are only collecting structured data, there is no reason to download images, scripts or style sheets.
  • Do not route calls through the proxy that do not need it, such as requests to your own services.

Keeping credentials out of your code also keeps your tooling tidy as it grows; the guide on managing proxy credentials with environment variables describes a clean way to do it.

Limits and what to watch for

Every estimate has limits, and it is better to know them in advance:

  • Response sizes change. A site that adds fields to its JSON or a longer list of items can double your traffic without any change in request count. Re-run your pilot periodically.
  • Pilot data may be unrepresentative. If you only test on a quiet endpoint or at an unusual time, the averages may be too optimistic.
  • Provider accounting can differ from your own. Providers may count bytes in both directions, include protocol overhead, or round usage. Compare your estimate with the dashboard rather than assuming they match.
  • Errors still use traffic. A burst of failures, such as a temporary outage on the target site, can inflate usage quickly if your retry logic is too aggressive.
  • Large downloads such as PDFs, images or archives can dwarf everything else. Treat them as a separate line in your budget.
  • Legal and policy limits apply regardless of traffic. Stay within the target site's terms and with applicable law, and do not attempt to bypass access controls or rate limits.

To avoid surprises, set up monitoring. A simple alert when usage reaches a threshold gives you time to react; the article on building a low proxy traffic alert system shows one way to do that.

A short checklist

Use this list before you start a new job:

  1. List every endpoint and the planned number of calls.
  2. Measure body size, header size and compression in a pilot.
  3. Measure retries, redirects and error rates.
  4. Compute per-endpoint traffic and add them up.
  5. Add a margin and compare with your plan's allowance on the product page.
  6. Set an alert and re-measure after any API change.

Summary

Proxy traffic follows bytes, not request counts. To estimate it properly, measure the real size of API responses in your code, add allowances for headers, handshakes, retries and redirects, run a small pilot, and turn the averages into a per-run and monthly figure with a safety margin. Then reduce waste with field selection, compression, conditional requests and caching, and keep watching the numbers because APIs change. To see how traffic is offered and metered, take a look at the proxy page and compare it with your own estimate.

Frequently asked questions

Is proxy traffic counted per request or per byte?

Traffic is usually measured in bytes transferred through the proxy, not in the number of requests. A request that returns a large JSON document uses far more traffic than a request that returns a short status message. Check your provider's plan page to see exactly how traffic is metered.

Do request headers and TLS handshakes count toward traffic?

In practice they add overhead on top of the response body. Headers, cookies and the connection setup all pass through the proxy, so a realistic estimate adds a margin to the body size you measure in your own code.

How do I estimate traffic before I run a full job?

Run a small pilot of a few dozen requests, record the average response size and the retry rate, then multiply by the planned number of requests and add a safety margin. Repeat the pilot whenever the API changes its response format.

Does compression change the numbers?

It can. If the server sends compressed responses, the bytes on the wire are smaller than the decoded body your code sees. Measure both the compressed and decoded sizes so you know which one your estimate is based on.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Need a proxy for this?

XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.

See proxy plans

Keep reading

Proxy Guides

Using a Proxy with Serverless Functions Without Timeouts

Serverless functions have strict time limits, and a proxy adds another hop. This guide explains how to plan time budgets, split jobs, retry safely and keep proxy calls inside the limit.

10 min read

Proxy Guides

How to Build an Alert System for When Proxy Traffic Runs Low

A proxy job that silently runs out of traffic fails at the worst moment. This guide shows how to track usage, set thresholds and send alerts that people act on.

9 min read

Proxy Guides

Managing Proxy Credentials with Environment Variables

Hardcoded proxy passwords end up in Git history, logs and screenshots. This guide shows a safer pattern using environment variables, with naming, loading, masking and rotation.

9 min read