Menu

Retrying an image API on 429: backoff, jitter and credits
πŸ“°

Retrying an image API on 429: backoff, jitter and credits

DEV Community: javascriptΒ·Sahadat HusainΒ·about 11 hours ago
#9q2B9KWl
#devtojavascript#devto#dev#retry#jobs
Reading 0:00
15s threshold

On a 429 , wait for the number of seconds in the Retry-After header plus a little random jitter, then send the same request again with the same Idempotency-Key . Against a mock of the Blinkimg API's limiter, that policy created 120 jobs in 144 requests. Retrying at once took 3,869 requests and still lost 72 jobs. The key is what stops a retry from paying twice.

What does the API send back on a 429?

I read this from the API's source ( apps/api ), not from memory. A request-rate refusal comes from @fastify/rate-limit , which keeps a fixed window per caller and sets Retry-After in whole seconds. The error handler mirrors that into the JSON body:

{ "error" : { "code" : "RATE_LIMITED" , "message" : "Rate limit exceeded" , "requestId" : "..." , "resetAt" : "2026-10-17T09:12:31.000Z" } }

Enter fullscreen mode

Exit fullscreen mode

The budget for an API key is 120 writes a minute (uploads, jobs, batches) and 1,200 reads a minute (polling). Two keys on one account share one budget.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.