{"_id":"@0xkinance/x402-anthropic","_rev":"2-f619f6e408c9e5d01a7d7960ac03d320","name":"@0xkinance/x402-anthropic","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@0xkinance/x402-anthropic","version":"0.1.0","keywords":["anthropic","x402","payments","claude","http402"],"license":"MIT","_id":"@0xkinance/x402-anthropic@0.1.0","maintainers":[{"name":"0xkinance","email":"kinance@gmail.com"}],"dist":{"shasum":"5b87f3e8efce4b6620175570284eabc378eccbdd","tarball":"https://registry.npmjs.org/@0xkinance/x402-anthropic/-/x402-anthropic-0.1.0.tgz","fileCount":20,"integrity":"sha512-ghbr9ctgoMD6G7R/U+OX7ItbWVW3bX3k5kElZbGv2Mqqqaklb6exidDkTfXmxGhY7M4jFMepp3dzZdqQrCcGuA==","signatures":[{"sig":"MEQCIFLQr4Rbz0nfY6hcuOu2iTziHzLlg0ffLBPboLwTs/59AiAaAeGNJpjsz6rqiR51uCjOrMXWEDBXnH6Nt7iFYH9Cuw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25640},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"24338df007151b5fb701de5c71c078633cf2b33f","scripts":{"test":"vitest run","build":"tsc","typecheck":"tsc --noEmit"},"_npmUser":{"name":"0xkinance","email":"kinance@gmail.com"},"_npmVersion":"10.9.2","description":"x402 payment transport for the Anthropic TypeScript SDK","directories":{},"_nodeVersion":"22.15.1","dependencies":{"@x402/fetch":"^2.5.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^1.6.0","typescript":"^5.4.0","@types/node":"^20.0.0","@anthropic-ai/sdk":"^0.52.0"},"peerDependencies":{"@anthropic-ai/sdk":">=0.40.0"},"optionalDependencies":{"@x402/evm":"^2.3.0","@x402/svm":"^2.3.0"},"_npmOperationalInternal":{"tmp":"tmp/x402-anthropic_0.1.0_1779884898486_0.27210169587346256","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Renamed to x402-anthropic"}},"time":{"created":"2026-05-27T12:28:18.324Z","modified":"2026-05-27T13:18:39.977Z","0.1.0":"2026-05-27T12:28:18.642Z"},"license":"MIT","keywords":["anthropic","x402","payments","claude","http402"],"description":"x402 payment transport for the Anthropic TypeScript SDK","maintainers":[{"name":"0xkinance","email":"kinance@gmail.com"}],"readme":"# x402-anthropic-typescript\n\n[![npm](https://img.shields.io/npm/v/@0xkinance/x402-anthropic)](https://www.npmjs.com/package/@0xkinance/x402-anthropic)\n[![TypeScript](https://img.shields.io/badge/typescript-5.0+-blue)](https://typescriptlang.org)\n[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/kinance/x402-anthropic-typescript/blob/main/LICENSE)\n[![CI](https://github.com/kinance/x402-anthropic-typescript/actions/workflows/node.yml/badge.svg)](https://github.com/kinance/x402-anthropic-typescript/actions)\n\nx402 payment transport for the [Anthropic TypeScript SDK](https://github.com/anthropics/anthropic-sdk-js).\n\nWrap the standard `Anthropic` client with a crypto wallet. When the server responds with **HTTP 402**, the library automatically signs a USDC payment and retries — zero code changes needed. Follows the pattern introduced by [qntx/x402-openai-typescript](https://github.com/qntx/x402-openai-typescript).\n\n## Install\n\n```bash\nnpm install @0xkinance/x402-anthropic @x402/evm viem        # EVM (Base, Ethereum)\nnpm install @0xkinance/x402-anthropic @x402/svm @solana/kit  # SVM (Solana)\nnpm install @0xkinance/x402-anthropic @x402/evm @x402/svm viem @solana/kit  # all chains\n```\n\n## Quick start\n\n```ts\nimport { X402Anthropic, EVMWallet } from \"@0xkinance/x402-anthropic\";\n\nconst client = new X402Anthropic({\n  wallet: new EVMWallet(\"0x...\"),\n  baseURL: \"https://your-x402-gateway.example.com\",\n});\n\nconst message = await client.messages.create({\n  model: \"claude-opus-4-5\",\n  max_tokens: 1024,\n  messages: [{ role: \"user\", content: \"Hello!\" }],\n});\nconsole.log(message.content[0]);\n```\n\nSwap `EVMWallet` for `SVMWallet` to pay on Solana — the API is identical.\n\n## Usage\n\n### Streaming\n\n```ts\nconst stream = await client.messages.stream({\n  model: \"claude-opus-4-5\",\n  max_tokens: 1024,\n  messages: [{ role: \"user\", content: \"Tell me a story.\" }],\n});\nfor await (const text of stream.textStream) {\n  process.stdout.write(text);\n}\n```\n\n### Payment policies\n\n```ts\nimport { X402Anthropic, EVMWallet, preferNetwork, maxAmount } from \"@0xkinance/x402-anthropic\";\n\nconst client = new X402Anthropic({\n  wallet: new EVMWallet(\"0x...\"),\n  policies: [preferNetwork(\"eip155:8453\"), maxAmount(1_000_000n)],  // Base, max $1 USDC\n  baseURL: \"...\",\n});\n```\n\n## API reference\n\n### `X402Anthropic`\n\nDrop-in replacement for `Anthropic` from `@anthropic-ai/sdk`.\n\n| Parameter | Type | Description |\n| :-- | :-- | :-- |\n| `wallet` | `Wallet` | Wallet adapter for signing payments |\n| `policies` | `Policy[]` | Payment policies (chain preference, amount cap) |\n| `baseURL` | `string` | Gateway URL (required — points at your x402 server) |\n\nAll standard Anthropic options (`timeout`, `maxRetries`, `apiKey`, …) are forwarded.\n\n### Wallet adapters\n\n| Class | Chain | Peer deps |\n| :-- | :-- | :-- |\n| `EVMWallet(privateKey)` | Base, Ethereum, any EVM | `@x402/evm viem` |\n| `SVMWallet(privateKey)` | Solana | `@x402/svm @solana/kit` |\n\nImplement the `Wallet` interface to add a new chain.\n\n### Policy helpers\n\n| Function | Effect |\n| :-- | :-- |\n| `preferNetwork(caip2)` | Prefer a specific chain (falls back to any if unavailable) |\n| `preferScheme(scheme)` | Prefer a payment scheme (e.g. `\"exact\"`) |\n| `maxAmount(units)` | Skip payment requirements above this USDC unit amount |\n\n## Examples\n\n```bash\nEVM_PRIVATE_KEY=\"0x...\"        npx tsx examples/basic.ts\nEVM_PRIVATE_KEY=\"0x...\"        npx tsx examples/streaming.ts\n```\n\n## Related\n\n- [x402-anthropic-python](https://github.com/kinance/x402-anthropic-python) — Python version of this library\n- [qntx/x402-openai-typescript](https://github.com/qntx/x402-openai-typescript) — OpenAI SDK equivalent\n- [coinbase/x402](https://github.com/coinbase/x402) — x402 protocol spec and reference implementation\n\n## License\n\nMIT\n","readmeFilename":"README.md"}