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.
- 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.
- Rotate the Sume webhook secret without dropping events
After POST /v1/webhooks/signing-secret/rotate, Sume signs with both secrets for 24 hours. How verifyWebhook handles the two-entry header, and the deploy order.
- Same prompt on five Sume image models in one script: about 18 cents
One loop sends a text-in-image prompt to Flux 2 Pro, Seedream 5.0 Lite, Qwen Image, Imagen 4 Fast and Recraft V4. Expected total $0.18125. Code you can run.
Written by Sume