BuyProxy logo
Log inSign up

CLI

Guides & recipes

Worked examples that combine several commands to get something done. New to the CLI? Start with the overview. Every command is documented in detail on its own page — see the command list.

Give a scraper rotating proxies

Most tools — curl, wget, pip, git, many scraping frameworks — honour the standard proxy environment variables. generate -f env prints them for you.

  1. Generate and export in one step:
bash
eval "$(buyproxy generate residential -c US -f env)"
  1. Confirm the tool now exits from a US address:
bash
curl https://api.ipify.org
  1. Run your scraper as normal in the same shell. HTTP_PROXY, HTTPS_PROXY and ALL_PROXY are set.
The exports are for the first proxy only, with a rotating IP per request. For a sticky exit add -s 10 (keep the same IP for ten minutes). To rotate between *different* proxies, generate several with -n and pick one per worker.

Build a proxy list for another tool

Plenty of tools want a file of proxies. Generate as many as you need (up to 1000 per call) and redirect:

bash
# 500 rotating German proxies, one per line: username:password@host:port
buyproxy generate premium -c DE -n 500 -f plain > proxies.txt

# the same as full URLs
buyproxy generate premium -c DE -n 500 -f url > proxies-urls.txt

# or as JSON for your own program
buyproxy generate premium -c DE -n 500 --json > proxies.json

Because the CLI prints only data when its output is redirected, there's no banner or colour to strip. Lines are on-demand, so regenerate the file when it's time to refresh rather than keeping it for weeks.

Get a ready snippet for Playwright or Python

Print a configuration you can paste directly into code, optionally onto your clipboard:

bash
buyproxy generate -c US -f playwright --copy     # Playwright launch options
buyproxy generate -c US -f requests              # a Python requests example
buyproxy generate -c US -f curl                  # a curl command that prints your exit IP

For more than a snippet, use an SDK — each has helpers for Playwright, Puppeteer, requests, httpx, Scrapy, Guzzle and more.

Monitor bandwidth in CI and get warned early

Run this on a schedule (cron, GitHub Actions) to fail loudly before a job runs dry. Store the key as a secret and export it as BUYPROXY_API_KEY.

bash
#!/usr/bin/env bash
set -euo pipefail

# products that are funded but have less than 2 GB left
low=$(buyproxy balance --json | jq -r '[.balances[] | select(.planId != null and .activeGb < 2) | .productKey] | join(", ")')

if [ -n "$low" ]; then
  echo "Low on proxy bandwidth: $low" >&2
  exit 1
fi

Hook the failure into your alerting (Slack, email, PagerDuty). When it fires, buyproxy topup — or your own automation calling buyproxy topup <product> --gb 50 --crypto --no-open --no-wait --json — creates the payment link to act on.

Health-check your proxies on a schedule

buyproxy test exits non-zero when a proxy doesn't work, so it drops straight into a cron job:

bash
# every 15 minutes: alert if a US exit stops working
*/15 * * * * BUYPROXY_API_KEY=… buyproxy test residential -c US --json >/dev/null || /usr/local/bin/alert "BuyProxy US exit failing"

To keep the history, log latency:

bash
buyproxy test --json | jq -c '{at: now, ok, latencyMs, ip: .body.ip}' >> proxy-health.jsonl

Each check uses a few kilobytes of bandwidth.

Onboard a reseller customer end to end

You need a reseller key (bp_live_…, Business plan or higher) — log in with it first: buyproxy login.

  1. Fund your pool (once, or whenever it runs low):
bash
buyproxy pool topup residential --gb 500 --card
buyproxy pool                      # confirm the GB arrived
  1. Create the customer and note the username it prints:
bash
buyproxy customers new "Acme Inc"
# Username  bp_acme_1a2b
  1. Allocate what they paid for — the CLI attaches an idempotency key, so retries are safe:
bash
buyproxy customers allocate bp_acme_1a2b residential 20
  1. Generate proxies for them and hand them over:
bash
buyproxy customers generate bp_acme_1a2b -c DE -n 5 -f plain
  1. Watch usage to bill or alert:
bash
buyproxy customers usage bp_acme_1a2b
buyproxy customers show bp_acme_1a2b
  1. Pause them if they stop paying, and bring them back when they do:
bash
buyproxy customers suspend bp_acme_1a2b
buyproxy customers activate bp_acme_1a2b
Allocated GB can't be moved back to your pool, and lines already handed out can keep working until they rotate even after a suspension — so allocate only what's paid for, and stop distributing lines when you suspend. To automate this inside your own product, use the reseller API or an SDK.

Was this page helpful?