Skip to content

x402 Rail

Overview

x402 is an HTTP extension for native payments. Servers return 402 Payment Required with payment requirements; clients pay and retry. Enables pay-per-API-call patterns between AI agents and service providers.

Setup

X402_FACILITATOR_URL=https://x402.org/facilitator
WALLET_PRIVATE_KEY=0x...
BASE_RPC_URL=https://mainnet.base.org

Usage

import { probeX402Endpoint } from '@pqsafe/agent-pay'
const requirements = await probeX402Endpoint('https://api.aiservice.xyz/v1/analyze')
// { maxAmountRequired: 0.001, network: 'base-mainnet', asset: 'USDC' }
const result = await executeAgentPayment(signed, {
recipient: 'api.aiservice.xyz',
amount: requirements.maxAmountRequired,
rail: 'x402',
})

Adapter: x402