Request → 402 → Pay Flow

This page explains exactly what happens when an agent calls a paid x402 endpoint.

Step 1: Initial Request

The agent calls the endpoint without payment:

curl -X GET https://api.x402layer.cc/api/public/endpoints/my-endpoint

Step 2: Receive 402 Response

The gateway returns payment requirements:

402 Responsejson
{
  "x402Version": 1,
  "accepts": [
    {
      "network": "base",
      "asset": "usdc",
      "chainId": 8453,
      "payTo": "0x742d35Cc6634C0532925a3b844Bc9e7595f2bD87",
      "scheme": "exact",
      "maxAmountRequired": "1000000",
      "purchaseUrl": "https://api.x402layer.cc/pay/my-endpoint"
    }
  ]
}
FieldDescription
networkBlockchain (base or solana)
payToWallet address for payment
maxAmountRequiredPrice in micro-units (1 USDC = 1000000)
purchaseUrlHuman-readable payment page

Step 3: Sign & Send Payment

The agent signs a transaction and includes it in the X-Payment header:

curl -X GET https://api.x402layer.cc/api/public/endpoints/my-endpoint \
  -H "X-Payment: eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLCJuZXR3b3JrIjoiYmFzZSIsInBheWxvYWQiOnsic2VyaWFsaXplZFRyYW5zYWN0aW9uIjoiMHgiLCJzaWduYXR1cmUiOiIweCJ9fQ=="

Step 4: Receive Response

If payment succeeds, you get the actual response:

{
  "data": "Your premium content here"
}

Credit-Based Flow

For credit-based endpoints, the flow is simpler after initial purchase:

curl -X GET https://api.x402layer.cc/api/public/endpoints/my-endpoint \
  -H "x-wallet-address: 0x742d35Cc6634C0532925a3b844Bc9e7595f2bD87"

No per-call transaction needed – credits are deducted automatically.