Pay per call with x402

An agent with no account can buy one chat completion and pay for it in USDC. It needs no API key, no workspace and no balance. The payment is the only credential.

The route uses x402, an open protocol for payment over HTTP. Any x402 client can pay it. The exchange runs the call through the same auction as an ordinary request.

The route

POST https://router.inference.ai.exchange/x402/v1/chat/completions
Item Value
Network Base (eip155:8453)
Asset USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)
Scheme exact
Protocol x402 version 2

The facilitator pays the gas, so the wallet of the agent needs only USDC.

The payment flow

  1. Send the request with no payment. The exchange answers 402 Payment Required with the price.
  2. Sign a payment for that price with the wallet of the agent.
  3. Send the same request again, with the payment in the PAYMENT-SIGNATURE header.
  4. The exchange checks the payment and runs the call.
  5. If the call succeeds, the payment settles. The answer has a PAYMENT-RESPONSE header with the transaction.

An x402 client library does steps 2 and 3 for you.

The price

The 402 answer has the price in the PAYMENT-REQUIRED header and in the body. The amount is in USDC units of one millionth of a dollar, so 1000 is $0.001.

curl -i https://router.inference.ai.exchange/x402/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "architect.auto", "messages": [{"role": "user", "content": "Say hello."}], "max_tokens": 64}'
{
  "x402Version": 2,
  "error": "PAYMENT-SIGNATURE header is required",
  "resource": {
    "url": "https://router.inference.ai.exchange/x402/v1/chat/completions",
    "mimeType": "application/json",
    "serviceName": "Architect",
    "iconUrl": "https://inference.ai.exchange/favicon.png"
  },
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:8453",
      "amount": "1000",
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "payTo": "0x…",
      "maxTimeoutSeconds": 600
    }
  ]
}

The price is the price cap of the offer that the exchange tries first for a request of this size. A larger max_tokens or a longer prompt gives a higher price. The price changes with the book, so ask again before each call.

The amount that you pay is the price cap of the call. The exchange never spends more than that amount. You pay the full amount, not the measured use. An account pays only for the tokens used. See Fees.

When you pay nothing

The payment settles only after the call succeeds. You pay nothing when:

Limits

For limits that are larger, streaming or purchasing rules, make an account. See the Quickstart.

Errors

Status Code Cause
400 invalid_request The body is not JSON, has no model or messages, streams or asks for too many tokens.
400 invalid_payment The PAYMENT-SIGNATURE header cannot be read.
402 none A price, or a payment that the exchange refused. error gives the reason. Pay again.
402 settlement_failed The call ran, but the payment did not settle.
404 no_offer No offer serves the model now.
404 x402_off The exchange sells nothing over x402 now.
503 x402_paused Paid calls are paused until the next UTC day.
503 facilitator_unavailable The exchange cannot reach the facilitator. You paid nothing.

The other errors of a call are the same as for Chat Completions. See Errors.