Ax402Docs
GETTING STARTED

Buyer clients

Pay gateway URLs from TypeScript, Go, Python, CLI, or MCP

Buyer clients pay gateway hostnames — seller API URLs wrapped by Ax402 — from scripts, agents, CI, or backends with an x402-capable EVM wallet. They do not call the control plane. For in-browser humans, use the React paywall.

How it works

  • Request a gateway URL (e.g. https://my-api.ax402.io/v1/data)
    • Gateway returns HTTP 402 with payment requirements
    • Buyer client signs with your EVM wallet and retries with PAYMENT-SIGNATURE
    • Gateway verifies via the facilitator and returns the upstream response

You do not configure a facilitator URL in buyer code — the gateway handles verify/settle.

Environment

  • AX402_EVM_PRIVATE_KEY — signing key funded with USDC on the gateway network (legacy: EVM_PRIVATE_KEY)
    • Gateway URL — seller hostname from your dashboard, not AX402_BASE_URL

Use a published gateway hostname and path from your seller account.

Language parity

  • TypeScriptexact + batch-settlement, browser wallet signer (@ax402/sdk/buyer)
    • Goexact + batch-settlement; settlement via SettleResponseFrom
    • Pythonexact + batch-settlement sync + AsyncBuyerClient

TypeScript

npm install @ax402/sdk @x402/fetch @x402/evm viem
import { buyerClientFromEnv } from "@ax402/sdk/buyer";

const client = await buyerClientFromEnv();
const { response, payment } = await client.pay({
  url: "https://my-api.ax402.io/v1/foo",
});
const body = await response.text();

Also: payAndFetch(signer, { url }), createPaymentFetch(signer), createEvmSignerFromBrowserProvider().

Batch-settlement gateways

const client = await buyerClientFromEnv({
  batch: { depositMultiplier: 5 },
});

Go

import "github.com/AxLabs/ax402-sdks/go/buyer"

c, err := buyer.NewFromPrivateKey(os.Getenv("AX402_EVM_PRIVATE_KEY"))
resp, err := c.Get(ctx, "https://my-api.ax402.io/v1/foo")
defer resp.Body.Close()
settle, _ := c.SettleResponseFrom(resp)

Batch: buyer.NewFromPrivateKey(key, buyer.BatchOptions{DepositMultiplier: 5}).

Also: PayURL(ctx, method, url, body), HTTPClient(). See Go SDK.

Python

cd ax402-sdks/packages/python && pip install -e ".[buyer]"
from ax402_sdk.buyer import BuyerClient

result = BuyerClient.from_env().get("https://my-api.ax402.io/v1/foo")
print(result.status_code, result.settlement)

# Async
from ax402_sdk.buyer import AsyncBuyerClient, evm_signer_from_private_key

CLI and MCP

export AX402_EVM_PRIVATE_KEY=0x...
ax402 inspect url --url https://my-api.ax402.io/v1/foo --json
ax402 pay url --url https://my-api.ax402.io/v1/foo --json

Install CLI globally: npm install -g @ax402/cli. MCP: npx @ax402/mcp-server. See MCP server and CLI reference.

When to use what

  • Node / TS backend or agent → @ax402/sdk/buyer
    • Go service or CI → github.com/AxLabs/ax402-sdks/go/buyer
    • Python script or async service → ax402_sdk.buyer
    • Browser SPA with wallet UI → React paywall

Protocol reference

Signing and facilitator interaction: x402-foundation/x402.

On this page