X402 payment handler for AI agent payment flows — middleware for agent-to-agent transactions
ap2-payment-handler is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on ai-agents, handler, payments, x402. It currently has 0 GitHub stars and 0 forks, and sits alongside related tools like legal-context-protocol, tdm-integration-kit, TDM-Agent-Integration-Kit, tael-protocol, inflow-node, inflow-cli.
Non-custodial crypto payment handler for the AP2 Agent Payment Protocol. The first open-source, zero-escrow AP2 implementation.
AP2 (Agent Payment Protocol) is Google's emerging standard for agentic commerce — enabling AI agents to negotiate and execute payments autonomously on behalf of users. This package implements the AP2 mandate lifecycle with a non-custodial, crypto-native approach.
npm install ap2-payment-handler
import { AP2PaymentHandler } from 'ap2-payment-handler';
const handler = new AP2PaymentHandler({
supportedMethods: ['usdc_base', 'x402'],
});
// Create an intent mandate (agent-initiated)
const mandate = handler.createIntentMandate({
agentId: 'my-agent-001',
merchantId: 'merchant-xyz',
maxAmount: 10.0,
currency: 'USDC',
ttl: Date.now() + 5 * 60_000, // 5 minutes
});
// Process payment
const response = await handler.handle({
mandate,
preferredMethod: 'usdc_base',
});
if (response.success) {
console.log('Payment initiated:', response.transactionId);
console.log('Audit trail:', response.paymentMandate?.auditTrail);
}
const cartMandate = handler.createCartMandate({
agentId: 'my-agent-001',
lineItems: [
{ name: 'API Credits', price: 5.0, qty: 2 },
{ name: 'Priority Queue', price: 3.0, qty: 1 },
],
total: 13.0,
currency: 'USDC',
});
const response = await handler.handle({
mandate: cartMandate,
preferredMethod: 'usdc_base',
});
import { X402Bridge } from 'ap2-payment-handler';
const bridge = new X402Bridge();
// When your agent receives a 402 response
const paymentResponse = await bridge.handleResponse({
status: 402,
headers: response.headers,
});
if (paymentResponse) {
// Build proof and retry request
const proof = await bridge.buildPaymentProof({
amount: '5.00',
currency: 'USDC',
address: '0x...',
agentId: 'my-agent-001',
});
}
| Method | Network | Description |
|---|---|---|
usdc_base |
Base (Coinbase L2) | USDC on Base — low fees, fast finality |
x402 |
Any | HTTP 402 Payment Required flow |
usdc_arbitrum |
Arbitrum | USDC on Arbitrum One |
usdc_optimism |
Optimism | USDC on Optimism |
This package is zero-escrow by design:
All PaymentMandate objects carry isNonCustodial: true as a type-level guarantee.
AP2PaymentHandlerconstructor({ supportedMethods }) — initialize with supported payment methodshandle(request) — process an AP2 payment requestcreateIntentMandate(params) — create an agent-initiated intent mandatecreateCartMandate(params) — create a cart mandate from line itemsgetSupportedMethods() — list configured methodsX402BridgeparsePaymentRequired(headers) — extract payment details from 402 headersbuildPaymentProof(params) — create a non-custodial payment proofhandleResponse(response) — handle HTTP responses, returns AP2PaymentResponse for 402validateMandate(mandate)Validates a mandate and throws AP2ValidationError on failure.
MIT © AI Agent Economy
An open standard for discovering the legal context of agentic commerce transactions.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Tael is a payment layer that enables autonomous AI agents to securely pay for APIs, MCP tools, data, and digital services using USDC on Stellar.
Official TypeScript/Node.js SDKs for the InFlow payments platform - x402 and MPP (Machine Payments Protocol) integration for sellers and buyers.
A wallet for your agents to onboard and pay. Agentic MPP / x402 payments from your machine - CLI + MCP server.
Lucid Agents Commerce SDK. Bootstrap AI agents in 60 seconds that can pay, sell, and participate in agentic commerce supply chains. Our protocol agnostic SDK provides CLI-generated templates and drop-in adapters for Hono, Express, Next.js, and TanStack, giving you instant access to crypto/fiat payment rails (AP2, A2A, x402, ERC8004).
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Skills & plugins for agentic commerce : UCP, ACP, AP2, A2A, WebMCP, Magento 2, BigCommerce, WooCommerce
Trust infrastructure for million-agent economies on Solana - identity, reputation, and validation designed for continuous feedback at scale.
A chain-agnostic AI-native payment infrastructure, authz layer for x402