{"_id":"@aeon-ai-pay/axios","_rev":"2-5855f5832a17240c88983f8bfcdc2132","name":"@aeon-ai-pay/axios","dist-tags":{"latest":"2.1.2"},"versions":{"2.1.0":{"name":"@aeon-ai-pay/axios","version":"2.1.0","keywords":[],"author":{"name":"Coinbase Inc."},"license":"Apache-2.0","_id":"@aeon-ai-pay/axios@2.1.0","maintainers":[{"name":"aeon_project","email":"code@alchemypay.org"}],"homepage":"https://github.com/coinbase/x402#readme","bugs":{"url":"https://github.com/coinbase/x402/issues"},"dist":{"shasum":"607b28b57fe9b959381e088b9b378fcd7fcefe97","tarball":"https://registry.npmjs.org/@aeon-ai-pay/axios/-/axios-2.1.0.tgz","fileCount":8,"integrity":"sha512-IPG8qJfv9RWuEvJfIg/u+f4+vOZgceTDhi+jEss5oZH1V6+GMff+cuIRe57u2aazc1OQG7Uw6p/RFQ1M7AmSuQ==","signatures":[{"sig":"MEYCIQCkB47xJF5tw1t2E9jPzKPDkXxwc6BluHEAuVHo89lKyQIhAJmbDc16xZdzUZIP7W2PaJ8Y6P0se28kyBIFE0cRw1Eb","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":36717},"main":"./dist/cjs/index.js","_from":"file:aeon-ai-pay-axios-2.1.0.tgz","types":"./dist/index.d.ts","module":"./dist/esm/index.js","exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"scripts":{"lint":"eslint . --ext .ts --fix","test":"vitest run","build":"tsup","start":"tsx --env-file=.env index.ts","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","lint:check":"eslint . --ext .ts","test:watch":"vitest","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\""},"_npmUser":{"name":"aeon_project","email":"code@alchemypay.org"},"_resolved":"/private/var/folders/rr/hyts0bs54zn73fgjjlld0tvm0000gn/T/d4623be2a73d9b6102c2cee3402f8a07/aeon-ai-pay-axios-2.1.0.tgz","_integrity":"sha512-IPG8qJfv9RWuEvJfIg/u+f4+vOZgceTDhi+jEss5oZH1V6+GMff+cuIRe57u2aazc1OQG7Uw6p/RFQ1M7AmSuQ==","repository":{"url":"git+https://github.com/coinbase/x402.git","type":"git"},"_npmVersion":"11.11.0","description":"x402 Payment Protocol","directories":{},"_nodeVersion":"25.8.1","dependencies":{"zod":"^3.24.2","axios":"^1.7.9","@aeon-ai-pay/core":"^2.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tsup":"^8.4.0","vite":"^6.2.6","eslint":"^9.24.0","vitest":"^3.0.5","prettier":"3.5.2","@eslint/js":"^9.24.0","typescript":"^5.7.3","@types/node":"^22.13.4","eslint-plugin-jsdoc":"^50.6.9","vite-tsconfig-paths":"^5.1.4","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.6","@typescript-eslint/parser":"^8.29.1","@typescript-eslint/eslint-plugin":"^8.29.1"},"_npmOperationalInternal":{"tmp":"tmp/axios_2.1.0_1775096316535_0.8898698819192528","host":"s3://npm-registry-packages-npm-production"}},"2.1.2":{"name":"@aeon-ai-pay/axios","version":"2.1.2","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/index.d.ts","keywords":[],"license":"Apache-2.0","author":{"name":"Coinbase Inc."},"repository":{"type":"git","url":"git+https://github.com/coinbase/x402.git"},"description":"x402 Payment Protocol","devDependencies":{"@eslint/js":"^9.24.0","@types/node":"^22.13.4","@typescript-eslint/eslint-plugin":"^8.29.1","@typescript-eslint/parser":"^8.29.1","eslint":"^9.24.0","eslint-plugin-import":"^2.31.0","eslint-plugin-jsdoc":"^50.6.9","eslint-plugin-prettier":"^5.2.6","prettier":"3.5.2","tsup":"^8.4.0","tsx":"^4.19.2","typescript":"^5.7.3","vite-tsconfig-paths":"^5.1.4","vitest":"^3.0.5","vite":"^6.2.6"},"dependencies":{"axios":"^1.7.9","zod":"^3.24.2","@aeon-ai-pay/core":"^2.1.2"},"exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"publishConfig":{"access":"public"},"scripts":{"start":"tsx --env-file=.env index.ts","test":"vitest run","test:watch":"vitest","build":"tsup","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"","lint":"eslint . --ext .ts --fix","lint:check":"eslint . --ext .ts"},"_id":"@aeon-ai-pay/axios@2.1.2","bugs":{"url":"https://github.com/coinbase/x402/issues"},"homepage":"https://github.com/coinbase/x402#readme","_integrity":"sha512-FU4tdovE91Ph6niL2dJWB2gEhW1wE8NvqZhzR4gsWrY264F9e6WQbaPN5d6w3mTlOG9EWPbo72SJ0UnwGXNFmA==","_resolved":"/private/var/folders/rr/hyts0bs54zn73fgjjlld0tvm0000gn/T/d6349bf7073714dd93fe7c0689fbc692/aeon-ai-pay-axios-2.1.2.tgz","_from":"file:aeon-ai-pay-axios-2.1.2.tgz","_nodeVersion":"25.8.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-FU4tdovE91Ph6niL2dJWB2gEhW1wE8NvqZhzR4gsWrY264F9e6WQbaPN5d6w3mTlOG9EWPbo72SJ0UnwGXNFmA==","shasum":"fb3a56f3b75ce9ecfa408a161eb66b617f84f297","tarball":"https://registry.npmjs.org/@aeon-ai-pay/axios/-/axios-2.1.2.tgz","fileCount":8,"unpackedSize":36717,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC2GOKVRZ5sIEfsI6/AsKZoFgu8IKlvpyF3UMSGUByo8gIgRKejJ9GjRf99NQA0AneyutyOD66gBB6iyDV4R7LBTR8="}]},"_npmUser":{"name":"aeon_project","email":"code@alchemypay.org"},"directories":{},"maintainers":[{"name":"aeon_project","email":"code@alchemypay.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/axios_2.1.2_1777276947043_0.391669980332918"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-02T02:18:36.451Z","modified":"2026-04-27T08:02:27.376Z","2.1.0":"2026-04-02T02:18:36.678Z","2.1.2":"2026-04-27T08:02:27.254Z"},"bugs":{"url":"https://github.com/coinbase/x402/issues"},"author":{"name":"Coinbase Inc."},"license":"Apache-2.0","homepage":"https://github.com/coinbase/x402#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/coinbase/x402.git"},"description":"x402 Payment Protocol","maintainers":[{"name":"aeon_project","email":"code@alchemypay.org"}],"readme":"# x402-axios\n\nA utility package that extends Axios to automatically handle 402 Payment Required responses using the x402 payment protocol v2. This package enables seamless integration of payment functionality into your applications when making HTTP requests.\n\n## Installation\n\n```bash\npnpm install @x402/axios\n```\n\n## Quick Start\n\n```typescript\nimport axios from \"axios\";\nimport { wrapAxiosWithPaymentFromConfig } from \"@x402/axios\";\nimport { ExactEvmScheme } from \"@x402/evm\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\n// Create an account\nconst account = privateKeyToAccount(\"0xYourPrivateKey\");\n\n// Wrap the axios instance with payment handling\nconst api = wrapAxiosWithPaymentFromConfig(axios.create(), {\n  schemes: [\n    {\n      network: \"eip155:8453\", // Base Sepolia\n      client: new ExactEvmScheme(account),\n    },\n  ],\n});\n\n// Make a request that may require payment\nconst response = await api.get(\"https://api.example.com/paid-endpoint\");\n\nconst data = response.data;\n```\n\n## API\n\n### `wrapAxiosWithPayment(axiosInstance, client)`\n\nWraps an Axios instance to handle 402 Payment Required responses automatically.\n\n#### Parameters\n\n- `axiosInstance`: The Axios instance to wrap (typically from `axios.create()`)\n- `client`: An x402Client instance with registered payment schemes\n\n### `wrapAxiosWithPaymentFromConfig(axiosInstance, config)`\n\nConvenience wrapper that creates an x402Client from a configuration object.\n\n#### Parameters\n\n- `axiosInstance`: The Axios instance to wrap (typically from `axios.create()`)\n- `config`: Configuration object with the following properties:\n  - `schemes`: Array of scheme registrations, each containing:\n    - `network`: Network identifier (e.g., 'eip155:8453', 'solana:mainnet', 'eip155:*' for wildcards)\n    - `client`: The scheme client implementation (e.g., `ExactEvmScheme`, `ExactSvmScheme`)\n    - `x402Version`: Optional protocol version (defaults to 2, set to 1 for legacy support)\n  - `paymentRequirementsSelector`: Optional function to select payment requirements from multiple options\n\n#### Returns\n\nA wrapped Axios instance that automatically handles 402 responses by:\n1. Making the initial request\n2. If a 402 response is received, parsing the payment requirements\n3. Creating a payment header using the configured scheme client\n4. Retrying the request with the payment header\n\n## Examples\n\n### Basic Usage with EVM\n\n```typescript\nimport { config } from \"dotenv\";\nimport axios from \"axios\";\nimport { wrapAxiosWithPaymentFromConfig, decodePaymentResponseHeader } from \"@x402/axios\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport { ExactEvmScheme } from \"@x402/evm\";\n\nconfig();\n\nconst { EVM_PRIVATE_KEY, API_URL } = process.env;\n\nconst account = privateKeyToAccount(EVM_PRIVATE_KEY as `0x${string}`);\n\nconst api = wrapAxiosWithPaymentFromConfig(axios.create(), {\n  schemes: [\n    {\n      network: \"eip155:*\", // Support all EVM chains\n      client: new ExactEvmScheme(account),\n    },\n  ],\n});\n\n// Make a request to a paid API endpoint\napi.get(API_URL)\n  .then(response => {\n    const data = response.data;\n    \n    // Optionally decode the payment response header\n    const paymentResponse = response.headers[\"payment-response\"];\n    if (paymentResponse) {\n      const decoded = decodePaymentResponseHeader(paymentResponse);\n      console.log(\"Payment details:\", decoded);\n    }\n    \n    console.log(\"Response data:\", data);\n  })\n  .catch(error => {\n    console.error(error);\n  });\n```\n\n### Using Builder Pattern\n\nFor more control, you can use the builder pattern to register multiple schemes:\n\n```typescript\nimport axios from \"axios\";\nimport { wrapAxiosWithPayment, x402Client } from \"@x402/axios\";\nimport { ExactEvmScheme } from \"@x402/evm/exact/client\";\nimport { ExactSvmScheme } from \"@x402/svm/exact/client\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport { createKeyPairSignerFromBytes } from \"@solana/kit\";\nimport { base58 } from \"@scure/base\";\n\n// Create signers\nconst evmSigner = privateKeyToAccount(\"0xYourPrivateKey\");\nconst svmSigner = await createKeyPairSignerFromBytes(base58.decode(\"YourSvmPrivateKey\"));\n\n// Build client with multiple schemes\nconst client = new x402Client()\n  .register(\"eip155:*\", new ExactEvmScheme(evmSigner))\n  .register(\"solana:*\", new ExactSvmScheme(svmSigner));\n\n// Wrap axios with the client\nconst api = wrapAxiosWithPayment(axios.create(), client);\n```\n\n### Multi-Chain Support\n\n```typescript\nimport axios from \"axios\";\nimport { wrapAxiosWithPaymentFromConfig } from \"@x402/axios\";\nimport { ExactEvmScheme } from \"@x402/evm\";\nimport { ExactSvmScheme } from \"@x402/svm\";\n\nconst api = wrapAxiosWithPaymentFromConfig(axios.create(), {\n  schemes: [\n    // EVM chains\n    {\n      network: \"eip155:8453\", // Base Sepolia\n      client: new ExactEvmScheme(evmAccount),\n    },\n    // SVM chains\n    {\n      network: \"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\", // Solana devnet\n      client: new ExactSvmScheme(svmSigner),\n    },\n  ],\n});\n```\n\n### Custom Payment Requirements Selector\n\n```typescript\nimport axios from \"axios\";\nimport { wrapAxiosWithPaymentFromConfig, type SelectPaymentRequirements } from \"@x402/axios\";\nimport { ExactEvmScheme } from \"@x402/evm\";\n\n// Custom selector that prefers the cheapest option\nconst selectCheapestOption: SelectPaymentRequirements = (version, accepts) => {\n  if (!accepts || accepts.length === 0) {\n    throw new Error(\"No payment options available\");\n  }\n  \n  // Sort by value and return the cheapest\n  const sorted = [...accepts].sort((a, b) => \n    BigInt(a.value) - BigInt(b.value)\n  );\n  \n  return sorted[0];\n};\n\nconst api = wrapAxiosWithPaymentFromConfig(axios.create(), {\n  schemes: [\n    {\n      network: \"eip155:8453\",\n      client: new ExactEvmScheme(account),\n    },\n  ],\n  paymentRequirementsSelector: selectCheapestOption,\n});\n```\n\n","readmeFilename":"README.md"}