- Optionally upload reference images or videos. Each upload returns an ID.
- Start a job with
POST /imageorPOST /video. The response contains ajob_idand the credits the job will cost. - Poll
GET /image/{job_id}orGET /video/{job_id}until the job has succeeded, then download the result.
Prerequisites
- Python 3.6+
requestslibrary (pip install requests)- An API key, passed in the
X-API-KEYheader. See Authentication for how to create one.
Choosing a model
List the available models, with the resolutions, aspect ratios and credits each one supports. The list changes as models are added, so read model IDs from here instead of hard-coding them.480p, 720p, 1080p, 2k or 4k, and each model lists the ones it supports. Video models also return a label for each resolution with the size actually rendered. For example, a model whose lowest tier renders at 360p lists it as 480p with the label 360p.
When you leave out resolution, aspect_ratio or duration, the model’s defaults are used.
Generating an image
Editing and combining images
Upload images first, then pass their IDs inreference_image_ids. The first image is the one being edited; the rest are extra references. Refer to them in the prompt as @Image 1, @Image 2 and so on, in the same order. Only models with supports_reference_images accept references.
image_id from the job result.
Generating a video
The kind of video is set by which inputs you send. Each model lists the modes it supports inmodes.
Send inputs for one mode only; mixing them returns a 422.
Text to video
Animating an image
Pass an uploaded image, or theimage_id of a generated image, as the start frame. Add end_frame_image_id to control where the clip ends.
Using reference images and videos
Upload reference clips withPOST /video/upload, then refer to every input in the prompt by type and position: @Image 1, @Video 1.
max_reference_images, max_reference_videos) and how long reference clips may be. Requests outside a limit return a 400 that names it.
Editing a video
Pass the clip to edit assource_video_id. For models with output_duration_follows_source, the result is as long as the source clip, so leave out duration. You’re charged for the clip’s length.
Credits
- Images are charged per generated image, at the price for the chosen resolution (
credits_by_resolution). - Videos are charged per second of generated video, at the price for the chosen resolution (
credits_per_second). - Every create request returns
estimated_credits. Credits are checked before the job starts and charged once the result is ready. - Uploads are free.
Error handling
Image and video jobs don’t return a 429 when you start many at once: they queue and start as capacity frees up. A job that fails returns
status: "failed" with a readable error, and isn’t charged.