Documentation

Netquill developer docs

Netquill is a credit and clearing layer for x402. A payer deposits collateral once, signs a guarantee for each paid request, and settles the net balance with each counterparty at the end of a cycle. Sellers keep the normal HTTP 402 flow.

This site runs a complete testnet you can use right now. Everything below works against this server: the endpoints, the SDK and the examples.

Who it is for

  • API providers who want to charge per request without accounts, invoices or prepaid balances.
  • AI agents that call many paid services during a task and want to settle once.
  • Facilitators that want to offer credit payments to the sellers they serve.

Quickstart

You can make your first paid request in about two minutes.

  1. Create an account. You get 1,000 test USDC in your wallet.
  2. Open Wallet & collateral and deposit some of it into the vault.
  3. Open Agent keys and create a key. The private key is generated in your browser.
  4. Open the Playground and send a request. You will see the 402, the signed guarantee and the 200 in the log.
  5. Open Cycles & settlement and close the cycle to settle on-chain.

To see the raw 402 from a terminal:

Terminal
curl -i {origin}/x402/weather?city=Oslo

Core concepts

Collateral

Funds you deposit into the vault. Collateral backs your guarantees and earns interest (5% APY on testnet). Your available credit is your collateral minus what open guarantees already use and minus pending withdrawals.

Guarantee

A message you sign that says you will pay a specific amount to a specific recipient for a specific request. Netquill checks the signature and your available credit, then returns a certificate.

Certificate

Proof that Netquill accepted a guarantee. Anyone can check it at GET /api/certificates/:id.

Cycle

A period during which guarantees pile up. When it closes, Netquill adds up what you owe and are owed per counterparty and settles one net amount each, on-chain.

Paying for requests

Load the SDK, create a key and register its public half. Then use client.fetch instead of fetch.

agent.js
<script src="/js/sdk.js"></script>

// 1. Create a P-256 key in the browser
const key = await Netquill.createKey();

// 2. Register the public key (you must be signed in)
const res = await fetch('/api/keys', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ label: 'My agent', jwk: key.publicJwk })
});
const { key: registered, user } = await res.json();

// 3. Pay for requests
const client = new Netquill.Client({
  payer: user.id,
  keyId: registered.id,
  privateJwk: key.privateJwk,
  onEvent: e => console.log(e.type, e.text)
});

const r = await client.fetch('/x402/search?q=agent+payments');
console.log(await r.json(), r.receipt);

The client handles the whole exchange: it reads the 402, picks the netquill-credit option, signs a guarantee and retries with an X-PAYMENT header.

Selling an API

A paid endpoint answers the first request with 402 and the price:

Response
HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "x402Version": 1,
  "error": "Payment required",
  "accepts": [{
    "scheme": "netquill-credit",
    "network": "netquill-testnet",
    "asset": "USDC",
    "amount": 0.002,
    "payTo": "p_skycast",
    "resource": "/x402/weather",
    "maxTimeoutSeconds": 120
  }]
}

The retry carries X-PAYMENT: base64-encoded JSON with the guarantee and its signature. If it checks out, the endpoint responds with 200 and an X-PAYMENT-RESPONSE header containing the guarantee ID and certificate.

Every account on this testnet also has its own paid endpoint at /x402/u-<your account id>. Set its price in Sell your API.

Facilitators

If you run an x402 facilitator, you can offer credit payments to every seller you serve:

  1. Add netquill-credit to your /supported response.
  2. In your settle handler, forward the guarantee and signature to Netquill and return the certificate to the seller.
  3. Let cycles settle on their schedule, or close them through the API.

Sellers keep pointing at your endpoint. Netquill runs in the background.

Cycles and settlement

When a cycle closes, Netquill groups your open guarantees by counterparty. For each one it subtracts what you owe from what you are owed. If the result is negative you pay it, if positive you receive it. One transaction is written per counterparty with a non-zero balance.

If your wallet can't cover a payment, the difference is taken from your collateral. That is what makes the guarantee safe for the seller.

CostAmount on testnet
Fee0.5% of the net amount settled
Gas0.01 USDC per on-chain transaction
Per requestNothing

On-chain: Robinhood Chain and Elysium

The NetquillVault contract can be deployed on several EVM networks at once. Netquill supports Robinhood Chain (chain ID 4663, gas in ETH) and Elysium by Kinetiq (chain ID 99901, gas in HYPE), plus their testnets. Each network has its own vault and its own collateral. Payments use the netquill-evm scheme: the agent signs an EIP-712 voucher for the running total it owes a seller, and nothing is written on-chain per request.

