Getting Started

Quickstart for Buyers

This guide walks you through how to use x402 to interact with PayPerScrape. By the end of this guide, you will be able to programmatically discover payment requirements, complete a payment, and scrape any website.

Prerequisites

Before you begin, ensure you have:

  • A crypto wallet with USDC (any EVM-compatible wallet)
  • Node.js and npm, or Python and pip
  • Access to PayPerScrape API endpoint

Note: Coinbase has pre-configured examples available in their repo, including examples for fetch, Axios, and MCP.

Note: These Docs have been adapted from the Coinbase x402 documentation. For the full documentation, see the Official x402 documentation

1

Install Dependencies

Node.js

HTTP Clients (Axios/Fetch) Install x402-axios or x402-fetch:

npmbash

Python

Install the x402 package:

pipbash
2

Create a Wallet Client

Node.js (viem)

Install the required package:

npmbash

Then instantiate the wallet account:

TypeScripttypescript

Python (eth-account)

Install the required package:

pipbash

Then instantiate the wallet account:

Pythonpython
3

Make Paid Requests Automatically

Node.js

You can use either x402-fetch or x402-axios to automatically handle 402 Payment Required responses and complete payment flows.

Fetch

x402-fetch extends the native fetch API to handle 402 responses and payment headers for you. Full example here

TypeScripttypescript

Axios

x402-axios adds a payment interceptor to Axios, so your requests are retried with payment headers automatically. Full example here

TypeScripttypescript

Python

You can use either httpx or Requests to automatically handle 402 Payment Required responses and complete payment flows.

  • Requests is a well-established library for synchronous HTTP requests. It is simple and ideal for straightforward, sequential workflows.
  • HTTPX is a modern library that supports both synchronous and asynchronous (async) HTTP requests. Use HTTPX if you need high concurrency, advanced features like HTTP/2, or want to leverage Python's async capabilities.

HTTPX

Full example here

Pythonpython

Requests

Full example here

Pythonpython
4

Error Handling

Clients will throw errors if:

  • The request configuration is missing
  • A payment has already been attempted for the request
  • There is an error creating the payment header
  • The target URL is invalid or blocked
  • The scraping failed after all escalation attempts

Summary

  • Install an x402 client package
  • Create a wallet client
  • Use the provided wrapper/interceptor to make paid API requests to PayPerScrape
  • Payment flows are handled automatically for you

References

For questions or support, join our Discord.