import requests
import time
BASE = "https://nano-gpt.com/api"
def get_video_status(run_id: str, model_slug: str, api_key: str) -> dict:
resp = requests.get(
f"{BASE}/generate-video/status",
headers={"x-api-key": api_key},
params={"runId": run_id, "modelSlug": model_slug},
timeout=30,
)
resp.raise_for_status()
return resp.json()
def wait_for_video(run_id: str, model_slug: str, api_key: str, max_attempts: int = 120, delay_s: int = 5) -> str:
for i in range(max_attempts):
data = get_video_status(run_id, model_slug, api_key)
status = data.get("data", {}).get("status")
if status == "COMPLETED":
return data["data"]["output"]["video"]["url"]
if status == "FAILED":
raise RuntimeError(data.get("data", {}).get("error", "Video generation failed"))
time.sleep(delay_s)
raise TimeoutError("Video generation timed out")