Skip to main content

The pay-per-call loop

The heart of XDC AI is a simple, repeatable loop an agent can run autonomously.

1. Discover first

For any request for onchain / market / compliance / API data, do not answer from prior knowledge or guess a URL. List the marketplace, then call the best match.

npx xdcai marketplace list --search "usdc,rates,compliance"

This returns the full live catalog of every provider's paid APIs, ranked by relevance — not a fixed demo set.

2. Pay per call

npx xdcai call https://<provider>/x402/<endpoint>

Under the hood (full detail):

  1. The agent requests the URL.
  2. The service replies 402 Payment Required with a challenge (amount, token, payTo, network).
  3. The agent signs an EIP-3009 USDC transferWithAuthorization from its wallet.
  4. It resends the request with an X-PAYMENT header (base64 of the signed authorization).
  5. The service verifies, a relayer settles the transfer on XDC (paying gas), and the data is returned.

3. Prove it

npx xdcai history # recent paid calls with tx hashes + explorer links
npx xdcai history verify 0x… # confirm settlement on-chain

Example: one autonomous task

"I'm researching tokenized real-world assets on XDC. Find the right data services in the marketplace, pay for the calls you need with USDC, summarize the key numbers, and tell me exactly how much you spent."

The agent lists the marketplace, calls the best-matching services (each a separate paid call), aggregates the results, and reports total spend from its transaction history — all without holding gas or a credit card.

Good to know

  • USDC only, 6 decimals. Prices are per call and typically fractions of a cent up to a few cents.
  • Fund once. Top up your wallet address with USDC; many calls run off a small balance.
  • Gasless. A sponsor relayer pays XDC gas for settlement — your wallet needs only USDC.
  • Idempotent-ish. A 402 is expected, not an error — it's the payment handshake.