x402-axios
A utility package that extends Axios to automatically handle 402 Payment Required responses using the x402 payment protocol. This package enables seamless integration of payment functionality into your applications when making HTTP requests with Axios.Installation
Quick Start
Features
- Automatic handling of 402 Payment Required responses
- Automatic retry of requests with payment headers
- Payment verification and header generation
- Exposes payment response headers
API
withPaymentInterceptor(axiosClient, walletClient)
Adds payment handling interceptors to an existing Axios instance.
Parameters
axiosClient
: The Axios instance to add payment handling towalletClient
: The wallet client used to sign payment messages (must implement the x402 wallet interface)
Returns
The same Axios instance with payment interceptors added. The interceptors will:- Catch 402 responses
- Parse payment requirements from the response
- Create payment headers using the wallet client
- Retry the original request with payment headers