Client / Buyer Integration
As an x402 client (buyer), your application makes requests to resource servers that require payment. When a server responds with HTTP 402 Payment Required, the x402 client libraries automatically handle the payment flow for you -- constructing the appropriate payment payload, submitting it to the facilitator, and retrying the original request with a valid payment header.
How It Works
- Your application makes a request to a paid endpoint.
- The server responds with
402 Payment Required, including payment requirements in the response headers (price, accepted currencies, facilitator URL). - The x402 client library intercepts the
402response, constructs a payment payload, and sends it to the facilitator athttps://facilitator.svmacc.techfor verification and settlement. - The library retries the original request with the
X-Paymentheader attached. - The server validates the payment and returns the requested resource.
This entire flow is transparent to your application code. You simply use the wrapped HTTP client as you normally would.
Supported Libraries
x402 provides client wrappers for popular HTTP libraries across multiple languages.
TypeScript / JavaScript
| Library | Package | Description |
|---|---|---|
| Fetch | x402-fetch | Wraps the native fetch API with automatic payment handling. |
| Axios | x402-axios | Adds a payment interceptor to Axios instances. |
Python
| Library | Package | Description |
|---|---|---|
| httpx | x402 | Async HTTP client built on httpx with automatic payment handling. |
| requests | x402 | Session wrapper for the requests library with automatic payment handling. |
Prerequisites
Before integrating an x402 client, you will need:
- A funded wallet -- An Ethereum-compatible private key with sufficient balance to cover payments on the required network.
- The resource server URL -- The base URL of the server hosting the paid endpoint.
- The endpoint path -- The specific path of the resource you want to access.
Environment Variables
All client examples use the following environment variables:
| Variable | Description |
|---|---|
RESOURCE_SERVER_URL | Base URL of the resource server (e.g., https://api.example.com). |
ENDPOINT_PATH | Path to the paid endpoint (e.g., /api/premium/data). |
PRIVATE_KEY | Your Ethereum-compatible private key (e.g., 0xabc123...). |
Next Steps
Choose the client library that matches your stack and follow the integration guide: