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.

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; useretry-afterwhen 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
- Retry a timed-out POST /v1/videos with one Idempotency-Key, pay once
A Python submit wrapper that retries network errors, 429 and 5xx with a stable Idempotency-Key, so a replay returns the original job instead of a second charge.
- Retry an avatar video submit without paying twice on Sume
Use one Idempotency-Key per paid avatar video submit and poll the job instead of resubmitting after a timeout. A Python example and the rules from Sume docs.
- Retry cost of a mixed project: what a failed shot, 402 and replay bill
Six failure cases for an image, voice, music, video and render project, with the cost of the retry for each and the one mistake that pays for everything twice.
- Review a 30-second Wan 3.0 clip: video inspect caps at 24 stills
Video inspect returns at most 24 stills per call, so a 30-second clip needs a sample rate of 0.8 fps or an explicit list of 24 times. Python builds the request.
Written by Sume