Payments10 min read

x402 Payment Protocol: HTTP-Native Micropayments

Understanding x402 — the HTTP-native payment protocol integrated with KAMIYO. How AI agents pay for API calls and services using HTTP 402 status codes.

What is x402

The x402 payment protocol reimagines HTTP status code 402 ("Payment Required") as the foundation for native web payments. Originally reserved in the HTTP specification for future use, 402 has been adopted by x402 as a machine-readable signal that a resource requires payment before access is granted. For AI agents that interact with APIs, services, and data providers programmatically, x402 transforms payment from a cumbersome integration into a native part of the HTTP request-response cycle.

KAMIYO Protocol integrates x402 as the payment rail for AI agent micropayments, combining HTTP-native payment flows with on-chain settlement guarantees. This integration means AI agents can autonomously discover, pay for, and consume services without pre-negotiated billing agreements, API keys, or subscription plans.

HTTP-Native Payments

x402 makes payment a first-class HTTP citizen. An AI agent does not need a separate payment SDK, billing account, or pre-authorized wallet. It just makes an HTTP request, receives a 402 response with payment instructions, pays, and retries. The entire flow is stateless and composable.

The x402 Flow

Understanding x402 requires walking through the complete request-response cycle as experienced by an AI agent.

1. Initial Request

An AI agent makes a standard HTTP request to a paid endpoint — an API, a data feed, a compute service, or any resource that has opted into x402 payment.

GET /api/v1/market-analysis?ticker=SOL HTTP/1.1
Host: data-provider.example.com
Accept: application/json

2. Payment Required Response

The server responds with HTTP 402 and includes structured payment instructions in the response headers. These instructions specify the payment amount, accepted token mints, the recipient address, and a payment deadline.

HTTP/1.1 402 Payment Required
X-Payment-Amount: 100000
X-Payment-Token: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
X-Payment-Recipient: RecipientPubkey...
X-Payment-Network: solana
X-Payment-Deadline: 1719849600
X-Payment-ID: req_abc123

3. On-Chain Payment

The AI agent's x402-compatible wallet reads the payment instructions, constructs a Solana transaction, and executes the payment. If the payment is within the agent's pre-authorized limits, this happens autonomously. If it exceeds limits, the agent can route through KAMIYO escrow for additional protections.

// Agent's x402 handler
const payment = await x402Client.pay({
  amount: response.headers['x-payment-amount'],
  token: response.headers['x-payment-token'],
  recipient: response.headers['x-payment-recipient'],
  paymentId: response.headers['x-payment-id'],
});

4. Retry with Receipt

After payment confirms on Solana, the agent retries the original request with a payment receipt in the header. The receipt includes the transaction signature, which the server can verify on-chain.

GET /api/v1/market-analysis?ticker=SOL HTTP/1.1
Host: data-provider.example.com
Accept: application/json
X-Payment-Receipt: tx_signature_base58...
X-Payment-ID: req_abc123

5. Resource Delivery

The server verifies the payment on-chain (either directly or via a verification service) and, if confirmed, delivers the requested resource with a standard 200 response. The entire cycle completes in seconds, bounded primarily by Solana's confirmation time.

KAMIYO Integration: Trust for Micropayments

Raw x402 handles the payment mechanics, but it does not address the trust question: what if the service delivers poor-quality data after payment? What if the server accepts payment but does not deliver? This is where KAMIYO's integration adds value.

Escrow-Backed x402

For higher-value x402 transactions, agents can route payments through KAMIYO escrow rather than paying directly. The payment is locked in escrow, the service delivers, and funds release only after the agent confirms receipt. If the service fails to deliver (or delivers garbage data), the agent can dispute the transaction through KAMIYO's dispute resolution system.

Trust Layer Receipts

Every x402 payment processed through KAMIYO generates a deterministic trust receipt via the trust layer engine. These receipts create an auditable record of agent spending patterns, service provider delivery rates, and payment dispute frequencies. Over time, this data feeds into the Meishi reputation system, helping agents identify reliable service providers and avoid problematic ones.

Pre-Funded Channels

For high-frequency micropayments (an agent making hundreds of API calls per minute), creating individual on-chain transactions for each call is impractical. KAMIYO supports pre-funded payment channels where an agent deposits funds into an escrow-like account and draws down per call, with periodic on-chain settlement. This amortizes transaction costs while maintaining the trust guarantees of on-chain settlement.

Building x402-Compatible Services

Service providers can adopt x402 by adding payment middleware to their HTTP stack. The middleware intercepts incoming requests, checks for payment receipts, and either serves the resource or returns a 402 response with payment instructions. KAMIYO provides reference middleware implementations for common frameworks.

// Express middleware example
import { x402Middleware } from '@kamiyo/middleware';

app.use('/api/v1/premium', x402Middleware({
  amount: 100_000,        // 0.1 USDC
  token: USDC_MINT,
  recipient: serviceWallet.publicKey,
  verifyOnChain: true,    // Verify payment tx on Solana
}));

// Protected routes work normally after payment
app.get('/api/v1/premium/data', (req, res) => {
  res.json({ data: premiumAnalysis });
});

Why x402 Matters for the Agent Economy

The current internet payment infrastructure was designed for humans: subscription forms, credit card inputs, checkout flows. None of this works for autonomous AI agents. x402 flips the model by embedding payment into the protocol layer that agents already speak — HTTP. Combined with KAMIYO's trust infrastructure, it creates an economy where AI agents can autonomously discover, evaluate, pay for, and consume services with the same ease that they currently make API calls.

This is the foundation of the agent economy: a world where millions of AI agents transact with each other billions of times per day, each transaction secured by on-chain escrow, verified by independent oracles, and recorded as a trust receipt. x402 is the payment rail. KAMIYO is the trust rail. Together, they make it work.

Frequently Asked Questions

What is x402?

x402 is a payment protocol that uses the HTTP 402 "Payment Required" status code to enable native web payments. When an AI agent hits a paid endpoint, it receives a 402 response with payment instructions, pays automatically, and retries the request with a payment receipt.

How does x402 integrate with KAMIYO?

KAMIYO provides the settlement and trust layer for x402 payments. Payments are verified on-chain, and the escrow system can be used for larger transactions that require quality verification before final settlement.

Does x402 work with any blockchain?

x402 is blockchain-agnostic at the HTTP layer, but KAMIYO's integration leverages Solana for settlement. The protocol's sub-second finality and low fees make it ideal for the high-frequency micropayments that x402 enables.

Build with KAMIYO Protocol

Start integrating trust infrastructure into your AI agent applications.

Docs →