The Axios instance to wrap
Configured t402Client instance for handling payments
The wrapped Axios instance that handles 402 responses automatically
import axios from 'axios';
import { wrapAxiosWithPayment, t402Client } from '@t402/axios';
import { ExactEvmScheme } from '@t402/evm';
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount('0x...');
const client = new t402Client()
.register('eip155:*', new ExactEvmScheme(account));
const api = wrapAxiosWithPayment(axios.create(), client);
// Make a request that may require payment
const response = await api.get('https://api.example.com/paid-endpoint');
Wraps an Axios instance with t402 payment handling.
This function adds an interceptor to automatically handle 402 Payment Required responses by creating and sending payment headers. It will: