AIXBT Docs

x402

Purchase API key passes via the x402 protocol

Purchase an API key pass for full API access over a set period. Pays with USDC on Base via the x402 protocol, no registration or account needed.

API Key Generation

Purchase time-limited API keys via x402. No account or registration needed. Pay with USDC on Base and receive an API key instantly. These keys are intended for personal use only.

EndpointPeriodPrice
POST /v2/api-keys/1d1 day$10
POST /v2/api-keys/1w1 week$50
POST /v2/api-keys/4w4 weeks$100

Save your API key immediately. The key is returned only once in the response. It cannot be retrieved again. Make sure your agent or application stores it before proceeding.

Example response:

{
  "status": 201,
  "data": {
    "apiKey": "a1b2c3d4e5f6...",
    "expiresAt": "2026-03-27T08:00:00.000Z",
    "period": "4w",
    "type": "x402",
    "scopes": ["mcp", "projects"],
    "rateLimit": {
      "requestsPerMinute": 30,
      "requestsPerDay": 10000
    },
    "warning": "Save this API key now. It will not be shown again."
  }
}

Once you have a key, use it with the REST API endpoints (/v2/...) via the x-api-key header. The key is intended for personal use only, with rate limits of 30 req/min and 10k req/day.

To check your key's expiration and metadata at any time, call GET /v2/api-keys/info.

How It Works

  1. Make a request to an x402 key-pass endpoint
  2. Receive a 402 Payment Required response with payment details
  3. Authorize the payment on-chain with your wallet
  4. Retry the request with payment proof
  5. Receive an API key

The x402 helper libraries handle steps 2-4 automatically. You make a single request and get the response. Payment happens transparently.

Integration

Use the @x402/fetch or @x402/axios package to wrap your HTTP client with automatic payment handling:

npm install @x402/fetch @x402/evm viem
import { wrapFetchWithPayment, x402Client, x402HTTPClient } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

// Create a wallet signer (using your private key)
const signer = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY);

// Create x402 client and register EVM scheme
const client = new x402Client();
registerExactEvmScheme(client, { signer });

// Wrap the fetch function with payment handling
const fetchWithPayment = wrapFetchWithPayment(fetch, client);

// Purchase a 1-day API key pass
fetchWithPayment("https://api.aixbt.tech/x402/v2/api-keys/1d", {
  method: "POST",
})
  .then(async (response) => {
    const data = await response.json();
    console.log("API key:", data);

    // Get payment receipt from response headers
    if (response.ok) {
      const httpClient = new x402HTTPClient(client);
      const paymentResponse = httpClient.getPaymentSettleResponse((name) =>
        response.headers.get(name)
      );
      console.log("Payment settled:", paymentResponse);
    }
  })
  .catch((error) => {
    console.log(error);
  });

Payment Settlement

Payments are only settled when the server returns a successful response (2xx status). If key generation fails, your payment is not charged:

  • 400 errors -- Invalid pass duration or request shape
  • 500 errors -- Server encountered an internal error

This means you only pay for successful key-pass purchases.

Example error response (no payment charged):

{
  status: 400,
  error: "Invalid duration",
  data: {
    message: "Use 1d, 1w, or 4w."
  }
}

Resources

On this page