{"_id":"@aipayagnet/fetch","name":"@aipayagnet/fetch","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@aipayagnet/fetch","version":"0.1.0","description":"AiPay client SDK — auto-pay x402 responses with your AI agent budget","main":"src/index.js","types":"src/index.d.ts","scripts":{"build":"tsc","dev":"tsc --watch"},"keywords":["aipay","x402","payment","usdc","fetch","ai","agent","auto-pay","crypto"],"license":"MIT","author":{"name":"AiPay","email":"66474902@qq.com"},"repository":{"type":"git","url":"git+https://github.com/aipay-work/aipay.git"},"homepage":"https://aipay.work","_id":"@aipayagnet/fetch@0.1.0","bugs":{"url":"https://github.com/aipay-work/aipay/issues"},"_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-sxOMjwKBjHllrRXaOt9O8vQ5g7McrqfkPjypq+OThf81riqczlOIP1MxM0dU01nRaIqZLG086zAjxaNyhErNEQ==","shasum":"a5534aedc638a70a725ce56fe246c9f7fcfdb08a","tarball":"https://registry.npmjs.org/@aipayagnet/fetch/-/fetch-0.1.0.tgz","fileCount":5,"unpackedSize":9615,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIG67SSo24Z1nVHhzIcyxfo8yo0dREQmBjdL6RzOVdYIqAiEAgKiVl6FdjlfRAkt4kB+tPKharYACah27dF2auueNJHA="}]},"_npmUser":{"name":"aipayagnet","email":"66474902@qq.com"},"directories":{},"maintainers":[{"name":"aipayagnet","email":"66474902@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fetch_0.1.0_1783244439174_0.6605634009897527"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-05T09:40:39.068Z","0.1.0":"2026-07-05T09:40:39.299Z","modified":"2026-07-05T09:40:39.453Z"},"maintainers":[{"name":"aipayagnet","email":"66474902@qq.com"}],"description":"AiPay client SDK — auto-pay x402 responses with your AI agent budget","homepage":"https://aipay.work","keywords":["aipay","x402","payment","usdc","fetch","ai","agent","auto-pay","crypto"],"repository":{"type":"git","url":"git+https://github.com/aipay-work/aipay.git"},"author":{"name":"AiPay","email":"66474902@qq.com"},"bugs":{"url":"https://github.com/aipay-work/aipay/issues"},"license":"MIT","readme":"# @aipay/fetch\n\nAiPay client SDK — auto-pay x402 responses with your AI agent budget.\n\n## Install\n\n```bash\nnpm install @aipay/fetch\n```\n\n## Quick Start\n\n```javascript\nimport { AiPay } from \"@aipay/fetch\";\n\nconst aipay = new AiPay({\n  apiKey: \"aipay_xxx\", // Your AiPay API key\n  agentId: \"agt_xxx\", // Your agent ID (from dashboard)\n  walletPrivateKey: \"0x...\", // Your wallet private key for signing payments\n});\n\n// Fetch a paid API — handles the 402 → pay → retry flow automatically\nconst resp = await aipay.fetch(\"https://paid-api.com/v1/search?q=test\");\nconst data = await resp.json();\n```\n\n## How It Works\n\n1. You call `aipay.fetch(url)` — the SDK adds your API key and agent headers.\n2. If the server responds with `402 Payment Required`, the SDK reads the x402 requirements.\n3. The SDK signs and broadcasts a USDC payment on the required chain (Polygon/Base/Ethereum).\n4. The SDK retries the request with the `X-PAYMENT` header and returns the successful response.\n\n## Risk Policies\n\nControl how much your agent can spend per call:\n\n```javascript\n// strict: max $0.25 per call\nawait aipay.fetch(url, { policy: \"strict\" });\n\n// balanced (default): no per-call limit, respects agent budget\nawait aipay.fetch(url, { policy: \"balanced\" });\n\n// permissive: no checks\nawait aipay.fetch(url, { policy: \"permissive\" });\n```\n\n## API\n\n### `new AiPay(config)`\n\n| Parameter | Type | Description |\n|---|---|---|\n| `config.apiKey` | `string` | Your AiPay API key (`aipay_xxx`) |\n| `config.agentId` | `string?` | Agent ID for budget tracking (`agt_xxx`) |\n| `config.walletPrivateKey` | `string?` | Wallet private key for signing payments (`0x...`) |\n| `config.dashboardUrl` | `string?` | Override dashboard URL |\n| `config.apiUrl` | `string?` | Override API URL |\n\n### `aipay.fetch(url, options?)`\n\nReturns a standard `Promise<Response>`. In addition to normal `fetch` options, accepts:\n\n| Parameter | Type | Description |\n|---|---|---|\n| `options.policy` | `\"strict\" \\| \"balanced\" \\| \"permissive\"` | Risk policy for spending |\n\n## License\n\nMIT © [AiPay](https://aipay.work)\n","readmeFilename":"README.md","_rev":"1-f261b6fcdf82664dbf5ffd035264f06c"}