How an agent checks it got what it paid for: signed receipts
Every settled paid answer this server sends carries a receipt it signs: a compact JWS (EdDSA over Ed25519) whose record names the request, a digest of the exact answer bytes, the price, the rail, the network, the payer and the settlement. Your agent checks it against the published key, offline or with one free call, and keeps it as proof of what it bought.
Where the receipt arrives
- A whole answer: the
Agent402-Receiptresponse header. - A server-sent event stream: a final comment line,
: agent402-receipt <receipt>, after the last byte. Event-stream parsers skip comments, so a client that reads only events is unaffected. - Any stream, with
TE: trailerson HTTP/1.1: anAgent402-Receipttrailer. - Any other stream: the head names
X-Agent402-Receipt-Url, andGET /api/receipt/<key>returns the receipt once the answer finished. The key is a random token only that head names.
A 4xx or 5xx answer, a payment that did not settle, and a free or trial answer carry no receipt.
What it says
The receipt is <header>.<record>.<signature>, each part base64url. The
header names the key (kid) and the type agent402-receipt+jws. The record:
| Field | Meaning |
|---|---|
method, path, slug |
the call that was paid for |
requestSha256 |
sha256 of "<METHOD> <path>[?<query>]\n" followed by the JSON request body (- when there is none) |
responseSha256 |
sha256 of the answer bytes, before any content encoding |
priceUsd |
the price paid |
rail, network |
how it was paid: x402, MPP, a credits key or a card |
payer, settlement |
who paid, and the settlement reference (an on-chain transaction for a wallet payment) |
iat, id, replay |
when it was signed, its id, and whether the answer was a replay of an earlier paid one |
Check it with one free call
Send the receipt to POST /api/receipts/verify, with the answer and the
request if you want those checked too:
curl -s -X POST https://agent402.tools/api/receipts/verify \
-H 'Content-Type: application/json' \
-d '{"receipt":"<the Agent402-Receipt value>","body":"<the answer text>",
"request":{"method":"POST","path":"/api/hash","body":{"text":"hi"}}}'
# {"valid":true,"reason":null,"kid":"…","checks":{"signature":true,"keyValidAtIssue":true,"response":true,"request":true},"record":{…}}
body and request are optional: without them the check covers the
signature and the key's validity on the day it was signed. With them it also
proves the answer you hold is the one that was paid for. A failed check names
its reason (bad_signature, unknown_kid, response_mismatch,
request_mismatch and the rest).
Check it offline
The public keys are at /.well-known/agent402-receipt-key.json. Fetch them once and check every receipt locally:
import { createPublicKey, verify, createHash } from "node:crypto";
const [head, body, sig] = receipt.split(".");
const { kid } = JSON.parse(Buffer.from(head, "base64url"));
const record = JSON.parse(Buffer.from(body, "base64url"));
const doc = await (await fetch("https://agent402.tools/.well-known/agent402-receipt-key.json")).json();
const key = doc.keys.find((k) => k.kid === kid);
const pub = createPublicKey({ key: { kty: "OKP", crv: "Ed25519", x: key.x }, format: "jwk" });
const signed = verify(null, Buffer.from(`${head}.${body}`), pub, Buffer.from(sig, "base64url"));
const sameAnswer = createHash("sha256").update(answerBytes).digest("hex") === record.responseSha256;
Also check that record.iat falls inside the key's validFrom and
validUntil. An earlier key stays published after a rotation, so an old
receipt still verifies.
When a paid call fails
An x402 payment settles only after a successful answer, so an x402 call that answers an error is not charged and carries no receipt.
Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded.
A charge that is not matched by a delivered answer is recorded as owed and
repaid after the payment is proven on chain; GET /api/refunds?tx=<transaction>
reads its status for an EVM transaction.