Create a job
Moth DocsReference
/jobsStarts an image, video or music job and answers at once with the job, which you then read until it succeeds.
curl https://api.runmoth.ai/v1/jobs \ -H "Authorization: Bearer $MOTH_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "nano-banana-2", "prompt": "A moth resting on a warm lamp at night", "n": 1, "aspect_ratio": "3:2" }'
moth-request-id req_4Gk9tQ2wXb7Lm1Pz8RcV { "id": "job_7Hc2pW9kLm4Qx8Rt1Vz3", "object": "job", "model": "nano-banana-2", "modality": "image", "status": "running", "created_at": 1793347200, "completed_at": null, "unit": "image", "units": 1, "held_usd": "0.047059", "charged_usd": null, "progress": 0, "outputs": [] }
Body
modelrequiredA media model ID from the catalog.
promptrequiredUp to 10,000 characters, or the model's max_prompt_chars when it is lower.
nintegerImages to make, up to the model's max_images. Images only, and 1 by default.
duration_secondsintegerThe clip's length, one of the model's durations. Video only, and the first listed by default.
aspect_ratiostringSuch as 16:9, one of the model's aspect_ratios, for images and video.
sizestringSuch as 1536x1024, turned into a ratio when aspect_ratio isn't sent. Images only.
stylestringA style for the song, up to 200 characters. Music only.
instrumentalbooleanA song with no vocals. Music only.
It answers 202 with the job's hold taken. POST /images is the same endpoint limited to image models, and Images, video and music walks through a whole job.
Safe retries
Send an Idempotency-Key header, 1 to 255 visible ASCII characters such as a UUID, and a retry with the same key within 24 hours gets the first job back with the header idempotent-replayed: true, so a request that timed out never starts or charges a second job.
The same key with another model, length, number of images or frame is refused with 409, and so is a retry while the first request is still going out, which you can retry a moment later. A request that was refused, such as for credit, frees its key. Moth keeps no prompt to compare, so a different prompt under the same key also gets the first job back.
A key with a webhook has Moth post to your server when the job ends, and List jobs shows every job from the last day.
Errors
400invalid_request_errorThe body isn't valid, names a chat model, or asks for a setting the model doesn't take401authentication_errorThe key is missing, revoked or expired402insufficient_creditThe balance or the key's cap can't cover the job's hold403permission_errorThe key may not use this model404not_found_errorThe model isn't in the catalog409invalid_request_errorThe Idempotency-Key was used for a different request, or the first request with it is still going out429rate_limit_errorToo many calls from the key or the account, or to the model, so wait for retry-after when it is sent503overloaded_errorMoth is briefly at capacity, so wait for retry-after529overloaded_errorThe model is paused, or busy or down at its host, so choose another or wait for retry-after when it is sent