The Axios instance to patch (e.g. axios or axios.create())
An initialized OmpxClient with payment methods configured
An uninstall function that removes the interceptors when called
import axios from 'axios'
import { OmpxClient } from '@ompx/client'
import { installOmpxAxios } from '@ompx/axios'
import { tempo } from '@ompx/tempo'
import { privateKeyToAccount } from 'viem/accounts'
const client = new OmpxClient({
methods: [tempo({ account: privateKeyToAccount('0x...') })],
})
installOmpxAxios(axios, client)
// All subsequent requests auto-pay on 402
const response = await axios.get('https://api.example.com/paid-resource')
Install OMPX payment handling as Axios response interceptors.
After installation, any 402 response received by the Axios instance will be automatically handled: OMPX signs the payment credential and retries the original request with the credential headers attached.
Works whether Axios treats HTTP 402 as success (
validateStatuspermits it) or as an error (Axios default). Both paths are handled.