Machine Native Payments

Brain integrates x402 as its primary protocol for machine-native payments over standard HTTP, allowing agents to pay for services in real time without API keys or static subscriptions.

x402 at the HTTP Layer

x402 defines how servers signal payment requirements using HTTP 402 responses and structured payment metadata. Brain handles policy evaluation and on-chain settlement. Agents and servers communicate only via standard HTTP headers, no custom protocols required.

The Full Payment Pipeline

1

Initial request (no payment)

Agent sends GET /resource with Agent-ID header. No funds committed yet.

2

Server returns 402

Response includes X-402-Payment header with amount, asset, merchant address, expiry, and nonce.

3

Brain parses and creates PaymentIntent

The Payment Orchestrator constructs a PaymentIntent linking agentId, resource URI, and all payment parameters.

4

Policy engine evaluates

Budget availability, merchant allowlists, approved assets, frequency limits, and rate limiting are all checked before any funds move.

5

On-chain settlement via ERC-4337

If approved, a UserOperation is submitted via the ERC-4337 bundler and executed on Base.

6

Retry with receipt

The Receipt Indexer records the tx hash. Brain replays the original HTTP request with X-402-Receipt. The server verifies and serves the resource.

Example Handler

handler.ts
async function handle402(response, agentId) {
  const header = response.headers['X-402-Payment'];
  const requirement = JSON.parse(header);

  const intent: PaymentIntent = {
    agentId,
    resourceUri: response.request.url,
    amount: requirement.amount,
    asset: requirement.asset,
    merchant: requirement.merchant,
    expiry: requirement.expiry,
    nonce: requirement.nonce,
  };

  const approval = await policyEngine.evaluate(intent);
  if (!approval.allowed) throw new Error('Payment not authorized');

  const txHash = await accountAbstraction.pay(intent, approval);
  await receiptIndexer.record(agentId, intent, txHash);
  return retryRequestWithReceipt(response.request, txHash);
}

Security Guarantees

Mechanism
Protection

Nonces

Prevent replay attacks

Expiries

Prevent stale charges

Per-merchant budgets

Enforced via policies, not server-side trust

Receipt binding

Every payment linked to a specific HTTP request and on-chain tx hash

circle-info

Payment receipts are tied to specific HTTP requests and resources, providing end-to-end auditability from HTTP to on-chain settlement.

Common Use Cases

  • AI Inference — pay per call to model providers (OpenAI, Anthropic, etc.)

  • Data Feeds — real-time market data, oracles, or analytics endpoints

  • Agent-to-Agent — one Brain agent paying another for a sub-task or service

  • API Services — any HTTP endpoint that accepts x402 payment headers

Last updated