How much bandwidth does a page cost? Budgeting residential proxies
Assumed page weights, how to measure yours, what to block in a headless browser, conditional requests, and what 1,000 or 100,000 pages cost at the live price.
The usage and proxy detail endpoints, a Python script that polls remaining_gb and tops up below a threshold, how often to poll, and what a top-up costs.
A residential plan on GhostConnect has no expiry date and nothing to renew, so the only way it fails is a script still running when the last megabyte goes. The fix is to see that coming. The API gives you two views of the same plan, one cheap and slightly stale, one live with a usage series behind it.
GET /proxies/residential/{id} returns the proxy as {"proxy": ...}: host, port_http, port_socks5, username, password, allowlist, an expires_at of null, and a bandwidth object with total_gb, used_gb and remaining_gb, all in gigabytes to three decimals. Next to it is synced_at, in Unix seconds: the moment that figure was last read from the network. The call itself does not go to the network; it hands you the stored figure and tells you how old it is. That is fine for a page you glance at and wrong for a script that is about to spend money on the strength of it.
GET /proxies/residential/{id}/usage is the live one. Every call reads the plan from the network, so the bandwidth object it returns is current, synced_at is seconds old, and the usage series the dashboard graphs comes with it. It is not a paying call: it does not count against the paying limit and takes no Idempotency-Key. When the network cannot be read at that moment the answer is 502 usage_unavailable, with a message saying the proxy itself is unaffected; a monitor should treat that as "skip this round", never as an empty plan. Asking for usage on a datacenter, ISP or rotating proxy gets 400 not_supported, because those are paid by time, not by traffic, and an id the key cannot see gets 404 not_found.
curl -H "Authorization: Bearer $GT_KEY" "https://ghostconnect.com/api/v1/proxies/residential/obcl4126/usage?window=24h"
{
"ok": true,
"data": {
"proxy_id": "obcl4126", "window": "24h", "bucket_hours": 1,
"from": 1795518000, "to": 1795604400,
"points": [
{ "at": 1795518000, "used_gb": 0.412 },
{ "at": 1795521600, "used_gb": 0.388 },
"...24 points, the last one still filling"
],
"total_gb": 8.13, "peak_gb": 0.463,
"bandwidth": { "total_gb": 10, "used_gb": 8.13, "remaining_gb": 1.87 },
"synced_at": 1795601430
}
}
One query parameter, window: 24h (the default), 7d or 30d; anything else is 400 invalid_window. The window sets the bucket size and the point count. 24h gives 24 hourly points with bucket_hours of 1; 7d gives 84 two-hour points with bucket_hours of 2; 30d gives 30 daily points with bucket_hours of 24. Each point is {"at": ..., "used_gb": ...}, where at is the bucket's start in Unix seconds, UTC, and used_gb is the data used inside that bucket, to three decimals. Usage is summed into a bucket, never sampled, so a two-hour point is the sum of its two hours. from is the first bucket's start, to the last bucket's end, total_gb the sum of the points and peak_gb the largest one. The same thirty days of hourly figures sit behind the three graphs on the plan's dashboard page; the privacy page notes that bandwidth history is deleted after 90 days.
The last point is the current bucket, and it is still filling. A monitor that computes a rate from it will see an hour that looks quiet at five past and busy at five to; use the complete buckets before it. Metering is on the data you receive, as the plan's page says, so the series moves with response sizes rather than request counts, and a day of large pages shows up long before a day of many small ones.
The question a monitor answers is "how long until zero at this pace", and the series gives both halves. Take the last few complete buckets, sum their used_gb, divide by the hours they cover, and you have gigabytes per hour; divide remaining_gb by that and you have hours left. The script below uses six complete hours from the 24h window, long enough to flatten a quiet hour and short enough to notice a job that just started. For a crawler that runs in bursts, the 7d window and its two-hour buckets give a steadier figure at the cost of noticing a change later.
For a worked example, assume a scraper that pulls 0.4 GB an hour (a figure for the arithmetic, not a measurement). A 10 GB plan, bought for $29.90, lasts 25 hours at that pace and costs $1.20 an hour, or $28.70 for a 9.6 GB day. A threshold of 2 GB gives 5 hours of warning, and a 10 GB top-up buys another 25 hours for the same $29.90. Change the rate and every other figure moves with it, which is why the script computes them each round rather than you computing them once.
The limit is 120 requests a minute per key, of which 30 may be paying requests, and a usage call is not a paying one. Past the limit the answer is 429 rate_limited with a Retry-After header in seconds, which the script honours. In practice the data decides the interval. The series is hourly, so the shape of the graph does not change between two calls a minute apart; only remaining_gb does, and it only has to be fresh enough that the threshold is noticed before the plan empties. At 0.4 GB an hour, a five-minute poll lets at most 0.033 GB slip past the threshold before the next check, a rounding error against a 2 GB margin. Every five or ten minutes is a sensible cadence for one plan; ten plans every five minutes is two calls a minute, still nowhere near the limit. Polling every few seconds costs nothing in money and gains nothing in information.
Pick the threshold from the lead time you want, not from a round number: hours of warning times the burn rate, plus a margin for the hour the current bucket is hiding. If the balance might be short, make the margin bigger, because the fix then involves a payment on the website, which takes longer than an API call.
Residential pricing is a straight line: $2.99 per gigabyte, whatever the size of the order or the top-up. The price function on our side is price times gigabytes, rounded to the cent, and POST /quote with kind topup_residential, the proxy id and gb returns exactly that as amount_usd, with a lines object showing what is added and what remains now, your balance_usd and a balance_covers boolean. Two top-ups of 5 GB ($14.95 each, $29.90 together) cost the same as one of 10 GB ($29.90); 25 GB is $74.75. There is no discount for volume and no penalty for small, frequent top-ups, so size them to your cash flow. Bandwidth never expires, so the only cost of buying too much is money sitting on a plan instead of on your balance. The largest single top-up is 1,000 GB, $2,990.00.
The top-up itself is POST /proxies/residential/{id}/topup with gb from 1 to 1,000. It pays from the balance at the moment of the call and answers 200 with the invoice, the updated proxy, whose bandwidth.remaining_gb already includes the new gigabytes, and balance_usd. If the balance is short it answers 402 insufficient_balance with amount_usd and balance_usd inside the error, and nothing is charged. Funding is a website step, crypto or card, with a deposit between $5.00 and $5,000.00; the API walkthrough covers the balance model and the Idempotency-Key in detail. Do not reach for POST /orders here: with type residential it creates a second plan with its own credentials, which is not what a running script wants.
curl -X POST -H "Authorization: Bearer $GT_KEY" -H "Content-Type: application/json" \
-d '{"kind":"topup_residential","id":"obcl4126","gb":10}' https://ghostconnect.com/api/v1/quote
curl -X POST -H "Authorization: Bearer $GT_KEY" -H "Idempotency-Key: topup-obcl4126-7f3a9c2e1b" \
-H "Content-Type: application/json" -d '{"gb":10}' \
https://ghostconnect.com/api/v1/proxies/residential/obcl4126/topup
{
"ok": true,
"data": {
"kind": "topup_residential",
"description": "Residential top-up, 10 GB",
"amount_usd": "29.90",
"lines": { "Adds": "10 GB", "Remaining now": "1.87 GB" },
"balance_usd": "61.40",
"balance_covers": true
}
}
Everything above in sixty lines of Python with requests. It polls the usage endpoint, prints the remaining gigabytes, the burn rate and the hours left, and when the remaining figure drops under the threshold it quotes a top-up, checks that the balance covers it, and buys it with one Idempotency-Key that is kept through every retry of that purchase. The key is in the GT_KEY environment variable; the proxy id, threshold, top-up size and interval are at the top.
import os, time, uuid
import requests
BASE = "https://ghostconnect.com/api/v1"
PROXY_ID = "obcl4126"
THRESHOLD_GB = 2.0 # top up when less than this is left
TOPUP_GB = 10 # how much to add each time
POLL_SECONDS = 300 # five minutes
s = requests.Session()
s.headers["Authorization"] = "Bearer " + os.environ["GT_KEY"]
def usage(window="24h"):
r = s.get(BASE + "/proxies/residential/" + PROXY_ID + "/usage", params={"window": window}, timeout=30)
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "60")))
return None
if r.status_code == 502: # usage_unavailable: the proxy works, the figures do not; skip this round
return None
r.raise_for_status()
return r.json()["data"]
def burn_rate(data):
complete = data["points"][:-1] # the last bucket is still filling
recent = complete[-6:]
hours = len(recent) * data["bucket_hours"]
return sum(p["used_gb"] for p in recent) / hours if hours else 0.0
def top_up(gb):
q = s.post(BASE + "/quote", json={"kind": "topup_residential", "id": PROXY_ID, "gb": gb}, timeout=30).json()
if not q["ok"]:
print("quote refused:", q["error"]["code"], q["error"]["message"])
return False
if not q["data"]["balance_covers"]:
print("balance", q["data"]["balance_usd"], "does not cover", q["data"]["amount_usd"], "- add funds")
return False
key = "topup-" + PROXY_ID + "-" + uuid.uuid4().hex # one key per purchase, kept across retries
for attempt in range(5):
try:
r = s.post(BASE + "/proxies/residential/" + PROXY_ID + "/topup", json={"gb": gb},
headers={"Idempotency-Key": key}, timeout=60)
except requests.exceptions.RequestException:
time.sleep(2 ** attempt)
continue
if r.status_code in (409, 429): # first attempt still running, or rate limited
time.sleep(int(r.headers.get("Retry-After", str(2 ** attempt))))
continue
body = r.json()
if r.status_code == 200:
print("topped up:", body["data"]["proxy"]["bandwidth"]["remaining_gb"], "GB left, balance", body["data"]["balance_usd"])
return True
print("top-up failed:", body["error"]["code"], body["error"]["message"])
return False
print("no answer after retries: read GET /invoices before trying again")
return False
while True:
data = usage()
if data is not None:
left = data["bandwidth"]["remaining_gb"]
rate = burn_rate(data)
hours = left / rate if rate else float("inf")
print(time.strftime("%Y-%m-%d %H:%M"), "left", left, "GB, rate", round(rate, 3), "GB/h, about", round(hours, 1), "h")
if left < THRESHOLD_GB:
top_up(TOPUP_GB)
time.sleep(POLL_SECONDS)
The script quotes first because that is the only way to learn balance_covers before committing, and a refused quote (400 invalid_order, for a gb outside 1 to 1,000) costs nothing. The top-up response carries the updated proxy, so the "topped up" line prints the new remaining figure without another call, and the next poll confirms it from the network. If the balance is short the script says so and keeps polling; the plan keeps serving until it hits zero, and the message is your cue to add funds.
GET /proxies/residential/{id} returns the stored figure with its synced_at. Decide on the usage endpoint's bandwidth, which is read live.gb is refused with 422 idempotency_key_reused. Decide the amount, then retry it unchanged.502 usage_unavailable as zero. It means the figures could not be read, not that the plan is empty. Skip the round.The same loop extends to several plans by iterating over GET /proxies?type=residential. For the dashboard you need nothing extra: the plan's page shows the same remaining figure, the same three graphs and the same top-up form with the preset sizes. Residential bandwidth is $2.99 per GB on the product page, bought with a key and a balance, and the endpoints above are documented field by field in the API reference.
Assumed page weights, how to measure yours, what to block in a headless browser, conditional requests, and what 1,000 or 100,000 pages cost at the live price.
Copy-paste proxy settings for curl, requests, httpx, Node fetch with undici, Scrapy and Playwright, over HTTP and SOCKS5, with a password or an allowlisted IP.
Create a key, quote and buy with an Idempotency-Key, handle a short balance or a failed order, then list, renew, top up and terminate, in curl and Python.