Retry Sume 429s in TypeScript: a fetch wrapper that obeys retry-after

A small fetch wrapper for the Sume API: retry 429 only when the request is a GET or carries an Idempotency-Key, wait retry-after, and never loop on queue_full.

5 min readSume
All posts

Retry a Sume 429 only when the request is safe to repeat, wait the number of seconds in retry-after, and cap the attempts. A safe request is a read, or a paid submit that carries an Idempotency-Key; the docs say not to retry unsafe submits without one.

The wrapper

It returns the 429 to the caller when the request is unsafe or attempts run out. It falls back to exponential waiting when retry-after is absent.

export async function sumeFetch(
  url: string,
  init: RequestInit = {},
  tries = 4,
): Promise<Response> {
  const headers = new Headers(init.headers);
  const safe =
    (init.method ?? "GET") === "GET" || headers.has("idempotency-key");
  for (let i = 0; ; i++) {
    const res = await fetch(url, init);
    if (res.status !== 429 || !safe || i >= tries - 1) return res;
    const wait = Number(res.headers.get("retry-after")) || 2 ** i;
    await new Promise((r) => setTimeout(r, wait * 1000));
  }
}

429 has two meanings

rate_limited is the request budget and clears with time. queue_full means the workspace has no accepted generation capacity left; the docs say to stop adding work, let jobs finish or cancel queued ones, then retry with the same idempotency key. Blind retries against queue_full just hold the line, so in production read error.code before sleeping and route queue_full to your scheduler.

What to log

Log ratelimit-remaining on every response and the x-sume-request-id header on every failure; request ids are safe to share with Sume support. Never log the API key or signed URLs.

429 handling by code (read 2026-10-03)
error.codeMeaningClient behavior
rate_limitedRequest volume over the key's budgetWait retry-after, retry safe requests
queue_fullNo accepted generation capacity leftStop submitting, drain or cancel, then retry with the same key

Sources

Related posts

More in Developers

All Developers posts

Written by Sume