{"_id":"@autopayprotocol/agent-sdk","_rev":"3-29c5211ff6e9a540052ed140c9f5c1ea","name":"@autopayprotocol/agent-sdk","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@autopayprotocol/agent-sdk","version":"0.1.0","license":"Apache-2.0","_id":"@autopayprotocol/agent-sdk@0.1.0","maintainers":[{"name":"apeoverflow","email":"kieranmarcus@gmail.com"}],"homepage":"https://github.com/apeoverflow/Auto-Pay-Protocol/tree/main/packages/agent-sdk#readme","bugs":{"url":"https://github.com/apeoverflow/Auto-Pay-Protocol/issues"},"dist":{"shasum":"4330d4a515afeb15e2f63f41d32a872bacfb0e06","tarball":"https://registry.npmjs.org/@autopayprotocol/agent-sdk/-/agent-sdk-0.1.0.tgz","fileCount":7,"integrity":"sha512-5762JsfSAnyh6IQvdY7Q5pqhAp/lmpNIKFKqI1tHMF38WC1ijhScCn25J+vk/Fthjv2yQdh1MDAJxEqg7jsEsw==","signatures":[{"sig":"MEUCIBnHJwf9c8mxj3x2Jew3aXbZwkSIBGtq7JpcTRPV0WNrAiEA/f3RaEGSPsSNOjvbEau7EXoUTTp2J5PDa7zE6zpewXU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":232814},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"gitHead":"55f56a92eb3dd134a4cadb03f226b5dc899a3843","scripts":{"dev":"tsup --watch","build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"apeoverflow","email":"kieranmarcus@gmail.com"},"repository":{"url":"git+https://github.com/apeoverflow/Auto-Pay-Protocol.git","type":"git","directory":"packages/agent-sdk"},"_npmVersion":"11.4.2","description":"Agent SDK for AutoPay Protocol — subscribe, cancel, and manage on-chain subscriptions from autonomous agents","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.1","viem":"^2.21.0","typescript":"^5.3.3","@types/node":"^20.11.0"},"peerDependencies":{"viem":"^2.0.0"},"_npmOperationalInternal":{"tmp":"tmp/agent-sdk_0.1.0_1772593147736_0.1726799212268746","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@autopayprotocol/agent-sdk","version":"0.1.1","license":"Apache-2.0","_id":"@autopayprotocol/agent-sdk@0.1.1","maintainers":[{"name":"apeoverflow","email":"kieranmarcus@gmail.com"}],"homepage":"https://github.com/apeoverflow/Auto-Pay-Protocol/tree/main/packages/agent-sdk#readme","bugs":{"url":"https://github.com/apeoverflow/Auto-Pay-Protocol/issues"},"dist":{"shasum":"c9c5ade62fe5d076d5908ba7f6f0610c3f1cda53","tarball":"https://registry.npmjs.org/@autopayprotocol/agent-sdk/-/agent-sdk-0.1.1.tgz","fileCount":7,"integrity":"sha512-PzxevVtBcJYQYPvoJOg3ew6BtuR/T6UWLLMTUkJGcfQVg1qQmHjbB/nPGlq+bWX50DPuUZ8tDRtkgTkBr/KJtQ==","signatures":[{"sig":"MEUCIQC4zIYmrtq9xN+fAGRL1K9IRATQ3ajV7PHIzAEi4Py+VAIgTbDvCTaqjc3YX5JZO/F7uwnV/fnZfOtwMyipJeMaLPg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":233132},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"gitHead":"55f56a92eb3dd134a4cadb03f226b5dc899a3843","scripts":{"dev":"tsup --watch","build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"apeoverflow","email":"kieranmarcus@gmail.com"},"repository":{"url":"git+https://github.com/apeoverflow/Auto-Pay-Protocol.git","type":"git","directory":"packages/agent-sdk"},"_npmVersion":"11.4.2","description":"Agent SDK for AutoPay Protocol — subscribe, cancel, and manage on-chain subscriptions from autonomous agents","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.1","viem":"^2.21.0","typescript":"^5.3.3","@types/node":"^20.11.0"},"peerDependencies":{"viem":"^2.0.0"},"_npmOperationalInternal":{"tmp":"tmp/agent-sdk_0.1.1_1772595344247_0.25559793360320304","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@autopayprotocol/agent-sdk","version":"0.1.2","description":"Agent SDK for AutoPay Protocol — subscribe, cancel, and manage on-chain subscriptions from autonomous agents","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/apeoverflow/Auto-Pay-Protocol.git","directory":"packages/agent-sdk"},"homepage":"https://github.com/apeoverflow/Auto-Pay-Protocol/tree/main/packages/agent-sdk#readme","bugs":{"url":"https://github.com/apeoverflow/Auto-Pay-Protocol/issues"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"engines":{"node":">=20"},"scripts":{"build":"tsup","dev":"tsup --watch","test":"vitest run","test:unit":"vitest run --exclude 'src/__tests__/integration.test.ts'","test:integration":"vitest run src/__tests__/integration.test.ts","test:watch":"vitest","typecheck":"tsc --noEmit"},"peerDependencies":{"viem":"^2.0.0"},"devDependencies":{"@types/node":"^20.11.0","tsup":"^8.0.1","typescript":"^5.3.3","viem":"^2.21.0","vitest":"^4.0.18"},"_id":"@autopayprotocol/agent-sdk@0.1.2","gitHead":"55f56a92eb3dd134a4cadb03f226b5dc899a3843","_nodeVersion":"24.3.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-nMbZuqo5/9SvJaCI6dxU+RhszgMzofAjWy11/uVqSK9AViaMPETkMtAvs0H4ieHWabiNoDNkrgfQpUyCQlLj/g==","shasum":"c908cccf62594eac2a0a1f2349ab75e9be7a4d4a","tarball":"https://registry.npmjs.org/@autopayprotocol/agent-sdk/-/agent-sdk-0.1.2.tgz","fileCount":8,"unpackedSize":238336,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBwQVvASmIfxvkl8rEht/mOZxzD3o6/iKYYwV4JBT5V8AiAOzT71N5y7/Xz9+Np7P78UnATVp5KxdhDZupCX//VPFg=="}]},"_npmUser":{"name":"apeoverflow","email":"kieranmarcus@gmail.com"},"directories":{},"maintainers":[{"name":"apeoverflow","email":"kieranmarcus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/agent-sdk_0.1.2_1772678115410_0.8664685234800276"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-04T02:59:07.656Z","modified":"2026-03-05T02:35:15.680Z","0.1.0":"2026-03-04T02:59:07.891Z","0.1.1":"2026-03-04T03:35:44.393Z","0.1.2":"2026-03-05T02:35:15.572Z"},"bugs":{"url":"https://github.com/apeoverflow/Auto-Pay-Protocol/issues"},"license":"Apache-2.0","homepage":"https://github.com/apeoverflow/Auto-Pay-Protocol/tree/main/packages/agent-sdk#readme","repository":{"type":"git","url":"git+https://github.com/apeoverflow/Auto-Pay-Protocol.git","directory":"packages/agent-sdk"},"description":"Agent SDK for AutoPay Protocol — subscribe, cancel, and manage on-chain subscriptions from autonomous agents","maintainers":[{"name":"apeoverflow","email":"kieranmarcus@gmail.com"}],"readme":"# @autopayprotocol/agent-sdk\n\nTypeScript SDK for autonomous AI agents to manage USDC subscriptions on [AutoPay Protocol](https://autopayprotocol.com). Subscribe, cancel, bridge USDC cross-chain, and authenticate with services — all from code.\n\n## Install\n\n```bash\nnpm install @autopayprotocol/agent-sdk viem\n```\n\n## Quickstart\n\n```typescript\nimport { AutoPayAgent, wrapFetchWithSubscription } from '@autopayprotocol/agent-sdk'\n\nconst agent = new AutoPayAgent({\n  privateKey: '0x...',\n  chain: 'base', // 'base' | 'flowEvm' | 'baseSepolia'\n})\n\n// Option 1: Wrapped fetch — auto-subscribes on HTTP 402\nconst fetchWithPay = wrapFetchWithSubscription(fetch, agent)\nconst res = await fetchWithPay('https://api.example.com/data')\n\n// Option 2: Direct subscription\nconst sub = await agent.subscribe({\n  merchant: '0x...',\n  amount: 10,          // 10 USDC\n  interval: 'monthly',\n})\n\nconst token = await agent.createBearerToken(sub.policyId)\n```\n\n## API Reference\n\n### `AutoPayAgent`\n\n| Method | Description |\n|--------|-------------|\n| `subscribe(params)` | Create subscription. Auto-approves USDC. First charge is immediate. |\n| `unsubscribe(policyId)` | Cancel subscription by revoking the on-chain policy. |\n| `getPolicy(policyId)` | Read full on-chain policy details. |\n| `isActive(policyId)` | Check if a policy is currently active. |\n| `canCharge(policyId)` | Check if a policy can be charged right now. |\n| `getBalance()` | Get USDC balance (raw 6-decimal bigint). |\n| `getGasBalance()` | Get native token balance for gas. |\n| `approveUsdc(amount?)` | Approve USDC to PolicyManager. Default: MaxUint256. |\n| `createBearerToken(policyId, ttlSeconds?)` | Create signed auth token. Default TTL: 1 hour. |\n| `bridgeUsdc(params)` | Bridge USDC from another chain via LiFi. |\n| `swapNativeToUsdc(params)` | Swap native tokens to USDC on the same chain. |\n\n### `SubscribeParams`\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `merchant` | `0x${string}` | Merchant address |\n| `amount` | `number` | USDC amount per cycle (e.g. `10` = 10 USDC) |\n| `interval` | `number \\| IntervalPreset` | Billing interval in seconds or preset |\n| `spendingCap?` | `number` | Max total USDC spend. Default: `amount * 30` |\n| `metadataUrl?` | `string` | Optional metadata URL (e.g. IPFS CID) |\n\n**IntervalPreset**: `'hourly'` | `'daily'` | `'weekly'` | `'biweekly'` | `'monthly'` | `'quarterly'` | `'yearly'`\n\n### `wrapFetchWithSubscription(fetchFn, agent, options?)`\n\nWraps `fetch` to transparently handle HTTP 402 responses with AutoPay discovery. On first 402, subscribes and retries. Subsequent requests reuse cached subscriptions.\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `store?` | `SubscriptionStore` | Persistence backend. Default: `MemoryStore` |\n| `selectPlan?` | `(plans) => number` | Plan selection strategy. Default: first plan (index 0) |\n| `spendingCap?` | `(amount) => number` | Cap strategy. Default: `amount * 30` |\n| `onSubscribe?` | `(merchant, sub) => void` | Called after new subscription |\n| `onReuse?` | `(merchant, policyId) => void` | Called when cached subscription is reused |\n| `bridge?` | `{ fromChainId, sourceRpcUrl, ... }` | Auto-bridge config for cross-chain funding |\n\n### Stores\n\n| Store | Description |\n|-------|-------------|\n| `MemoryStore` | In-memory (default). Lost on restart. |\n| `FileStore(path)` | File-backed JSON. Persists across restarts. |\n\n### Error Classes\n\n| Error | Code | Description |\n|-------|------|-------------|\n| `InsufficientBalanceError` | `INSUFFICIENT_BALANCE` | Not enough USDC |\n| `InsufficientGasError` | `INSUFFICIENT_GAS` | No native tokens for gas |\n| `PolicyNotFoundError` | `POLICY_NOT_FOUND` | Policy doesn't exist |\n| `PolicyNotActiveError` | `POLICY_NOT_ACTIVE` | Policy is cancelled/expired |\n| `TransactionFailedError` | `TRANSACTION_FAILED` | On-chain transaction failed |\n| `BridgeQuoteError` | `BRIDGE_QUOTE_FAILED` | LiFi quote failed |\n| `BridgeExecutionError` | `BRIDGE_EXECUTION_FAILED` | Bridge tx failed |\n| `BridgeTimeoutError` | `BRIDGE_TIMEOUT` | Bridge polling timed out |\n\n## Supported Chains\n\n| Chain | Key | Chain ID |\n|-------|-----|----------|\n| Base | `base` | 8453 |\n| Flow EVM | `flowEvm` | 747 |\n| Base Sepolia | `baseSepolia` | 84532 |\n\n## Configuration\n\n```typescript\nconst agent = new AutoPayAgent({\n  privateKey: '0x...',       // Required\n  chain: 'base',             // Default: 'base'\n  rpcUrl: '...',             // Override default RPC\n  policyManager: '0x...',    // Override contract address\n  usdc: '0x...',             // Override USDC address\n})\n```\n\n## Links\n\n- [Full Documentation](https://autopayprotocol.com/docs)\n- [Agent SDK Quickstart](https://github.com/apeoverflow/Auto-Pay-Protocol/blob/main/documentation/agent-sdk-quickstart.md)\n- [MCP Server](https://www.npmjs.com/package/@autopayprotocol/mcp)\n- [Middleware](https://www.npmjs.com/package/@autopayprotocol/middleware)\n","readmeFilename":"README.md"}