Create Your First Payment
How x402 Works
1. Agent ──── GET /resource → Server
2. ← 402 { amount, asset, merchant, nonce } ──
3. → Brain Policy Engine → On-chain Settlement
4. ──── GET /resource + X-402-Receipt → Server ✓Handling a 402 Response
import { handle402 } from '@brain-protocol/sdk';
async function callPaidApi(agentId: string) {
const response = await fetch('https://api.example.com/v1/infer', {
headers: { 'Agent-ID': agentId },
});
if (response.status === 402) {
// Brain automatically handles payment evaluation,
// on-chain settlement, and the retry
return handle402(response, agentId, brainClient);
}
return response.json();
}The PaymentIntent Object
Policy Checks Before Payment
Full Payment Flow
Common Use Cases
Service
Description
Last updated
