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.
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.
- Create an account. You get 1,000 test USDC in your wallet.
- Open Wallet & collateral and deposit some of it into the vault.
- Open Agent keys and create a key. The private key is generated in your browser.
- Open the Playground and send a request. You will see the 402, the signed guarantee and the 200 in the log.
- Open Cycles & settlement and close the cycle to settle on-chain.
To see the raw 402 from a terminal:
curl -i {origin}/x402/weather?city=OsloCore 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.
<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:
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:
- Add
netquill-creditto your/supportedresponse. - In your settle handler, forward the guarantee and signature to Netquill and return the certificate to the seller.
- 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.
| Cost | Amount on testnet |
|---|---|
| Fee | 0.5% of the net amount settled |
| Gas | 0.01 USDC per on-chain transaction |
| Per request | Nothing |
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.
domain = { name: "Netquill", version: "1", chainId, verifyingContract: VAULT }
Voucher(address payer, address recipient, uint256 cumulativeAmount)Paying
- Deposit collateral:
approvethendeposit(amount). - Authorise your agent key:
authorizeSigner(agent). - On a 402, read
GET /api/chain/state?payer=&recipient=, add the price tocumulative, sign, and retry withX-PAYMENT= base64 of{ scheme: "netquill-evm", voucher, signature }.Netquill.EvmClientin the SDK does this for you. Passnetwork: "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.
| Function | What 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.store | Helpers for keeping private keys in localStorage. |
Guarantee format
{
"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).
Body: { name, email, password }. Creates an account with 1,000 test USDC.
Body: { email, password }.
Your balances, keys and settings, or { user: null }.
Adds 1,000 test USDC. Once every 30 seconds.
Body: { amount }. Moves USDC from wallet to collateral.
Body: { amount }. Starts a withdrawal with a 20 second grace period.
Body: { label, jwk } where jwk is a public P-256 key.
Preview of the current cycle, netted per counterparty.
Nets and settles the current cycle.
Body: { name, price, enabled }.
Body: { count }. Other agents pay your endpoint.
Recent testnet transactions.
Checks a certificate.
The demo paid APIs and their prices.
Paid endpoints: weather, search, images and u-<account id>.
Errors
| Status | Meaning |
|---|---|
| 400 | The request or guarantee is malformed. |
| 401 | Not signed in, unknown key or invalid signature. |
| 402 | Payment needed, or the guarantee doesn't cover the price, has expired or exceeds your available credit. |
| 409 | The request ID was already used. |
| 429 | Too 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.jsonnext to the server.
Questions? Contact support.