> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pictory.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Video from Reference Images

> Create AI-generated videos guided by one or more reference images using the Pictory AI Studio API

This guide shows you how to generate an AI video using reference images along with a text prompt. By providing up to four reference images, you can influence the subjects, style, and composition of the generated video. This is particularly useful for combining elements from multiple images into a single video scene.

## What You Will Build

> [card] Multi-Image Reference
>
> Use up to four images to guide the video output

> [card] Subject Composition
>
> Combine subjects from different images into one scene

> [card] Visual Consistency
>
> Maintain character or scene appearance across generations

> [card] Creative Direction
>
> Steer the video style and content with visual references

## Before You Begin

Make sure you have:

* A [Pictory API key](https://app.pictory.ai/api-access)
* Node.js or Python installed on your machine
* The required packages installed
* One to four publicly accessible image URLs to use as references (up to 3 on Veo, one on Omni Flash)

```bash npm theme={null}
npm install axios
```

```bash pip theme={null}
pip install requests
```

## Step-by-Step Guide

### Step 1: Set Up Your Request

Prepare your API credentials, the reference image URLs, and a prompt that describes the desired video. The prompt should explain how the subjects or elements from the reference images should appear in the video.

```javascript Node.js theme={null}
import axios from "axios";

const API_BASE_URL = "https://api.pictory.ai/pictoryapis";
const API_KEY = "YOUR_API_KEY"; // Replace with your actual API key

// Video generation with reference images
const videoRequest = {
  prompt: "The woman from the first image walks through the open field from the second image, approaching the farmhouse in the distance in a wide shot",
  referenceImageUrls: [
    "https://example.com/images/woman-portrait-outdoor.png",
    "https://example.com/images/green-field-farmhouse.png"
  ],
  model: "pixverse6",
  aspectRatio: "9:16",
  duration: "8s"
};
```

```python Python theme={null}
import requests
import time

API_BASE_URL = "https://api.pictory.ai/pictoryapis"
API_KEY = "YOUR_API_KEY"  # Replace with your actual API key

# Video generation with reference images
video_request = {
    "prompt": "The woman from the first image walks through the open field from the second image, approaching the farmhouse in the distance in a wide shot",
    "referenceImageUrls": [
        "https://example.com/images/woman-portrait-outdoor.png",
        "https://example.com/images/green-field-farmhouse.png"
    ],
    "model": "pixverse6",
    "aspectRatio": "9:16",
    "duration": "8s"
}
```

> [!NOTE]
>
> The `referenceImageUrls` array accepts up to 4 image URLs on `pixverse6` and `pixverse5.6`, up to 3 on `veo3.1`, and 1 on `omni-flash`. All URLs must point to publicly accessible images. This parameter cannot be used together with `firstFrameImageUrl` or `extendVideoUrl`. On `veo3.1`, a request with reference images must use an `8s` duration.

### Step 2: Submit the Video Generation Request

Send the request to the AI Studio video generation endpoint.

```javascript Node.js theme={null}
async function generateVideoFromReferences() {
  try {
    console.log("Submitting reference-based video generation request...");

    const response = await axios.post(
      `${API_BASE_URL}/v1/aistudio/videos`,
      videoRequest,
      {
        headers: {
          "Content-Type": "application/json",
          Authorization: API_KEY,
        },
      }
    );

    const jobId = response.data.data.jobId;
    console.log("Video generation started.");
    console.log("Job ID:", jobId);

    return jobId;
  } catch (error) {
    console.error("Error submitting request:", error.response?.data || error.message);
    throw error;
  }
}
```

```python Python theme={null}
def generate_video_from_references():
    try:
        print("Submitting reference-based video generation request...")

        response = requests.post(
            f"{API_BASE_URL}/v1/aistudio/videos",
            json=video_request,
            headers={
                "Content-Type": "application/json",
                "Authorization": API_KEY
            }
        )
        response.raise_for_status()

        job_id = response.json()["data"]["jobId"]
        print("Video generation started.")
        print(f"Job ID: {job_id}")

        return job_id

    except requests.exceptions.RequestException as error:
        print(f"Error submitting request: {error}")
        raise
```

### Step 3: Poll for the Result

Check the job status at regular intervals until the video is ready.

```javascript Node.js theme={null}
async function waitForVideo(jobId) {
  console.log("\nPolling for video generation result...");

  while (true) {
    const response = await axios.get(
      `${API_BASE_URL}/v1/jobs/${jobId}`,
      {
        headers: { Authorization: API_KEY },
      }
    );

    const data = response.data;
    const status = data.data.status;
    console.log("Status:", status);

    if (status === "completed") {
      console.log("\nVideo generated successfully!");
      console.log("Video URL:", data.data.url);
      console.log("Duration:", data.data.duration);
      console.log("Dimensions:", data.data.width, "x", data.data.height);
      console.log("AI Credits Used:", data.data.aiCreditsUsed);
      return data;
    }

    if (status === "failed") {
      throw new Error("Video generation failed: " + JSON.stringify(data));
    }

    // Wait 15 seconds before polling again
    await new Promise(resolve => setTimeout(resolve, 15000));
  }
}

// Run the complete workflow
generateVideoFromReferences()
  .then(jobId => waitForVideo(jobId))
  .then(result => console.log("\nDone!"))
  .catch(error => console.error("Error:", error));
```

```python Python theme={null}
def wait_for_video(job_id):
    print("\nPolling for video generation result...")

    while True:
        response = requests.get(
            f"{API_BASE_URL}/v1/jobs/{job_id}",
            headers={"Authorization": API_KEY}
        )
        response.raise_for_status()

        data = response.json()
        status = data["data"]["status"]
        print(f"Status: {status}")

        if status == "completed":
            print("\nVideo generated successfully!")
            print(f"Video URL: {data['data']['url']}")
            print(f"Duration: {data['data']['duration']}")
            print(f"Dimensions: {data['data']['width']} x {data['data']['height']}")
            print(f"AI Credits Used: {data['data']['aiCreditsUsed']}")
            return data

        if status == "failed":
            raise Exception(f"Video generation failed: {data}")

        # Wait 15 seconds before polling again
        time.sleep(15)

# Run the complete workflow
if __name__ == "__main__":
    job_id = generate_video_from_references()
    result = wait_for_video(job_id)
    print("\nDone!")
```

## Understanding the Parameters

| Parameter | Type | Required | Default | Description |
| - | - | - | - | - |
| `prompt` | string | Yes | - | A text description that explains how the reference images should be used in the video. Must be between 5 and 5,000 characters. |
| `referenceImageUrls` | array of strings | No | - | An array of publicly accessible image URLs to guide the generation: up to 4 on `pixverse6` and `pixverse5.6`, up to 3 on `veo3.1`, and 1 on `omni-flash`. Each entry must be a valid URI. Cannot be used together with `firstFrameImageUrl` or `extendVideoUrl`. |
| `model` | string | No | `pixverse5.6` | The AI model to use for generation. Supported values: `pixverse6`, `pixverse5.6`, `veo3.1`, `omni-flash`. See [Generate Video API](https://docs.pictory.ai/api-reference/ai-studio/generate-video.md) for model capabilities and pricing. |
| `aspectRatio` | string | No | First supported ratio of the selected model | The output aspect ratio. Valid values depend on the model. For example, `pixverse6` supports eight ratios including `21:9` and `2:3`, `pixverse5.6` supports `16:9`, `9:16`, `1:1`, `3:4`, `4:3`, and `veo3.1` supports `16:9`, `9:16`. |
| `duration` | string | No | First supported duration of the selected model | The video length. Valid values depend on the model. For example, `pixverse6` supports `5s`, `8s`, `10s`, `15s`, `pixverse5.6` supports `5s`, `8s`, `10s`, and `veo3.1` supports `4s`, `6s`, `8s`. |
| `audio` | boolean | No | `false` | Generate synchronized audio with the video. Billed at the model's with-audio rate. Always on for `omni-flash`. See [Generate Video with Audio](https://docs.pictory.ai/guides/ai-studio/video-with-audio.md). |
| `trainingPreset` | string | No | - | `sales-training`, `product-training`, or `soft-skills-training`. Steers prompt enhancement and always turns it on, even when `enhancePrompt` is `false`. |
| `enhancePrompt` | boolean | No | `false` | Set to `true` to rewrite the prompt with the AI enhancer before generation. Off by default: the prompt is sent verbatim. |
| `webhook` | string | No | - | A URL to receive a POST notification when the job completes. Must be a valid URI. |

## Use Cases for Reference Images

| Use Case | Number of Images | Description |
| - | - | - |
| **Character consistency** | 1 | Provide a character portrait to maintain appearance across video generations |
| **Scene composition** | 2 | Combine a character image with a background or environment image |
| **Multi-subject scenes** | 2 to 4 | Provide images of different subjects that should appear together in the video |
| **Style reference** | 1 | Use an image with the desired visual style to influence the output |

## Tips for Reference Image Videos

* **Describe the relationship between images.** In your prompt, explain how the elements from each reference should interact. For example, "The person from the first image walks into the landscape from the second image."
* **Use high-quality references.** Clear, well-lit images produce better results. Avoid blurry or heavily compressed images.
* **Keep subjects distinct.** When combining multiple images, ensure each reference contributes a clearly identifiable element such as a character, background, or object.
* **Name each reference.** On `pixverse6` and `pixverse5.6`, refer to the images as `@subject1`, `@subject2`, and so on, in array order, so the model binds each mention to the right image. Any reference you do not mention is appended to the prompt automatically.
* **Use 8s on Veo.** `veo3.1` only generates 8-second videos from reference images; other durations are rejected before any credits are reserved.

## Next Steps

* [Generate Video from Text Prompt](https://docs.pictory.ai/guides/ai-studio/text-to-video.md) to create videos without reference images
* [Generate Video from First Frame](https://docs.pictory.ai/guides/ai-studio/video-from-first-frame.md) to animate from a specific starting frame
* [Extend Video with AI](https://docs.pictory.ai/guides/ai-studio/extend-video.md) to continue an existing video
* [Generate Video API Reference](https://docs.pictory.ai/api-reference/ai-studio/generate-video.md) for the complete parameter documentation


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.