Batch hero stills from a CSV
Render one hero still per row of a CSV, with an idempotency key so a crash never double-charges.
batch.py
import csv, os, time, requests
TAKES = "https://edengen.ai/v1"
H = {"Authorization": f"Bearer {os.environ['TAKES_API_KEY']}"}
rows = list(csv.DictReader(open("shots.csv"))) # columns: shot, prompt
total = sum(requests.post(f"{TAKES}/estimate", headers=H, json={
"model": "nano-banana-pro", "prompt": r["prompt"], "resolution": "2K"}).json()["usd_total"] for r in rows)
input(f"{len(rows)} stills for ${total:.2f}. Enter to render, Ctrl+C to stop. ")
for r in rows:
take = requests.post(f"{TAKES}/takes", headers={**H, "Idempotency-Key": f"hero-{r['shot']}", "Prefer": "wait=60"},
json={"model": "nano-banana-pro", "prompt": r["prompt"], "resolution": "2K",
"aspect_ratio": "21:9", "metadata": {"shot": r["shot"]}}).json()
while take["status"] in ("queued", "processing"):
time.sleep(3)
take = requests.get(f"{TAKES}/takes/{take['id']}", headers=H).json()
if take["status"] == "succeeded":
open(take["output"]["filename"], "wb").write(requests.get(take["output"]["url"], headers=H).content)
print(r["shot"], "ok", take["id"])
else:
print(r["shot"], "refunded:", take["error"])Why the idempotency key matters
Run the script twice after a crash and every finished row returns its existing take instead of rendering and charging again.