DEV Community

Api-Ceilings
Api-Ceilings

Posted on

The 429 that waiting doesn't fix

I spent an hour last week waiting for a request that was never going to succeed.

The setup: a scheduled job calling the Anthropic API. It started returning 429s around 3am. My retry wrapper did what retry wrappers do — read the Retry-After header, pause, retry. There was no Retry-After header. The wrapper fell through to exponential backoff, paused 2 seconds, retried. 429 again. Paused 4 seconds, retried. 429 again. Ten retries over five minutes. Every one failed. Same error. Same request. Same result.

I assumed the request was rate-limited. Rate limits clear. I waited longer.

They didn't clear.

What was actually happening: the API was returning a spend cap 429, not a rate-limit 429. The account's monthly spend limit had been hit. The response looked like this:

text
{
"type": "error",
"error": {
"type": "rate_limit_error",
"message": "This request would exceed your account's spend limit..."
}
}
Same type. Same HTTP status. Same retry playbook. But it doesn't clear when you wait. It clears on the first of the month.

The signature — the only thing that distinguishes it from a real rate-limit 429 — is a detail buried in the response body: details.error_code: enforced_spend_limit_reached. If your retry wrapper is only reading the top-level error.type, it never sees this. It just sees rate_limit_error, which it's been trained to retry, and it retries forever.

I checked the JavaScript SDK. It's doing the same thing. It sees rate_limit_error, waits, retries. It never gets to the details field because the top-level code already looks retryable. The retry loop eats requests (and tokens) until something else times out.

The fix is three lines:

js
if (err?.error?.type === 'rate_limit_error') {
const spendCap = err?.error?.details?.error_code === 'enforced_spend_limit_reached';
if (spendCap) throw err; // do not retry
// otherwise, retry with backoff
}

But the fix isn't the interesting part. The interesting part is that a retry loop that reads only the top-level error type — which is what every retry library does — treats two completely different failures as the same failure. One clears in 60 seconds. The other clears in up to 31 days. A wrapper that can't tell them apart will retry the 31-day one 31 days × 86,400 times.

This isn't just an Anthropic problem. It's the general shape of the problem the archive is built around.

Stripe has the same structure — five different rate axes, one error code, but at least it puts the reason in the Stripe-Rate-Limited-Reason header. Twilio has five different 429 codes in the body, and only one of them is safe to retry. Cloudflare uses the IETF Ratelimit header format, which is a structured field, not a string. Notion has seven rate_limit_reason values, one of which (public_api_request_blocked) should never be retried at all — it's not a rate limit, it's a restriction.

Every one of these vendors returns 429 for something that is not a rate limit. The retry wrapper only sees the status code. Which means every one of these vendors has the same bug — and every developer who hits it has the same experience of thinking they're the only one.

I built a trap page for the Anthropic one.

It's the fifth trap page in the archive, and it's a small one. But it's the first one that started as a bug I actually hit rather than a query I noticed in Search Console. The GitHub secondary rate limit page was written because the query was already ranked #1. This one was written because I got the bug wrong for an hour.

Same page structure. The number at the top says "monthly spend cap, resets the 1st." The error shape is the actual JSON. The retry snippet is the three-line fix. The escape hatch is "raise the spend cap or wait until the 1st."

I think these are more useful than the data-driven ones, honestly. A trap page written because you hit the bug is a different thing than a trap page written because the query had volume. The first one knows what you were thinking when you hit it.

So the question I'm asking this time is different. It's not "what query do you want covered." It's:

What 429 have you hit that waiting didn't fix?

Not the ones where you waited 60 seconds and it cleared. The ones where you waited, and waited, and it didn't. The ones where the retry loop ate hours and you eventually figured out it wasn't a rate limit at all. Paste the error string if you have it. Paste the fix if you found one.

Every one of those is either an API returning 429 for something that isn't rate limiting, or a retry library that can't tell the difference. Either way, that's a page.

I'm collecting the ones that didn't fix themselves.

Top comments (9)

Collapse
 
smtahosin profile image
S M Tahosin •

quota 429 xD body said quota_exceeded, waiting did nothing :D

Collapse
 
apiceilings profile image
Api-Ceilings •

quota and spend-cap are the same trap wearing different words - both clear on a billing boundary, not a clock. waiting is the one thing that can't work :D

Collapse
 
smtahosin profile image
S M Tahosin •

lol Api that billing boundary bit.. yeah. me at like 1am, tea gone cold, hitting retry again and again xD quota_exceeded, quota_exceeded. waiting wasn't fixing nothing haha. thanks for that, honestly :D

Thread Thread
 
apiceilings profile image
Api-Ceilings •

quota exceeded is going on the list : cold tea at 1am is exactly who those pages are written for.

Thread Thread
 
smtahosin profile image
S M Tahosin •

Api xD on the list it goes... my 1am brain needed that warning tattooed on the mug lol thanks :D

Thread Thread
 
apiceilings profile image
Api-Ceilings •

mug first, tattoo second.

Thread Thread
 
smtahosin profile image
S M Tahosin •

api lol marker on the mug it is... my marker squeaks and everything, still less permanent than a tattoo xD deal :D

Collapse
 
apiceilings profile image
Api-Ceilings •

the github secondary rate limit page was written because the query was already #1. this one was written because i got the bug wrong for an hour. honestly the second kind is more useful - a page written by someone who just hit the wall knows what you were thinking when you hit it.

Collapse
 
apiceilings profile image
Api-Ceilings •

What 429 have you hit that waiting didn't fix?