SDKs
PHP SDK
The official PHP library for BuyProxy: generate residential, mobile, ISP and datacenter proxies, check bandwidth, buy more by card or crypto, and run a reseller business. PHP 8.1+ with ext-curl and ext-json. Typed readonly models, PHP 8 named arguments, and a pluggable HTTP transport.
Typed
readonlymodels and exceptionsPHP 8 named arguments:
generate($planId, country: 'US', count: 5)Pluggable HTTP transport (cURL by default) โ swap in Guzzle or Symfony HttpClient
Helpers for Guzzle, Laravel `Http`, Symfony HttpClient and raw cURL
Source, issues and releases: github.com/DishantSinghDev2/buyproxy-php
Installation
composer require buyproxy/buyproxyPHP 8.1+ with ext-curl and ext-json. No other runtime dependencies.
Authentication
Create an API key under Dashboard โ API keys โ personal keys start bp_key_, reseller keys bp_live_. The SDK reads BUYPROXY_API_KEY from the environment automatically; you can also pass the key explicitly. A missing key fails immediately with an authentication error, without a network call.
// 1. Environment variable (recommended)
$bp = new Client();
// 2. Explicit key, e.g. from Laravel config / a secrets manager
$bp = new Client(apiKey: config('services.buyproxy.key'));
// 3. Which kind of key is it?
echo $bp->keyKind(); // "personal" | "reseller" | nullQuick start
<?php
require 'vendor/autoload.php';
use BuyProxy\Client;
$bp = new Client(apiKey: getenv('BUYPROXY_API_KEY')); // or omit it โ reads BUYPROXY_API_KEY
$plan = $bp->plans->list()[0];
$result = $bp->plans->generate($plan->id, country: 'US', city: 'Austin', count: 5);
echo $result->proxies[0]->url(); // http://user-country-us-city-austin:pass@gw.buyproxy.org:6969Pass stickyMinutes: 10 to keep the same IP for ten minutes, or protocol: 'socks5' for SOCKS5.
Generating proxies
Generation is free and instant โ bandwidth is only consumed when traffic flows through a proxy. Every parameter is optional; omit one and the API's default applies. (Names follow each language's conventions, e.g. stickyMinutes / sticky_minutes / StickyMinutes.)
| Parameter | Type | What it does | |
|---|---|---|---|
protocol | "http" \ | "socks5" | Proxy protocol. Default http (which also carries HTTPS). Check plan.generate.protocols for what a product supports |
count | integer 1โ1000 | How many proxy lines to return. Default 1 | |
country | ISO 3166-1 alpha-2 | e.g. US, DE, JP. Omit for a worldwide IP | |
state | string | State or region, where the product supports it | |
city | string | City, where the product supports it | |
isp | string | Network / carrier, where the product supports it | |
stickyMinutes | integer | Keep the same IP for this many minutes. Omit for a fresh IP on every request. The maximum is plan.generate.maxStickyMinutes; 0 there means the product has no sticky sessions |
Each returned line is username:password@host:port with your targeting encoded in the username. Lines are on-demand and not persistent โ generate fresh ones when you need them instead of storing them, because credentials can rotate when the pool moves.
// Country, state and city โ what a plan supports is in $plan->generate->targeting
$bp->plans->generate($plan->id, country: 'US', state: 'California', city: 'Los Angeles');
// Sticky session: keep one IP for 30 minutes (max is $plan->generate->maxStickyMinutes)
$bp->plans->generate($plan->id, country: 'DE', stickyMinutes: 30);
// SOCKS5 instead of HTTP
$bp->plans->generate($plan->id, protocol: 'socks5', count: 10);
// Bulk: up to 1000 lines per call
$result = $bp->plans->generate($plan->id, count: 1000);
file_put_contents('proxies.txt', implode("\n", $result->lines));Every top-up and allocation call takes a product key. Live prices come from the catalog call, so you never hard-code a rate.
| Key | Product | Min order | Best for |
|---|---|---|---|
residential | Core Residential | 1 GB | Everyday rotating residential IPs with country targeting |
premium | Premium Residential | 2 GB | City-level targeting, sticky sessions and priority routing |
isp | ISP Rotating | 1 GB | Datacenter speed with ISP-grade trust |
mobile | Mobile Proxies | 1 GB | Real carrier IPs for mobile-only targets |
ipv4 | Datacenter IPv4 | 1 GB | Fast, cheap per-GB datacenter traffic |
ipv6 | IPv6 Proxies | 1 GB | Huge address diversity at the lowest per-GB rate |
Pay-as-you-go top-ups of 100 GB or more include a 10% volume bonus, and a single order is capped at 10,000 GB.
Using the proxies with your stack
Each generated proxy is a small object (host, port, username, password, protocol) with helpers that return exactly what common clients expect, so you never hand-build a proxy URL or worry about percent-encoding special characters in a password.
Guzzle
$http = new GuzzleHttp\Client($result->proxies[0]->toGuzzle());
echo $http->get('https://api.ipify.org')->getBody();Laravel
use Illuminate\Support\Facades\Http;
$ip = Http::withOptions($result->proxies[0]->toGuzzle())->get('https://api.ipify.org')->body();Register the client once in a service provider:
$this->app->singleton(\BuyProxy\Client::class, fn () => new \BuyProxy\Client(apiKey: config('services.buyproxy.key')));Symfony HttpClient
$client = Symfony\Component\HttpClient\HttpClient::create($result->proxies[0]->toSymfony());
echo $client->request('GET', 'https://api.ipify.org')->getContent();cURL
$ch = curl_init('https://api.ipify.org');
curl_setopt_array($ch, $result->proxies[0]->toCurl() + [CURLOPT_RETURNTRANSFER => true]);
echo curl_exec($ch);Account, balances & history
Read-only calls for building dashboards, alerts and pre-flight checks. balances is the one to watch: it shows spendable GB per product, including GB from a payment that's still being added (pending).
$catalog = $bp->products->list(); // product keys & live prices โ no API key needed
$account = $bp->account->get(); // email, plan, lifetime GB
$balances = $bp->balances->list(); // spendable GB per product (+ GB still arriving)
$plans = $bp->plans->list(); // plan ids and what each can generate
$history = $bp->transactions->list(limit: 20);Buying bandwidth
- Call the top-up method โ it returns a hosted payment URL and a transaction id. Card payments are processed by Stripe Checkout; crypto by an invoice page.
- Send your user (or yourself) to that URL to pay.
- Poll the transaction (or use the SDK's
waithelper) untilstatusissucceededorfailed. Crypto payments are checked live on every poll, so they settle even if a webhook is delayed. - The GB shows up under
balanceswithin seconds โpendingGbwhile it's arriving,activeGbonce it's live.
Plans are subscriptions billed monthly or yearly by card (crypto only covers pay-as-you-go top-ups). If the account already has a subscription, the call returns the subscription settings page as the URL and a null transaction id โ switching plans is prorated there, and you can't accidentally subscribe twice.
// Buy 10 GB of Core Residential by card โ send the customer to payUrl
$checkout = $bp->topup->card(productKey: 'residential', gb: 10);
header('Location: ' . $checkout->payUrl);
// Or subscribe to a plan (monthly or yearly)
$bp->topup->card(plan: 'pro', interval: 'year');
// Crypto (pay-as-you-go top-ups only)
$bp->topup->crypto('residential', 50);
// Wait for the payment to settle โ GB appears on $bp->balances->list() right after
$tx = $bp->transactions->wait($checkout->transactionId);
echo $tx->status; // "succeeded"Card payments are processed by Stripe; crypto top-ups are pay-as-you-go only. Subscriptions can be managed or cancelled from Dashboard โ Billing.
Reseller API
The reseller API lets you build a proxy product on top of BuyProxy. The flow is always the same:
- Fund your pool โ buy GB per product into your reseller pool by card or crypto. Pool GB is priced like a normal top-up (including the volume bonus), fixed at purchase time.
- Create a customer โ an isolated sub-account with its own credentials and no bandwidth. Store the returned
username. - Allocate โ move whole GB of one product from your pool onto that customer, with an idempotency key. The first allocation of a product creates the plan; later ones add to it.
- Generate โ produce proxy lines for the customer from their plan id (found on the customer record), with all the usual targeting options.
- Monitor โ read the customer's usage (remaining, used, total per plan, plus any GB still arriving) to bill or alert.
- Suspend / reactivate โ a suspended customer can't generate new lines (
403). Lines already handed out may keep working until they rotate, so stop distributing them at the same time. You can also rename a customer.
Allocated GB can't be moved back to the pool, so allocate what a customer has paid for.
$reseller = new Client(apiKey: 'bp_live_โฆ');
$reseller->reseller->pool->topupCard('residential', 500); // buy into your pool
$customer = $reseller->reseller->customers->create('Acme Inc'); // isolated sub-account
$reseller->reseller->customers->allocate($customer->username, 'residential', 20, idempotencyKey: 'order-1042');
$detail = $reseller->reseller->customers->get($customer->username);
$result = $reseller->reseller->customers->generate($customer->username, $detail->plans[0]->id, country: 'DE');
$reseller->reseller->customers->update($customer->username, status: 'suspended');Allocating bandwidth to a customer moves real GB, so it accepts an idempotency key. Send the same key twice and the second call moves nothing and returns alreadyApplied: true with the same result โ safe to retry after a timeout or crash.
Use a value you can derive again from your own data (an order id, an invoice number), not a random value created per attempt. Keys are scoped to your account and may be up to 200 characters.
Errors & retries
Every non-success response becomes a typed error carrying the HTTP status and the API's own message, so you can branch on the failure instead of parsing strings.
| HTTP | Exception | Meaning |
|---|---|---|
| 400 | ValidationException | A parameter was missing or invalid |
| 401 | AuthenticationException | Missing or invalid API key (also thrown locally when no key is set) |
| 402 | InsufficientBandwidthException | Empty reseller pool, or a plan with no GB left |
| 403 | PermissionDeniedException | Suspended account/customer, or the plan doesn't include this endpoint |
| 404 | NotFoundException | Plan, customer or transaction not found on this account |
| 429 | RateLimitException | Over 60 requests/minute โ has ->retryAfterSeconds |
| 5xx | ServerException | BuyProxy or an upstream provider is unavailable |
| โ | ConnectionException | No response (DNS, reset, timeout, offline) |
use BuyProxy\Exceptions\{AuthenticationException, InsufficientBandwidthException, RateLimitException};
try {
$bp->plans->generate($planId);
} catch (InsufficientBandwidthException) {
echo 'Out of GB โ top up first';
} catch (RateLimitException $e) {
echo "Slow down; retry in {$e->retryAfterSeconds}s";
} catch (AuthenticationException) {
echo 'Check your API key';
}Every exception extends BuyProxy\Exceptions\BuyProxyException and exposes ->status and ->body.
Every SDK retries for you, with the same rules:
- Rate limits (`429`) are always retried, waiting for the
Retry-Afterthe API sends (capped at 30 s) or an exponential back-off with jitter. - Reads (
GET) are also retried on502/503/504and on network failures. - Writes are not retried on server errors โ a repeated checkout or allocation must never double-charge โ unless you attach an idempotency key (see below), which makes the retry provably safe.
- The default is 2 retries; set it to 0 to turn retries off. After the last attempt you get the typed error.
The API allows 60 requests per minute per key. Batch with count (up to 1000 lines per call) rather than looping over single-proxy calls.
Configuration
new Client(
apiKey: 'bp_key_โฆ', // default: getenv('BUYPROXY_API_KEY')
baseUrl: 'https://www.buyproxy.org',
timeout: 30.0,
maxRetries: 2, // 429s always; 5xx only for safe requests
transport: new MyGuzzleTransport(), // implement BuyProxy\Http\Transport
);Concurrency
// Calls are synchronous. For parallel work, fan out through your queue
// (e.g. Laravel Horizon / Symfony Messenger) โ one job per customer or plan โ
// and keep the total under 60 requests/minute per API key.Testing your code
You don't need a real account or network to unit-test code that uses the SDK โ inject a fake transport. This is how the SDK's own test suite works.
use BuyProxy\Client;
use BuyProxy\Http\Transport;
final class FakeTransport implements Transport
{
public function send(string $method, string $url, array $headers, ?string $body, float $timeout): array
{
return ['status' => 200, 'headers' => [], 'body' => '{"lines":["u:p@gw.buyproxy.org:6969"]}'];
}
}
$bp = new Client(apiKey: 'bp_key_test', transport: new FakeTransport());
$this->assertSame('gw.buyproxy.org', $bp->plans->generate('plan_1')->proxies[0]->host);API reference
Every method maps one-to-one onto a documented REST endpoint.
| Capability | Call |
|---|---|
| Catalog & prices | $bp->products->list() |
| Account | $bp->account->get() |
| Spendable GB per product | $bp->balances->list() |
| Plans | $bp->plans->list() |
| Generate proxies | $bp->plans->generate($planId, โฆ) |
| Card checkout | $bp->topup->card(โฆ) |
| Crypto checkout | $bp->topup->crypto($product, $gb) |
| Payments | $bp->transactions->list() ยท ->get($id) ยท ->wait($id) |
| Create an account | $bp->auth->signup() ยท ->verifyOtp() ยท ->resendOtp() |
| Reseller summary | $bp->reseller->me() |
| Customers | $bp->reseller->customers->list/create/get/update/usage/allocate/generate |
| Reseller pool | $bp->reseller->pool->get/topupCard/topupCrypto |
Notes
All exceptions live in
BuyProxy\Exceptionsand extendBuyProxyException(with->statusand->body).Plug in Guzzle, Symfony HttpClient or a framework client by implementing the one-method
BuyProxy\Http\Transportinterface.Proxyhas helpers for Guzzle, Laravel'sHttpfacade, Symfony HttpClient, raw cURL and environment variables.
Developing the SDK
composer install
vendor/bin/phpunitWas this page helpful?