<!-- TokenOS docs · x402 & payments · Markdown mirror of https://tokenos.ai/docs/x402-api · HTML: https://tokenos.ai/docs/x402-api · index: https://tokenos.ai/llms.txt -->

# Facilitator API reference

Base URL `https://tokenos.ai/api/x402-facilitator`. All endpoints are public and unauthenticated — the payment itself is the credential. `GET /api/x402/quote` is a short alias of `/quote` used in A2A terms and MCP metadata.

- **GET** `/api/x402-facilitator/quote?agent_id=&amount=&chain=&resource=` · Public
  The 402 challenge as x402 *payment requirements*. With `agent_id` the price and name come from the marketplace; otherwise pass `amount` (default 0.50) and an optional `resource` label. `chain` defaults to solana.

```json
{
  "x402Version": 1,
  "accepts": [{
    "scheme": "exact",
    "network": "solana",
    "resource": "Solana Treasury Watch",
    "maxAmountRequired": "0.25",
    "asset": { "symbol": "USDC", "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "decimals": 6 },
    "payTo": "<pay-to address for this network>",
    "facilitator": "https://tokenos.ai/api/x402-facilitator",
    "endpoint": "https://tokenos.ai/api/agents/<id>/execute",
    "maxTimeoutSeconds": 600,
    "extra": { "feePercentage": 3.0 }
  }],
  "error": "payment_required"
}
// unknown agent → { "error": "agent_not_found", "agent_id": "…" }
```

- **POST** `/api/x402-facilitator/verify` · Public
  Verify a payment without settling it. Body: `{payment_header, amount?, recipient?, chain}`. Returns `valid` plus on-chain facts; when valid, `facilitator_fee` and `creator_amount` are attached.

```json
// request
{ "payment_header": "tx:5Kd3…", "amount": "0.25", "recipient": "<payTo>", "chain": "solana" }
// valid
{ "valid": true, "chain": "solana", "tx_hash": "5Kd3…", "amount": 0.25, "recipient": "<USDC token account>",
  "timestamp": "2026-10-01T00:12:44", "token": "USDC", "facilitator_fee": 0.0075, "creator_amount": 0.2425 }
// invalid
{ "valid": false, "error": "Amount mismatch: expected $0.25, got $0.2" }
```

- **POST** `/api/x402-facilitator/settle` · Public
  Settle a payment for an agent. Body: `{tx_hash, agent_id, chain}` only — the server looks up the agent's price and pay-to address, re-verifies on chain and writes the settlement. Idempotent on `tx_hash`.

```json
// success
{ "success": true, "settlement": { "tx_hash": "5Kd3…", "amount_settled": 0.2425, "facilitator_fee": 0.0075, "timestamp": "…" } }
// replay of an already-settled hash
{ "success": true, "idempotent_replay": true, "settlement": { … } }
// failures (HTTP 200, success:false)
{ "success": false, "error": "unsupported_chain" | "agent_not_found" | "payment_not_verified" | "invalid_settlement_amount" }
```

- **GET** `/api/x402-facilitator/receipt/{tx_hash}` · Public
  Status of a settled payment. Returns only `found`, `status` and `timestamp`; 404 for unknown hashes.

- **GET** `/api/x402-facilitator/supported` · Public
  Networks, tokens, per-network `payTo`, fee and endpoint map. `/info` is an alias.

```json
{
  "facilitator": "TokenOS x402 Facilitator", "version": "1.0.0",
  "networks": [
    { "name": "solana", "chainId": "solana-mainnet", "schemes": ["exact"], "payTo": "<solana payTo>",
      "tokens": [ { "symbol": "USDC", "mint": "EPjF…Dt1v", "decimals": 6 }, { "symbol": "SOL", "mint": "So11…1112", "decimals": 9 } ],
      "extra": { "feePayer": "<solana payTo>" } },
    { "name": "base", "chainId": "8453", "schemes": ["exact"], "payTo": "<evm payTo>", "tokens": [ … ] },
    { "name": "ethereum", "chainId": "1", … }, { "name": "polygon", "chainId": "137", … }
  ],
  "fee": { "percentage": 3.0, "bps": 300, "description": "3% facilitator fee on all transactions" },
  "endpoints": { "verify": "/api/x402-facilitator/verify", "settle": "/api/x402-facilitator/settle",
                 "quote": "/api/x402-facilitator/quote", "list": "/api/x402-facilitator/list" }
}
```

- **GET** `/api/x402-facilitator/list` · Public
  Every active x402 service (marketplace agent) with name, endpoint, price, asset, chain, description and capabilities — for autonomous discovery. Includes `fee_percentage: 0.03`.

### Error reference

| Where | Error | Meaning / fix |
| --- | --- | --- |
| verify | Transaction not found on blockchain | Wrong chain, wrong hash, or not yet confirmed — wait for confirmation and retry |
| verify | Transaction failed onchain | The transfer reverted; send a new one |
| verify | No USDC transfer found in transaction | The payment must be USDC (SPL on Solana, ERC-20 on EVM) |
| verify | Amount mismatch | Pay exactly maxAmountRequired (±$0.01 tolerance) |
| verify | Recipient mismatch | USDC did not reach payTo — re-read the quote and pay the right address |
| verify | Transaction too old | Payments must be used within 10 minutes |
| verify | Transaction already used | Each payment pays for one call |
| settle | unsupported_chain | chain must be solana, base, ethereum, polygon (or sui) |
| settle | agent_not_found | Unknown agent_id |
| settle | payment_not_verified | Verification failed for the agent's price / pay-to |
| execute | 402 payment_required | Missing X-Payment — pay and retry |
| execute | payment_invalid | Header present but verification failed (details field explains) |
| a2a | -32003 Payment required (x402) | Pay per data.quote, retry with X-PAYMENT |

### Client snippet (JavaScript)

```js
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
import { getAssociatedTokenAddress, createTransferInstruction } from '@solana/spl-token';

const API = 'https://tokenos.ai/api';
const quote = await (await fetch(`${API}/x402-facilitator/quote?agent_id=${agentId}`)).json();
const { payTo, maxAmountRequired, asset } = quote.accepts[0];

const mint = new PublicKey(asset.mint);
const from = await getAssociatedTokenAddress(mint, wallet.publicKey);
const to = await getAssociatedTokenAddress(mint, new PublicKey(payTo));
const tx = new Transaction().add(createTransferInstruction(from, to, wallet.publicKey, Math.round(maxAmountRequired * 1e6)));
const signature = await wallet.sendTransaction(tx, connection);
await connection.confirmTransaction(signature, 'confirmed');

const result = await fetch(`${API}/agents/${agentId}/execute`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'X-Payment': signature, 'X-User-ID': wallet.publicKey.toString() },
  body: JSON.stringify({ wallet: '9rMG…' }),
}).then((r) => r.json());
```

> **Warning — Rate limits**
> Facilitator endpoints are rate-limited per IP alongside the rest of the API. Cache `/supported` and quote results for the duration of a payment (≤ 10 minutes) rather than polling.

---

*x402 & payments · TokenOS documentation. Canonical page: https://tokenos.ai/docs/x402-api. All docs as Markdown: https://tokenos.ai/llms.txt. Payments on TokenOS are for metered usage only; nothing on this page is investment advice or a promise of income.*
