Create a job

Moth DocsReference

POSThttps://api.runmoth.ai/v1/jobs

Starts 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" }'
Response
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

modelrequired

A media model ID from the catalog.

promptrequired

Up to 10,000 characters, or the model's max_prompt_chars when it is lower.

ninteger

Images to make, up to the model's max_images. Images only, and 1 by default.

duration_secondsinteger

The clip's length, one of the model's durations. Video only, and the first listed by default.

aspect_ratiostring

Such as 16:9, one of the model's aspect_ratios, for images and video.

sizestring

Such as 1536x1024, turned into a ratio when aspect_ratio isn't sent. Images only.

stylestring

A style for the song, up to 200 characters. Music only.

instrumentalboolean

A 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 take
401authentication_errorThe key is missing, revoked or expired
402insufficient_creditThe balance or the key's cap can't cover the job's hold
403permission_errorThe key may not use this model
404not_found_errorThe model isn't in the catalog
409invalid_request_errorThe Idempotency-Key was used for a different request, or the first request with it is still going out
429rate_limit_errorToo many calls from the key or the account, or to the model, so wait for retry-after when it is sent
503overloaded_errorMoth is briefly at capacity, so wait for retry-after
529overloaded_errorThe model is paused, or busy or down at its host, so choose another or wait for retry-after when it is sent
On this page