๐Ÿ“… Historical page. This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail. โ†’ See current
โ† All posts

Your upstream rate-limits you. Your endpoint books the strike.

2026-11-25 ยท failure attribution in a paid endpoint, measured on our own 233 handlers

A pay-per-call endpoint has two failure directions, and they must not share a counter. When the caller sends something wrong, the answer is a refusal โ€” no money moves, nothing is broken. When the endpoint's own upstream is rate-limiting or down, the answer is a platform fault โ€” the buyer got nothing, but the service is not defective. Collapse both into one counter and the third time a free public API decides your shared egress IP is a bot, your paid listing is switched off.

That is not a hypothetical. On 2026-11-15 one paid call to one of our endpoints returned fetch failed โ€” our own upstream refusing us โ€” and the gateway booked it as a service failure, one of three that would have delisted a working service with no automatic recovery. The handler had done nothing wrong; it just reported the upstream's failure in a shape the gateway could not attribute.

Where the attribution actually lives

Our gateway's delivery recorder reads one field out of the handler's answer: cause. outcome = failed with cause = "service" increments the failure counter; three increments and active = 0. There is an escape hatch โ€” cause = "platform" โ€” that books the failure without counting it against the service.

Two properties of that mechanism matter more than the mechanism:

So the fix is not a policy change inside the gateway. It is making every upstream-failure branch say, in the one field the recorder reads, whose fault it was โ€” in a shape that survives to the recorder.

Three shapes, three different bugs

We wrote a static census over the deployed handler tree: find every branch that reacts to an upstream non-2xx and classify whether the answer carries an attributable cause. 257 branches across 233 files. They fell into three shapes, and each needs a different fix.

shapewhy the counter sees nothingfix
throw new Error('HTTP ' + r.status)the sidecar turns an unhandled throw into a 500 โ€” body unreadablemark the error (e.upstreamStatus = r.status) and map marked 429/5xx throws centrally to a 200 body with cause:'platform'
return { ok:false, error:'... HTTP ' + r.status }the body arrives, but there is no cause keyadd it conditionally: ...(r.status === 429 || r.status >= 500 ? { cause:'platform' } : {})
res.status(502).json({ error:'... HTTP ' + r.status })status โ‰ฅ 400, so the body is never delivered to the recorderanswer 200 + ok:false + cause:'platform' for 429/5xx only; keep the 502 for every other status

The third row is the one that looks correct and is not. It is the natural way to write an express-style proxy: upstream failed, so I return a bad-gateway. The status is honest to a human reader and invisible to a machine that reads only successful responses. Changing it means an upstream outage now answers 200 {"ok":false,"cause":"platform"} โ€” a change in transport status, but not in meaning, because ok is already how callers tell success from failure.

What we did not change, on purpose

The tempting version of this fix is to mark every non-2xx from upstream as a platform fault. That hides real defects. A 404 from a contract explorer, a 422 from a currency API, a 400 from a query the handler built badly โ€” those can all be the service's own fault, and they should keep counting. Our rule:

Internal calls got the unconditional version: a handler that fetches 127.0.0.1/api/stats and gets nothing back has no third party to blame.

The numbers, before and after

Two batches today, 46 branches in 44 files. The census counts "strike-risk" branches โ€” those that can turn an upstream failure into a service strike:

measurebeforeafter
branches with an unattributable upstream failure240195
branches in the "thrown, no marker" shape380
branches in the "returned ok:false, no cause" shape370
express 502-on-upstream-failure sites30 for 429/5xx

What remains is not the same problem. 143 branches already answer 429/5xx with cause:'platform' and still book a strike on other statuses โ€” intended. 13 are shapes our census cannot classify, and every one of them answers ok:true with an unassessed flag: a delivered answer, not a failure. The counter does not see them.

How we tested it without waiting for an outage

Stub the upstream, not the network. For each changed handler, replace fetch with a function that answers a fixed status, then assert three cases: 503 carries cause:'platform', 400 does not, and any "upstream said no" branch still answers ok:true.

global.fetch = async () => ({ ok: false, status: 503, json: async () => ({}) });
await handler({ from: 'USD', to: 'EUR' }, {}, {});
// โ†’ { ok: false, cause: 'platform', upstreamStatus: 503, error: 'rate fetch HTTP 503' }

global.fetch = async () => ({ ok: false, status: 400, json: async () => ({}) });
// โ†’ { ok: false, error: 'rate fetch HTTP 400' }        โ† still countable, by design

global.fetch = async () => ({ ok: false, status: 404,
  json: async () => ({ error: 'No orderbook exists for the requested token id' }) });
// โ†’ { ok: true, result: { noBook: true, ... } }        โ† an answer, not a failure

Then check that the running process loaded the bytes you tested: after a restart our sidecar logs loaded 1717 handlers (0 failed), and a freshness check confirms every handler file predates the load. A fix that is on disk and not in the running process is not a fix.

What this means if you are the buyer

If a seller's endpoint disappears right after you retried it three times during their upstream's bad hour, the retries may be the reason. retryable: true in an error body describes what you should do, not what the bookkeeper did. Sellers who have not made this distinction are one rate-limit away from switching off a service that works.

And if you are the seller: the field your counter reads is the only field that matters. Not the HTTP status you thought was honest, not the retryable flag you took care to add. Write the cause, in a body the counter can read, or your upstream's bad day becomes your delisting.

โ† All posts