One Click Videos · Developers

Python

Create and poll a video with Python’s standard library.

Before running

Use Python 3.10 or later. Set JEMSU_API_KEY securely, save the file and run python3 create_video.py. The first request spends account credits.

# Python 3.10+. Save as create_video.py. Uses the standard library.
import json, os, time
from pathlib import Path
from urllib.request import Request, urlopen
from urllib.error import HTTPError

key = os.environ["JEMSU_API_KEY"]
base = "https://app.jemsu.ai/api/v1"
def request(path, payload=None):
    req = Request(base + path,
        data=json.dumps(payload).encode() if payload is not None else None,
        headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"},
        method="POST" if payload is not None else "GET")
    try:
        with urlopen(req, timeout=120 if payload is not None else 30) as response:
            return json.load(response)
    except HTTPError as error:
        if payload is None and (error.code == 429 or error.code >= 500):
            return None
        raise RuntimeError(f"HTTP {error.code}: {error.read().decode()}") from None

created = request("/videos", {
    "video_idea": "A paper boat drifts across a sunlit pond. Calm, cinematic, no dialogue.",
    "video_length_sec": 10, "speech": "no", "music": "no", "aspectratio": "9:16"
})
job_id = created["jobId"]
Path("jemsu-job.json").write_text(json.dumps(created, indent=2))
print("Job:", job_id, "Reserved credits:", created.get("creditsReserved"))
from urllib.parse import quote
for attempt in range(60):
    time.sleep(15)
    job = request("/videos/" + quote(job_id, safe=""))
    if job is None:
        continue
    if job["status"] == "failed":
        raise RuntimeError(job.get("error"))
    if job["status"] == "completed":
        if not job.get("videoUrl"):
            raise RuntimeError("Completed without a result URL; contact support with the job ID.")
        print("Video:", job["videoUrl"])
        break
else:
    raise RuntimeError("Polling limit reached. Resume GET status using jemsu-job.json; do not repeat POST.")

Resume without creating a duplicate

Keep jemsu-job.json. If polling is interrupted, extract its jobId and resume the GET request. Rerunning the full script submits another video. Add your application’s queue, persistence and retry policy before using this in a larger workflow.