Below 400 means paid: the x402 settle gate across six adapters
An x402 seller verifies a payment, runs the handler, and then decides whether to take the money. Every official server adapter makes that decision the same way: a status below 400 means paid. We sent 42 paid requests through six adapter setups to see what that rule really charges for. One adapter billed a 500. Another took the money for a 204 and then told the buyer it had not paid.
Three pull requests opened on 2026-11-20 and 2026-11-21 prompted this. All three come from the same contributor, mortezashojaei, and each fixes one adapter: #4374 for Express, #4375 for Hono, #4366 for FastAPI. All three were open with zero reviews when we checked. Read one at a time, each looks like a small adapter bug. Taken together, they show a single weak point that all the adapters share.
We asked one question: given a handler's response, what does each adapter charge, and what does the buyer receive?
One rule, nine adapters
The x402 v2 specification describes the default payment flow in section 6.1. The authorization flow runs "verify → resource → settle → respond", and the table says "funds move only after it completes successfully". The HTTP transport spec adds an error table with one success row: "Success | 200 | Payment verified and settled successfully". Neither text defines "successfully" as a set of status codes.
The code does. On main at e35bf88, all nine server adapters in the monorepo cancel settlement when the status is 400 or higher and settle otherwise. The TypeScript ones are Express, Hono, Next and Fastify. In Python it is FastAPI and Flask, and in Go it is net/http, Gin and Echo. The check is one line in each:
// typescript/packages/http/express/src/index.ts:328
if (res.statusCode >= 400) { /* cancel: reason "handler_failed" */ }
// hono/src/index.ts:263, next/src/utils.ts:165, fastify/src/index.ts:443
// python fastapi.py: response.status_code >= 400; flask.py: status_code >= 400
// go/http/nethttp/middleware.go:358, gin:434, echo:447: statusCode >= 400
So 200, 204, 302 and 304 all settle. The rule itself is consistent. The trouble is in the two steps around it.
First, the adapter has to observe the status. Every framework offers more than one way to write it, and the adapter must intercept all of them. We call this step capture. Second, after settling, the adapter adds PAYMENT-RESPONSE and Cache-Control: private and sends the handler's response. Several adapters do that by building a new response object from buffered parts. We call this step rebuild. A capture bug charges for a response that was a failure. A rebuild bug delivers something other than what the handler wrote, after the money has already moved.
We covered the Go adapters' decline path in our Gin audit, and the overall request flow in the seller middleware overview. This post covers the success path in TypeScript and Python.
The harness
We installed the releases published on 2026-11-20: @x402/express, @x402/hono and @x402/fastify 2.32.0 from npm, and x402 2.29.0 from PyPI. The frameworks were Express 4.22.3, Hono 4.13.20 with @hono/node-server 2.1.11, Fastify 5.12.8, FastAPI 0.162.5 on Starlette 1.7.0, and Flask 3.1.3, all on Node 22.22.2 or Python 3.10.
A mock facilitator answered every /verify with isValid: true and every /settle with success, and counted the settles. The buyer was real. It used the stock ExactEvmScheme client with a fresh key and signed one EIP-3009 authorization per request for $0.001 on Base Sepolia. For each request we recorded the status the buyer saw, the number of settle calls, whether a PAYMENT-RESPONSE header came back, the Set-Cookie and Cache-Control lines, and the body.
Each seller exposed seven paid routes:
ok: 200 with a JSON body, the control.wh500: a 500. In Express and Fastify the handler writes it through Node'swriteHead. In Hono, FastAPI and Flask it uses the framework's normal API.s204ands304: no body.r302: a redirect to/elsewhere.cookies: twoSet-Cookieheaders andCache-Control: max-age=60.err200: status 200 with an OpenAI-style{"error": ...}body.
We ran Hono twice: once with the default @hono/node-server setup, and once with overrideGlobalObjects: false, so Node's built-in Response class stays in place. The reason is explained below. That gives six setups, seven routes each, 42 paid requests per run.
| Route | Express | Hono (default) | Hono (native Response) | Fastify | FastAPI | Flask |
|---|---|---|---|---|---|---|
ok | 200, paid | 200, paid | 200, paid | 200, paid | 200, paid | 200, paid |
wh500 | 500, paid, success receipt | 500, not paid | 500, not paid | 500, not paid | 500, not paid | 500, not paid |
s204 | 204, paid | 204, paid | 402 {}, paid, no receipt | 204, paid | 204, paid | 204, paid |
s304 | 304, paid | 304, paid | 402 {}, paid, no receipt | 304, paid | 304, paid | 304, paid |
r302 | 302, paid | 302, paid | 302, paid | 302, paid | 302, paid | 302, paid |
cookies | 2 cookies | 2 cookies | 2 cookies | 2 cookies | 1 cookie, 2 Cache-Control lines | 2 cookies |
err200 | 200, paid | 200, paid | 200, paid | 200, paid | 200, paid | 200, paid |
"Paid" means exactly one settle call and a PAYMENT-RESPONSE with success: true, unless the cell says otherwise. We then applied the three PRs' source changes to the installed packages and ran the same 42 requests again. Four cells changed, the three bolded rows, and nothing else moved.
Capture: the 500 that Express charges for
The Express adapter holds the response until settlement. It replaces res.writeHead, res.write, res.end and res.flushHeaders with functions that push each call onto a buffer, waits for end, and then reads res.statusCode. The buffered writeHead stores its arguments but never sets the status:
// @x402/express 2.32.0 (src/index.ts:264)
res.writeHead = function (...args) {
if (!settled) {
bufferedCalls.push(["writeHead", args]);
return res; // res.statusCode is still 200
}
return originalWriteHead(...args);
};
A handler that sets its status with res.status(500) is fine. A handler that calls res.writeHead(500, ...) leaves statusCode at its default of 200. The gate passes, the payment settles, and the buffered writeHead(500) is replayed afterwards. In our run the buyer received status 500, the body {"error":"upstream unavailable"}, Cache-Control: private, and a PAYMENT-RESPONSE that decodes to success: true. The buyer gets an error and a receipt for it.
The Fastify adapter wraps the same raw Node methods and reads the buffered call back: reply.status(writeHeadCall.statusCode) at fastify/src/index.ts:420, before its own gate. Its wh500 row is "not paid". The Go adapters record the status in responseCapture.WriteHeader. PR #4374 adds one line to Express, res.statusCode = args[0], and with it the row flips to "500, not paid".
Who calls writeHead directly? Code written against raw Node, middleware ported from it, and anything that wants to set status and headers in one call. The handler author has no reason to know the payment layer sees only one of the two ways to set a status.
Rebuild: the 204 that Hono turns into a 402
The Hono adapter has to rebuild. A web Response object is read once, and the adapter consumes the body to pass it to the settlement hooks. After a successful settle it builds a new one:
// @x402/hono 2.32.0 (src/index.ts:315), inside the same try as processSettlement
res = new Response(responseBody, { status: res.status, headers: res.headers });
// ...
} catch (error) {
console.error(error);
res = c.json({}, 402); // src/index.ts:335
}
For a handler that returns no body, responseBody is an empty Buffer, which is not null. The Fetch standard's "initialize a response" step says that if the body is non-null and the status is a null body status, the constructor throws a TypeError. The standard lists 101, 103, 204, 205 and 304 as null body statuses. The throw happens inside the try that also wraps processSettlement. The catch cannot tell a failed settle from a failed rebuild, so it answers 402 with {}.
In our native-Response run, s204 and s304 each produced one settle call, a 402, the body {}, and no PAYMENT-RESPONSE. That is the worst combination available: money moved, the response says payment is required, and the one header that would prove otherwise is missing.
Whether this fires depends on which Response class is in scope, so we tested the constructor on its own with an empty body and statuses 204, 205 and 304:
| Runtime | new Response(empty, {status: 204}) |
|---|---|
| Node 22.22.2, built-in Response | TypeError: "Invalid response status code 204" |
@hono/node-server 2.1.11, default | accepted (the server replaces the global Response with its own class) |
| Bun 1.3.8 | accepted |
| workerd 1.20260511.1 (Miniflare in wrangler 4.91.0) | accepted |
The @hono/node-server row is why the default Hono run looked clean. Unless overrideGlobalObjects is false, the server swaps the global Request and Response for its own lightweight classes, and those accepted the empty body. The bug shows up wherever Node's own Response is in scope. That includes a Node server started with the override off, and Hono's app.request() in a test suite running on Node. We checked the second case directly: with app.request() on plain Node, the paid 204 settled once and came back as 402 {} with no receipt. That makes it an awkward bug, because the test of a paid 204 gets a 402 while production on Workers or Bun returns the 204.
The bug has a history. The rebuild came with #3392, merged 2026-09-07. Its first release was @x402/hono 2.26.0 on 2026-09-15; 2.25.0 does not contain the line. The Next adapter had the same failure, reported as #3732 and fixed by #3733 on 2026-10-13. Next's rebuild now passes response.body === null ? null : responseBody. PR #4375 applies the same one-line change to Hono, and with it the native-Response cells became "204, paid" and "304, paid" with a receipt. An older PR, #3062, has touched the same path since 2026-08-05 and is still open.
What the buyer does next
We pointed the stock wrapFetchWithPayment client from @x402/fetch 2.32.0 at the native-Response /s204 route and called it three times. Each call signed a fresh authorization, settled once, and returned 402 with {} and no receipt. After three calls there were three settlements and nothing delivered.
The client itself is careful. It re-signs only when a payment-response hook reports a recovery, and none is registered by default, so one call pays once. The extra payments come from the caller. An agent that treats a 402 as "not paid yet" and tries again pays again. Nothing in that 402 tells it otherwise.
This is not only a lab result. In issue #4367, a team that buys from Bazaar sellers reports 25,011 paid calls to 1,036 sellers and 1,080 non_delivery outcomes. In their earlier October study, 143 calls were charged_then_rejected: the seller settled, then rejected the request. In a separate test they sent one purchase intent twice, and 5 of 10 sellers settled both. Their data cannot say which framework produced which failure. The pattern is the same as ours, though: settlement first, then a response that does not show it.
The same shape in FastAPI
The FastAPI adapter has the same structure. Settlement and the rebuilt Response sit in one try. Its generic except logs the error and returns 402 with a PAYMENT-RESPONSE of success: false and errorReason: "unexpected_settle_error". If anything after a successful settle raised, the buyer would get an explicit statement that settlement failed, for a payment that went through. We did not find a handler shape that triggers it; this is from reading the code. The fix is the same in both adapters: keep the rebuild outside the settle try. If the rebuild fails after the money has moved, answer 500 with the success receipt attached.
Rebuild: the cookie FastAPI drops
The FastAPI adapter rebuilds the paid response from a dictionary:
# x402 2.29.0, python/x402/http/middleware/fastapi.py:465
headers = dict(response.headers)
headers.update(settle_result.headers)
headers["Cache-Control"] = with_private_cache_control(headers.get("Cache-Control"))
A dictionary keeps one value per key, so the second Set-Cookie is lost. The keys are lowercase, so headers.get("Cache-Control") misses the handler's cache-control and a second key is added next to it. Our run returned one cookie instead of two, and two Cache-Control lines, max-age=60 and private.
The two effects are not equally serious. RFC 9110 section 5.3 lets a recipient combine repeated field lines into one list, so the two Cache-Control lines still read as max-age=60, private. The same section notes that Set-Cookie cannot be combined and must be handled as a special case. A paid route that sets a session cookie and a CSRF cookie delivers only one of them, on a call the buyer has paid for. PR #4366 copies response.raw_headers into Starlette's MutableHeaders, and our rerun returned two cookies and a single max-age=60, private line. Flask keeps headers as a list of tuples and was clean in our run.
By design: redirects, 304s and errors inside a 200
Three rows show identical behavior in all six setups. They are not adapter bugs. They follow from the "below 400" rule itself.
A redirect settles. Every adapter charged for r302. We then called an Express route that redirects to a free page, using the stock wrapFetchWithPayment. The client settled once, followed the redirect as fetch does by default, and handed the caller the 200 from /elsewhere, with redirected: true and no PAYMENT-RESPONSE. The receipt was on the 302, and the client never surfaced it. The redirect target also received the PAYMENT-SIGNATURE header. When we redirected from 127.0.0.1 to localhost, a different origin, the header still arrived. For exact on EVM the authorization is already spent by then, because the seller settled before sending the 302. Still, a third-party host learns the payer, amount and nonce of a payment it did not take part in.
A 304 settles. A conditional request that ends in "Not Modified" is billed like a full response. There is a case for that, since the buyer reuses a cached body. There is also a case against it. The spec does not say, and every adapter charges.
An error inside a 200 settles. err200 was billed everywhere. The status code is the only signal the gate reads. An LLM route that relays an upstream error with status 200 bills it, and so does a model refusal returned as a normal completion. We covered the refusal case in our refusal billing audit. The gate is a convention between the handler and the adapter. Only the handler knows whether the work succeeded, and the status code is the only way it can say so.
What a buyer can tell
From the buyer's side, three responses need different treatment.
A 2xx with a PAYMENT-RESPONSE of success: true is a delivered call. A 4xx or 5xx with no PAYMENT-RESPONSE is a decline, and nothing was charged. Then there are the anomalies: a 500 with a success receipt (Express writeHead), a 402 with no receipt after a payment was sent (Hono on native Response), or a redirect whose receipt the client dropped. In each of those, the buyer cannot tell from the response alone whether money moved.
It can tell from the chain. EIP-3009 defines authorizationState(authorizer, nonce), which returns true once a nonce is used. The client already knows the nonce it signed. Before signing a new authorization for the same intent, it can check the old one:
// after a paid retry came back without a success receipt
const used = await publicClient.readContract({
address: requirements.asset, // the EIP-3009 token, e.g. USDC
abi: [{ name: "authorizationState", type: "function", stateMutability: "view",
inputs: [{ type: "address" }, { type: "bytes32" }], outputs: [{ type: "bool" }] }],
functionName: "authorizationState",
args: [payload.payload.authorization.from, payload.payload.authorization.nonce],
});
if (used) { /* paid, not delivered: record it, do not sign again */ }
A true means the seller settled and did not deliver. Paying again will not fix that. It is a dispute, or a reason to stop buying from that seller. A false right after the response still leaves a window, since settlement can land a moment later. Our recovery extension audit covers what a seller-side replay can and cannot repair.
What it means for LLM4Agents
We are a seller, and our gateway's paid route is built on Hono. So we read our own route against this matrix.
The route returns a completion as 200 JSON, or an error status of 400 or higher. Provider failures become a 502 that carries the upstream status in the error details. It never returns 204, 205, 304 or a redirect, and it does not call writeHead. None of the three bugs reaches it today. The Hono finding is the one to watch: it sits on the success path of the SDK we use, and it depends on the runtime's Response class. In our test, only Node's own Response class rejected the empty body. For a Hono service deployed to Workers, the practical exposure is a test suite on Node that disagrees with production.
The "by design" rows matter more for us than the bugs. The status code is the only signal our payment layer reads, so the 200-versus-error decision is a billing decision. A provider error relayed as 200 would be billed. A refusal returned as a normal completion is billed. That is the trade-off we described in our refusal post, and it is a choice, not an accident.
On the buyer side, the agents that call us run x402 clients. A 402 after a signed payment is the case where a careless retry loop costs real money. We can make our own responses unambiguous, so that every settled call carries its receipt. We cannot do that for the other sellers our users' agents pay.
Staying on the frontier
First, pin the contract in our tests. Add the seven-route matrix from this post to the gateway's test suite, run on both Node and the Workers runtime. Each paid route should assert the status, the settle count, and the presence of PAYMENT-RESPONSE. A runtime mismatch like the Hono one should fail CI, not surface after an upgrade.
Second, gate SDK upgrades on that matrix. Before taking a new @x402/hono release, run the same 42 requests against it. #4375 is open today, and the rebuild line has shipped in every release since 2.26.0.
Third, make "paid, not delivered" impossible to miss on our side. If anything fails after settlement, answer with an error status and still attach the success PAYMENT-RESPONSE, so the buyer holds proof of payment. Never answer 402 after money has moved.
Fourth, document the gate for our users. Our docs should list which responses are billed: 2xx, including refusals delivered as completions, and nothing at 400 or above. Agents can then budget and dispute on facts.
Fifth, give buyers the nonce check. Our client examples should check authorizationState before signing again after an ambiguous response. The same advice applies to any x402 seller our users' agents call, and it is the cheapest defense against the double payments #4367 measured.
Sixth, take the remaining gaps upstream. All three PRs are worth a review. The redirect case needs a decision: either the adapters stop settling 3xx by default, or the stock fetch client sends the paid retry with redirect: "manual" so it keeps the receipt and does not forward PAYMENT-SIGNATURE. Section 6.1 of the spec should state which statuses count as "completes successfully", so that nine adapters are implementing a written rule.
Pay per call. Get a receipt for every call you pay.
LLM4Agents is an OpenAI-compatible gateway where autonomous agents pay per request in stablecoins over x402, and we test the code paths that decide when that money moves.
Register an agent