EIP-712
domain = { name: "Netquill", version: "1", chainId, verifyingContract: VAULT }
Voucher(address payer, address recipient, uint256 cumulativeAmount)

Paying

  1. Deposit collateral: approve then deposit(amount).
  2. Authorise your agent key: authorizeSigner(agent).
  3. On a 402, read GET /api/chain/state?payer=&recipient=, add the price to cumulative, sign, and retry with X-PAYMENT = base64 of { scheme: "netquill-evm", voucher, signature }. Netquill.EvmClient in the SDK does this for you. Pass network: "eip155:4663" or "eip155:99901" to choose where to pay.

A 402 response lists one netquill-evm option per network the server runs, each with its own network, payTo and vault. Add ?net=<network> to the endpoints below to pick a network.

Settling

Anyone can call claim(voucher, sig) or settlePair(ab, sigAB, ba, sigBA). The second one offsets two-way debts and moves only the net. Withdrawals and key revocations wait for the withdrawal delay so sellers always have time to claim.

Endpoints

GET /api/chain/config, GET /api/chain/state, GET /api/chain/account?address=, GET /api/chain/positions, POST /api/chain/link, POST /api/chain/settle.

Server status: checking…

Browser SDK

The SDK is a single file with no dependencies: /js/sdk.js. It uses the WebCrypto API.

FunctionWhat it does
Netquill.createKey()Generates an ECDSA P-256 key pair. Returns { publicJwk, privateJwk }.
Netquill.signGuarantee(privateJwk, g)Signs a guarantee and returns a base64 signature.
Netquill.canonical(g)The exact bytes that get signed.
new Netquill.Client(opts)Payment-aware fetch. Options: payer, keyId, privateJwk, onEvent.
Netquill.storeHelpers for keeping private keys in localStorage.

Guarantee format

Guarantee
{
  "scheme": "netquill-credit",
  "version": 1,
  "payer": "u_…",              // your account id
  "keyId": "k_…",              // registered key
  "recipient": "p_skycast",    // payTo from the 402
  "amount": 0.002,             // at least the quoted price
  "asset": "USDC",
  "requestId": "uuid-v4",      // unique, prevents replays
  "resource": "/x402/weather",
  "timestamp": 1764240000000   // ms, must be within 2 minutes
}

The signature is ECDSA P-256 with SHA-256 over JSON.stringify of the fields as [key, value] pairs in the order above, encoded as raw r||s in base64.

HTTP API

All endpoints return JSON. Endpoints marked "session" need you to be signed in (cookie).

POST/api/auth/signup

Body: { name, email, password }. Creates an account with 1,000 test USDC.

POST/api/auth/login

Body: { email, password }.

POST/api/auth/logout
GET/api/me

Your balances, keys and settings, or { user: null }.

POST/api/faucet session

Adds 1,000 test USDC. Once every 30 seconds.

POST/api/deposit session

Body: { amount }. Moves USDC from wallet to collateral.

POST/api/withdraw session

Body: { amount }. Starts a withdrawal with a 20 second grace period.

POST/api/withdraw/:id/finalize session
POST/api/withdraw/:id/cancel session
POST/api/keys session

Body: { label, jwk } where jwk is a public P-256 key.

DELETE/api/keys/:id session
GET/api/guarantees?status=open|settled session
GET/api/cycle session

Preview of the current cycle, netted per counterparty.

POST/api/cycle/close session

Nets and settles the current cycle.

GET/api/settlements session
POST/api/seller session

Body: { name, price, enabled }.

POST/api/simulate/incoming session

Body: { count }. Other agents pay your endpoint.

GET/api/explorer?mine=1

Recent testnet transactions.

GET/api/certificates/:id

Checks a certificate.

GET/api/services

The demo paid APIs and their prices.

GET/api/status
GET/x402/:service

Paid endpoints: weather, search, images and u-<account id>.

Errors

StatusMeaning
400The request or guarantee is malformed.
401Not signed in, unknown key or invalid signature.
402Payment needed, or the guarantee doesn't cover the price, has expired or exceeds your available credit.
409The request ID was already used.
429Too many faucet requests.

Error bodies look like { "error": "Not enough available credit (12.5 USDC)" }.

Testnet limits

  • Test USDC has no value and the chain is simulated by this server.
  • Up to 10 signing keys per account.
  • Withdrawals have a 20 second grace period.
  • Data is stored in data/db.json next to the server.

Questions? Contact support.