Python AI video API
Requires Python 3.9+ and requests. Copy also lives at /examples/python/generate.py. Longer tutorial: blog post.
#!/usr/bin/env python3
"""Minimal VideoGenAPI client: generate + poll status.
Last executed pattern: 16 August 2026. Set VIDEOGENAPI_KEY in the environment.
"""
import os
import sys
import time
import requests
BASE = "https://videogenapi.com/api/v1"
KEY = os.environ.get("VIDEOGENAPI_KEY", "")
def generate(prompt: str, model: str = "kling-3", duration: int = 5) -> dict:
r = requests.post(
f"{BASE}/generate",
headers={"Authorization": f"Bearer {KEY}", "Content-Type": "application/json"},
json={"model": model, "prompt": prompt, "duration": duration},
timeout=30,
)
r.raise_for_status()
return r.json()
def wait(generation_id: str, timeout: int = 300) -> dict:
deadline = time.time() + timeout
while time.time() < deadline:
r = requests.get(
f"{BASE}/status/{generation_id}",
headers={"Authorization": f"Bearer {KEY}"},
timeout=30,
)
r.raise_for_status()
data = r.json()
status = (data.get("status") or data.get("data", {}).get("status") or "").lower()
if status in {"completed", "success", "failed", "error"}:
return data
time.sleep(3)
raise TimeoutError("generation did not finish before timeout")
if __name__ == "__main__":
if not KEY:
sys.exit("Set VIDEOGENAPI_KEY")
prompt = sys.argv[1] if len(sys.argv) > 1 else "A ceramic mug on a sunlit table, slow camera push-in"
job = generate(prompt)
gid = job.get("generation_id") or job.get("id") or job.get("data", {}).get("id")
print("queued", gid)
print(wait(gid))
Errors to expect
- 401 — missing or invalid API key
- 429 — rate limit or monthly allowance, see rate limits
- failed status — content policy or provider error; read
erroron the status payload