import time
import requests
BASE = "https://api.naga.ac/v1"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
# A job: 202 at once, then poll until it is done. Duration, resolution and
# aspect ratio default to the model's own; GET /v1/videos/models lists them.
job = requests.post(
f"{BASE}/videos",
headers=HEADERS,
json={
"model": "kling-v3.0-std",
"prompt": "A red paper boat drifting on a calm lake at dawn",
},
).json()
while job["status"] in ("pending", "in_progress"):
time.sleep(10)
job = requests.get(job["polling_url"], headers=HEADERS).json()
if job["status"] == "completed":
video = requests.get(f"{BASE}/videos/{job['id']}/content", headers=HEADERS)
with open("video.mp4", "wb") as file:
file.write(video.content)
else:
print(job["error"])