Submit 6 ad hooks in parallel in Python with one Idempotency-Key each

A Python script that submits six 3-second Omni hook jobs in parallel, each with its own Idempotency-Key so a retry replays the original job. Cost: $2.25.

5 min readSume
All posts

The script below submits six 3-second hook jobs to POST /v1/videos at the same time, each with its own Idempotency-Key. If you run it again after a network error, a replay returns the original job and does not start a second one. Six hooks at 720p on Gemini Omni Flash 1.1 cost 6 x $0.375 = $2.25 on Sume.

The script

Set SUME_API_KEY in your shell, install requests, and run the file. The code uses asyncio.to_thread to run the blocking calls side by side. It does not use top-level await.

Each worker thread blocks on one HTTP call, and asyncio.gather waits for all six. For six jobs, that is simple and fast enough. For hundreds of jobs, cap the number of parallel calls with a semaphore, and read the docs for the limits that apply to your account.

import asyncio, os
import requests

KEY = os.environ["SUME_API_KEY"]
HOOKS = [
    "Hand drops the bottle into a bag, cut to a smile",
    "Close macro of the label, slow push-in",
    "Before and after of a kitchen counter wipe",
    "Box opens on a table, product lifts out",
    "Price tag falls and lands on the bottle",
    "Person points at the bottle and nods",
]

def submit(i, prompt):
    r = requests.post(
        "https://api.sume.com/v1/videos",
        headers={"Authorization": f"Bearer {KEY}", "Idempotency-Key": f"hooks-q4-v1-{i}"},
        json={"model": "gemini-omni-flash-1.1", "prompt": prompt, "duration": 3,
              "resolution": "720p", "aspect_ratio": "9:16"},
        timeout=60,
    )
    r.raise_for_status()
    return r.json()["polling_url"]

async def main():
    urls = await asyncio.gather(*(asyncio.to_thread(submit, i, p) for i, p in enumerate(HOOKS)))
    print("\n".join(urls))

asyncio.run(main())

Why the key is built this way

The key is built from the campaign, the version and the hook number. It is stable across runs, so a rerun sends the same six keys. The Video Generation docs say that a replay with the same key returns the original job.

Change the version part, for example to v2, only when you want new takes. A new key is a new job and a new charge.

Do not put a timestamp or a random number in the key. A key like that changes on every run, and a rerun would start six new jobs and charge for them.

Keep the prompts and the keys in the same file. When you review the results, the hook number in the key tells you which prompt made which clip, with no extra bookkeeping.

Cost and failure

Each job takes 3 seconds at 720p, which is 3 x $0.125 = $0.375 on Omni. Six jobs are $2.25. At 1080p the rate is $0.1875 per second, so six jobs are $3.375. Sume returns a 402 with insufficient_credits when the balance is below the reserve for a job, and raise_for_status raises on it, so a short wallet stops the script at the first failed call and not silently.

Six drafts for $2.25 is a fair price for a hook test, but check the wallet first. A balance below the reserve for a single job is rejected, so top up before a large batch and not in the middle of it.

The reserve is taken when the job is accepted, and the final amount follows the job. For fixed-length Omni clips the two match, since the price is the per-second rate times the seconds.

Six 3-second Omni hooks, Sume prices read 2026-10-07
ResolutionPer clipSix clips
360p$0.1125$0.675
720p$0.375$2.25
1080p$0.5625$3.375

Next step: poll or use a webhook

The script prints the polling URLs. Poll each with GET until its status is completed, then download from unsigned_urls[0], as in the docs. For a push instead of a poll, pass a callback_url on HTTPS and verify the signature headers on your receiver, using a non-empty secret.

Once you have the files, pick two or three and join each to a body clip in Timeline. The hook test then costs $2.25 for the six drafts plus $0.10 for each joined cut.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume