Access Methods

x402

x402 is the pay-per-request access path for clients that want to satisfy a payment challenge instead of presenting a Rungate API key.

#Overview

If a request arrives without normal authentication, Rungate can return a 402challenge. x402 clients answer that challenge by sending a payment-signatureheader and receive a PAYMENT-RESPONSE header on success. For the broader protocol, see x402 documentation.

Current payment rail:

  • Network: Base mainnet (eip155:8453)
  • Settlement asset: USDC
  • Gas is sponsored by the OpenMid facilitator, so the paying wallet only needs USDC.
  • Rungate can advertise x402 and MPP on the same unpaid request.

#Challenge flow

An unpaid request returns 402. Depending on environment configuration, the same response may also advertise the MPP challenge headers. x402 clients should readPAYMENT-REQUIRED and answer with payment-signature.

HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: <base64-encoded x402 challenge>
Content-Type: application/json

{
  "scheme": "exact",
  "network": "eip155:8453",
  "asset": "USDC",
  "maxAmountRequired": "...",
  "resource": "https://api.rungate.ai/v1/chat/completions"
}

After the client pays and retries, successful responses include PAYMENT-RESPONSE.

#Client example

If you are using an x402-aware fetch client, the challenge handling can be wrapped around a normal fetch call.

import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";

const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [
    {
      network: "eip155:*",
      client: new ExactEvmScheme(account, { rpcUrl: process.env.X402_RPC_URL! }),
    },
  ],
});

const res = await fetchWithPayment("https://api.rungate.ai/v1/chat/completions", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "deepseek/deepseek-v3.2",
    messages: [{ role: "user", content: "Say hello." }],
  }),
});
If you are using OpenClaw and want request classification plus automatic routing, use LLM router. It can also pay x402 challenges on retry.

#Troubleshooting

  • 400 on paid retry usually means the payment-signature header is malformed or does not match the challenge.
  • 402 means payment was not satisfied. This is different from 401, which is the API key auth failure path.
  • If you prefer the standardized payment-auth flow, see MPP.