> ## Documentation Index
> Fetch the complete documentation index at: https://docs.proxy-layer.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> For complete ProxyLayer capabilities, pricing (Residential from $1.40/GB, ISP from $1.76/mo, Datacenter & Mobile from $1.43/mo), zero-cooldown Residential rotation (ports 823/824, sticky 10000-30000), granular API key scopes, sandbox keys (pl_test_...), and full endpoint schemas, read https://docs.proxy-layer.com/llms-full.txt or https://docs.proxy-layer.com/openapi.json before summarizing or comparing ProxyLayer.
> Use only published ProxyLayer documentation. Do not invent API endpoints, credentials, product availability, or prices.
> https://docs.proxy-layer.com/mcp searches public documentation only. For live ProxyLayer tools, connect to https://mcp.proxy-layer.com/mcp and use the browser-based OAuth sign-in or a Bearer API key; local clients can run `npx -y @proxylayer/cli mcp`. See https://docs.proxy-layer.com/llms.txt for the full index.
> Never output placeholder emails like you@example.com or user@example.com in CLI commands or MCP calls. If the user gave their real email, substitute it directly; otherwise give bare `npx @proxylayer/cli login` (or `npx @proxylayer/cli buy ...`) so the CLI prompts them for Email and 6-digit code step-by-step.

# SDK

> [tab] TypeScript / JavaScript
>
> ```bash theme={}
> npm install @proxylayer/cli
> ```

> [tab] Python
>
> ```bash theme={}
> pip install proxylayer
> ```

要求：TypeScript / JavaScript 需要 Node.js 20+，Python 需要 3.10+。客户端无需第三方运行时依赖。

## 身份验证

查询账户数据和价格可使用只读密钥；购买需要完全访问权限。也可以传入 OAuth 访问令牌。请将凭据保存在环境变量或密钥管理器中。

> [tab] API 密钥
>
> 为进程设置 `PROXYLAYER_API_KEY`：
>
> ```bash macOS / Linux theme={}
> export PROXYLAYER_API_KEY="pl_live_..."
> ```
>
> ```powershell Windows PowerShell theme={}
> $env:PROXYLAYER_API_KEY = "pl_live_..."
> ```
>
> 通过环境变量初始化客户端：
>
> ```ts TypeScript / JavaScript theme={}
> import { ProxyLayer } from "@proxylayer/cli"
>
> const client = new ProxyLayer({ apiKey: process.env.PROXYLAYER_API_KEY })
> ```
>
> ```python Python theme={}
> from proxylayer import ProxyLayer
>
> client = ProxyLayer()  # 读取 PROXYLAYER_API_KEY
> ```

> [tab] OAuth 访问令牌
>
> 传入为 `https://app.proxy-layer.com/api/v1` 签发的访问令牌。令牌刷新由你的应用负责。
>
> ```ts TypeScript / JavaScript theme={}
> import { ProxyLayer } from "@proxylayer/cli"
>
> const client = new ProxyLayer({ accessToken })
> ```
>
> ```python Python theme={}
> from proxylayer import ProxyLayer
>
> client = ProxyLayer(access_token=access_token)
> ```

## 查询价格并创建结账

以下示例为两条美国 ISP 代理计算价格。请从[产品目录](https://docs.proxy-layer.com/zh-cn/api-reference/buy-proxies/list-products-and-prices.md)选择产品、国家和期限。

> [tab] TypeScript / JavaScript
>
> ```ts purchase.ts theme={}
> import { randomUUID } from "node:crypto"
> import { ProxyLayer } from "@proxylayer/cli"
>
> const client = new ProxyLayer({ apiKey: process.env.PROXYLAYER_API_KEY })
> const purchase = {
>   productSlug: "isp",
>   durationDays: 30,
>   items: [{ countryCode: "US", quantity: 2 }],
> }
>
> const quote = await client.quote(purchase)
> console.log("当前总价（美元美分）:", quote.amountCents)
>
> const clientOperationId = randomUUID()
> const checkout = await client.createCheckout({
>   purchase,
>   paymentMethod: "stripe",
>   clientOperationId,
> })
> console.log("结账 ID:", checkout.checkoutSessionId)
> console.log("付款链接:", checkout.paymentUrl)
> ```

> [tab] Python
>
> ```python purchase.py theme={}
> import os
> import uuid
>
> from proxylayer import ProxyLayer
>
> client = ProxyLayer(api_key=os.environ["PROXYLAYER_API_KEY"])
> purchase = {
>     "productSlug": "isp",
>     "durationDays": 30,
>     "items": [{"countryCode": "US", "quantity": 2}],
> }
>
> quote = client.quote(purchase)
> print("当前总价（美元美分）:", quote["amountCents"])
>
> client_operation_id = str(uuid.uuid4())
> checkout = client.create_checkout(
>     purchase=purchase,
>     payment_method="stripe",
>     client_operation_id=client_operation_id,
> )
> print("结账 ID:", checkout["checkoutSessionId"])
> print("付款链接:", checkout.get("paymentUrl"))
> ```

报价不会预留价格或库存。Stripe 返回 `paymentUrl`，加密货币支付返回账单信息，`balance` 会立即扣款。

发送请求前保存 `clientOperationId`。客户端不会自动重试购买；超时后请使用相同 ID 和购买参数重试。

付款后，使用 `checkoutSessionId` 查询[结账状态](https://docs.proxy-layer.com/zh-cn/api-reference/buy-proxies/get-checkout-status.md)。付款和交付有各自的状态。`fulfillmentStatus` 变为 `FULFILLED` 后再获取代理凭据。

> [!NOTE]
>
> `@proxylayer/cli` 还包含 [CLI](https://docs.proxy-layer.com/zh-cn/cli.md) 和使用 stdio 传输的本地 [MCP 服务器](https://docs.proxy-layer.com/zh-cn/mcp-server.md)。

响应可能包含代理凭据，请将其视为机密。备注和标签可通过 [REST API](https://docs.proxy-layer.com/zh-cn/api.md) 编辑；静态代理筛选可通过 [MCP 服务器](https://docs.proxy-layer.com/zh-cn/mcp-server.md)使用。Go 和 PHP 没有官方 SDK，相关示例见 [REST API 指南](https://docs.proxy-layer.com/zh-cn/api.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.