OMPX JavaScript SDK
    Preparing search index...

    Function installOmpxAxios

    • 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 (validateStatus permits it) or as an error (Axios default). Both paths are handled.

      Parameters

      • axiosInstance: AxiosInstance

        The Axios instance to patch (e.g. axios or axios.create())

      • ompxClient: OmpxClient

        An initialized OmpxClient with payment methods configured

      Returns () => void

      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')