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.

Your agent sleeps between requests and still gets 429

2026-12-04 · why a per-request sleep is not a rate limit, what the server actually counts, and a shared limiter that took our own 429s from 220 a day to zero

For a week, our own verification tools were the loudest source of 429 on our own API. Every one of them already slept between requests. The sleeps were not lying — they were just answering the wrong question.

A sleep controls one process's cadence. A server-side rate limit controls a key. If your tool is one process and the key is "this IP on this route group", sleeping is equivalent to limiting only while exactly one thing on that IP is talking. The moment a second process, a retry loop, or your own ad-hoc curl shares the IP, the arithmetic changes and the sleep stops meaning anything.

1. What the counter is keyed on

The limiter we run keys its counters as scope|clientIP. A "scope" is a route group: the catalog read routes, the per-service read routes, the compatibility surface, the paid surface — each has its own budget, and buckets do not spill into one another. The exemptions are an operator-managed IP allowlist; a User-Agent string is never an exemption, because it is self-reported and therefore free to forge.

As measured on 2026-12-04, the per-IP budgets look like this:

Surface Bucket keys on Budget
/x402/*, /mcp — anonymous read that scope + IP 600/min
/x402/*, /mcp — request carries a payment header that scope + IP 120/min
/svc/* — compatibility surface that scope + IP 120/min
/api/stats, /api/services/:id, /service.html one shared "global" bucket 60/min

Two things in that table do the damage. The paid surface has a smaller budget than the anonymous one, so a client that pays per call has less headroom than a crawler reading listings. And several unrelated paths share one global bucket — a catalog sweep that reads stats, then per-service JSON, then the HTML detail page is spending from a single 60/min counter the whole way, however many different URLs it thinks it is visiting.

2. Why "0.75 s between requests" is not 80/min

Because the sleep is per process, and the budget is per IP-and-scope. One request every 0.75 s is 80 requests/minute — already a third over a 60/min bucket before any second process exists. Our catalog sweep slept between requests and still collected 429s, because the paths it walked (per-service JSON, the HTML detail page, stats) all draw from that one shared bucket. Add a second tool on the same IP and the sum only goes up; nothing in either tool's code records that.

This is also why adding a bigger sleep to every tool "worked" for a day and then stopped. The next tool added to the schedule shifts the sum, and nothing in any individual tool's code changes. A per-request sleep has no place to put the aggregate.

The same shape hits multi-tenant clients. Two directories' probers sharing one NAT egress IP each send a batch every 30 minutes. Individually reasonable; together they peaked around 306 requests/minute against a 120/min bucket and collected 924 429s in a day. The server cannot tell them apart, and should not try: the honest key is the IP.

3. The measurement trap: who is "you" behind a CDN

Before fixing the client, fix the reading. Our origin sits behind Cloudflare, so $remote_addr in the access log is an edge address for every request in the world. The real client is in X-Forwarded-For. If you count 429s by remote_addr, you will attribute the entire internet's throttling to a handful of edge IPs and learn nothing.

The second reading mistake is counting 429s globally. In one 48-minute window we saw 1,065 429s at the origin — and 1,061 of them were a single third-party liveness crawler bursting on its own. Our own traffic in the same window was 59 requests, none throttled. A complaint ("your agent is flooding us") and the correct answer ("no, that's one crawler; here is the per-client breakdown") both require the same join: filter by client, then group by route scope.

4. The fix: one budget, shared across processes

What replaced the per-process sleeps is a tiny file-locked sliding window. Every process that talks to the API asks the same shared state file for a slot, so the budget is enforced across the whole box, not per script. We deliberately budget at half the server's number: the rest of the allowance belongs to interactive calls, retries, and anything else sharing that IP.

import fcntl, json, os, time LOCK, STATE = "/var/tmp/agent-budget.lock", "/var/tmp/agent-budget.json" WINDOW = 60.0 def take(key, budget_per_min): """Block until a slot is free in the shared (key, 60s) window.""" with open(LOCK, "a+") as lk: while True: fcntl.flock(lk, fcntl.LOCK_EX) try: st = json.load(open(STATE)) if os.path.exists(STATE) else {} except ValueError: st = {} # truncated by a crash: fail open now = time.time() hits = [t for t in st.get(key, []) if now - t < WINDOW] if len(hits) < budget_per_min: hits.append(now) st[key] = hits tmp = STATE + ".%d" % os.getpid() with open(tmp, "w") as fh: json.dump(st, fh) os.replace(tmp, STATE) # atomic: readers never see half a file fcntl.flock(lk, fcntl.LOCK_UN) return wait = WINDOW - (now - hits[0]) fcntl.flock(lk, fcntl.LOCK_UN) time.sleep(min(wait, 1.0)) # re-check: another process may have gone 

Three details matter more than the algorithm. The state write is tmp + os.replace, so a crash never leaves a half-written JSON that every later process has to guess about. The wait loop re-acquires the lock instead of sleeping the full window outside it, otherwise N waiters all wake at once and stampede. And the budget is per scope, because the server's buckets are per scope — a single global counter would either over-throttle the wide read surface or under-throttle the narrow one.

5. What changed, measured

On 2026-12-04 our host sent 11,562 requests to our own API; 220 came back 429. Four tool families accounted for 214 of them:

Tool family Requests 429s
catalog sweep 1,051 48
alias registrar 683 47
verification probe suite 2,418 104
description guard 306 15

After the shared limiter was wired into those four (21:43Z), the same host sent 1,828 requests before midnight — including a five-minute scheduled sweep of 1,526 paid-surface probes, peaking at 361 requests in one minute — and received zero 429s. The change was not "send fewer requests". It was "make the aggregate visible to every process before it sends".

6. Rules that generalise

  1. Find the key before you tune the sleep. Ask what the counter is keyed on: IP, IP+route, API key, or account. Your sleep must be expressed in the same unit as the budget.
  2. Treat a budget as aggregate, not per loop. If more than one process on the box can call the same key, the limit has to live where they can all see it — a lock file, a local sidecar, a token in Redis.
  3. Retries spend budget too. A client that retries a 429 three times turns one over-budget request into four. Back off on the same shared counter, not in a private loop.
  4. Never book a 429 as an upstream failure. If your monitoring counts throttling as a service error, your own runaway client will eventually delist a healthy service. Attribute 429 to the caller side.
  5. Leave headroom for the rest of the IP. Half the published budget is a reasonable client default; the other half is for humans, retries and the next tool you write.
  6. Count by real client, not by socket. Behind a CDN or proxy, the address you see is the proxy. Use X-Forwarded-For (from a trusted edge) and group by route scope before drawing conclusions.

7. Caveats

The budgets above are one gateway's, measured on one day; yours will differ, and a well-run API will change them as traffic changes. What does not change is the shape: a limiter is a keyed counter with a window, and every client that shares a key shares the arithmetic. If your agent's politeness is implemented per process, it is not politeness — it is a coincidence that holds until the second process starts.

← All posts

Originally published at minia2a.uk.