Stocks / ETFs / FX: coming soonData provided by CoinGecko
QuantX402powered by KronosKronos Guide $47

← Blog

How an AI agent pays $0.02 for a forecast with x402

2026-10-11 · x402, ai-agents, usdc, base, solana, api, tutorial

Status: QuantX402 payments are live on Base and Solana mainnet in real USDC, settled through the Coinbase CDP facilitator. Each call costs real money, so start with the free preview endpoints and fund your agent's wallet with a small balance.

Most APIs make you sign up, get a key and add a card before your first call. That doesn't work for an AI agent in the middle of a task. x402 fixes this by reviving an old HTTP status code: 402 Payment Required. The server says what it costs, the agent pays in USDC, and the data comes back on the retry. There's no account and no API key.

Here's the whole loop against our real endpoint, GET https://quantx402.app/api/v1/forecast.

Step 1: Call it without paying

curl -i "https://quantx402.app/api/v1/forecast?symbol=BTC-USD&tf=1h"

The response is:

HTTP/2 402
content-type: application/json
payment-required: eyJ4NDAyVmVyc2lvbiI6MiwiZXJyb3IiOiJQYXltZW50IHJlcXVpcmVkIi...

The body is an empty {}. Everything is in the PAYMENT-REQUIRED header.

Step 2: Read the price

The header is base64-encoded JSON. Decoded (captured Oct 11 2026 on mainnet, trimmed):

{
  "x402Version": 2,
  "error": "Payment required",
  "resource": {
    "url": "https://quantx402.app/api/v1/forecast?symbol=BTC-USD&tf=1h",
    "serviceName": "QuantX402",
    "mimeType": "application/json"
  },
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:8453",
      "amount": "20000",
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "payTo": "0x2b79541911a436a83074eb3a38a920042524db96",
      "maxTimeoutSeconds": 300,
      "extra": { "name": "USD Coin", "version": "2" }
    }
  ]
}

What it means:

The same requirements are published ahead of time in /.well-known/x402 and /openapi.json, so an agent can check the price before it calls.

Step 3: Sign and retry

The client picks one option from accepts, signs a USDC payment for that amount with its wallet, and repeats the same request with the signed payment in a PAYMENT-SIGNATURE header. A facilitator checks the signature and settles the payment on-chain. QuantX402 uses the Coinbase CDP facilitator.

Step 4: Get the JSON

On success you get 200 with the fact list, plus a PAYMENT-RESPONSE header that holds the settlement receipt (including the transaction hash). The body has the fields from the free sample, plus per-step percentiles, p_close_above strike shares, age_minutes and stale:

{
  "symbol": "BTC-USD", "timeframe": "1h", "model": "Kronos-small",
  "as_of": "[AS_OF]", "horizon_end": "[HORIZON_END]",
  "direction": "[UP|DOWN|NEUTRAL]", "prob_up": "[0..1]",
  "expected_move_pct": "[X.XX]", "band_80_pct": ["[LO]", "[HI]"],
  "invalidation_level": "[PRICE or null]", "confidence": "[LOW|MEDIUM]",
  "band_calibrated": false,
  "disclaimer": "Probabilistic model output for research and education. Not financial advice. ..."
}

To see real values without paying, call the free GET /api/v1/sample?symbol=BTC-USD&tf=1h. It returns the same fact list, at least 2 hours old.

You're never charged for errors. The payment only settles if the handler returns a status below 400. An unsupported symbol (400 INVALID_SYMBOL), no forecast yet (404), or a forecast that's 2+ candles old (503 FORECAST_STALE) all return without settling.

The client, in about 20 lines

This is the standard client pattern (@x402/fetch v2). The wrapper handles steps 1–4: it sees the 402, picks the option you registered, signs, retries, and hands you the final response.

// npm i @x402/fetch @x402/core @x402/evm viem
// Pays real USDC on Base mainnet. Use a dedicated agent wallet with a small balance.
import { wrapFetchWithPayment, x402Client, decodePaymentResponseHeader } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY); // never hard-code keys
const client = new x402Client();
client.register("eip155:8453", new ExactEvmScheme(account));     // Base mainnet

const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://quantx402.app/api/v1/forecast?symbol=BTC-USD&tf=1h");

console.log(res.status);                      // 200 when paid
const facts = await res.json();
console.log(facts.direction, facts.prob_up, facts.band_80_pct, facts.invalidation_level);

const receipt = res.headers.get("PAYMENT-RESPONSE");
if (receipt) console.log(decodePaymentResponseHeader(receipt)); // settlement details

Solana payments are live too. To pay from Solana, register ExactSvmScheme from @x402/svm/exact/client with a Solana signer for solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp. Only register the networks you want the client to use.

Before you put this in an agent:

Why this matters if you build agents

The same pattern works for any API. If your agent or service does something useful, x402 lets other agents pay for it per call without you building accounts, billing or key management. QuantX402 is one worked example, and the free guide shows the client side in full.

QuantX402 forecasts are experimental model output (not calibrated; track record is public) for research and education: informational, not financial advice. Payments are live in USDC on Base and Solana mainnet.

Forecasts are probabilistic model output for research and education. Not financial advice.