Images, video and music
Moth DocsGuides
Media runs as a job, which you start with one request, read until it succeeds and then download.
Start the job
Send a job with a media model and a prompt. It answers 202 with the job already running and its hold taken.
Read its status
Read the job every few seconds until
statusissucceededorfailed, whileprogressruns from 0 to 1.Download the files
Each output has a
urlon the API. Fetch it with the same key within 24 hours, since the job is forgotten after that.
- Start202POST /jobs answers at once, with the job running and its hold taken
- RunningRead GET /jobs/{id} every few seconds while progress goes from 0 to 1
- SucceededDownload the files within 24 hours. Images are charged per image, a clip or a song in fullorFailedOr unfinished after an hour. Nothing is charged and the hold comes back
import os, time, requests api = "https://api.runmoth.ai/v1" auth = {"Authorization": f"Bearer {os.environ['MOTH_API_KEY']}"} job = requests.post(f"{api}/jobs", headers=auth, json={ "model": "nano-banana-2", "prompt": "A moth resting on a warm lamp at night", "n": 2, }).json() while job["status"] in ("queued", "running"): time.sleep(3) job = requests.get(f"{api}/jobs/{job['id']}", headers=auth).json() for out in job["outputs"]: image = requests.get(f"https://api.runmoth.ai{out['url']}", headers=auth).content
Settings by kind
n up to the model's max_images, and aspect_ratio or sizeimage deliveredduration_seconds from the model's durations, and aspect_ratiosecond, in full when it succeedsstyle and instrumentalsongEach model's limits in the catalog lists what it takes. A setting outside them is refused with 400 before anything is held, and seed is refused on every model.
A failed job costs nothing. A job that fails, or hasn't finished after an hour, ends as failed and gives its whole hold back.
/images is the same endpoint limited to image models. It is not OpenAI's images API, and it answers with a job in the same way.
Instead of reading a job until it ends, a key with a webhook has Moth post to your server when it does. A job sent with an Idempotency-Key can be retried safely, as Create a job explains, and List jobs shows every job from the last day.