Retry a timed-out Omni Flash submit without paying twice (Node)

Node 18+ code that retries a Gemini Omni Flash 1.1 POST to Sume's /v1/videos on timeout or 429 with one Idempotency-Key, so a retry returns the same job.

3 min readSume
All posts

Reuse the same Idempotency-Key on every attempt. Sume's docs say a replay returns the original job, so a submit whose response you never saw can be retried without a second reservation.

Without a key, the errors page is blunt: do not retry unsafe submit requests. With one, back off on 429 using retry-after when present.

Code

Save as submit.mjs and run with Node 18 or later.

const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const body = JSON.stringify({
  model: "gemini-omni-flash-1.1",
  prompt: "Rain on a taxi window at night, wipers and distant horns",
  duration: 5, resolution: "720p", aspect_ratio: "16:9",
});
const headers = {
  Authorization: `Bearer ${process.env.SUME_API_KEY}`,
  "Content-Type": "application/json",
  "Idempotency-Key": "taxi-rain-001",
};
for (let i = 0; i < 4; i++) {
  try {
    const r = await fetch("https://api.sume.com/v1/videos", {
      method: "POST", headers, body, signal: AbortSignal.timeout(20000),
    });
    if (r.status === 429) {
      await sleep(Number(r.headers.get("retry-after") ?? 2) * 1000);
      continue;
    }
    console.log(r.status, await r.json());
    break;
  } catch {
    await sleep(2000 * (i + 1));
  }
}

What it protects

A 5 second 720p Omni clip reserves $0.625. Four blind retries without a key could, in the worst case, be $2.50 of holds; with the key it is one job.

Limits

Use a fresh key for each intended clip, and keep the key with your own record of the prompt. Do not retry 402: the balance cannot cover the reserve, so an identical retry fails the same way. Submit a cheaper request or wait for more balance.

Which responses to retry

The loop above retries a timeout or a 429 and prints anything else, which is the right default for a paid submit. The docs list these codes:

  • 429 rate_limited: request volume exceeded an abuse-protection limit; use retry-after when present.
  • 429 queue_full: the workspace has no remaining accepted-job capacity; wait for jobs to finish or cancel queued ones, then retry with the same key.
  • 402 insufficient_credits: do not retry unchanged.
  • 409 idempotency_conflict: the key was used for a different payload; mint a new key only for a genuinely new request.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume