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

# Quick Start: Reference to Video

> Generate a video from a reference video or images and a text prompt.

Upload a reference video, describe the shot you want, and generate a new video that carries the reference's subject or style. Submit one request to `POST /v1/videos`, then poll `GET /v1/videos/{video_id}` for the finished video. This **H3 Video** mode includes native audio and also accepts reference images, with or without a reference video.

## What you need

* An API key from the [Viggle Dashboard](https://portal.viggle.ai/keys), exported as `VIGGLE_API_KEY`.
* Your reference video saved as `reference.mp4` in the directory where you run the example. It must be 0.5–600 seconds long, at least 64×64 pixels, with even width and height.
* For cURL, install `jq`; for Node, use Node.js 20+ and save the example as an `.mjs` file; for Python, install `requests` with `pip install requests`.

The examples upload your local file and request a 5-second output. Change the `prompt` to describe your desired shot. Both `prompt` and `quality` are required; use `low` for faster iteration or `high` for higher fidelity.

## Generate and poll the video

<CodeGroup>
  ```bash cURL theme={null}
  #!/usr/bin/env bash
  set -euo pipefail

  response=$(curl --fail-with-body -sS "https://apis.viggle.ai/v1/videos" \
    -H "Authorization: Bearer $VIGGLE_API_KEY" \
    -F prompt="keep the same outfit and walk forward" \
    -F quality=high \
    -F reference_video=@./reference.mp4 \
    -F duration_s=5)
  video_id=$(echo "$response" | jq -er '.id')

  for _ in $(seq 1 60); do
    video=$(curl --fail-with-body -sS "https://apis.viggle.ai/v1/videos/$video_id" \
      -H "Authorization: Bearer $VIGGLE_API_KEY")
    status=$(echo "$video" | jq -r '.status')

    case "$status" in
      ready)
        echo "$video" | jq -r '.video_url'
        exit 0
        ;;
      failed|cancelled)
        echo "Video $status: $(echo "$video" | jq -c '.error')" >&2
        exit 1
        ;;
    esac
    sleep 5
  done

  echo "Timed out waiting for video $video_id" >&2
  exit 1
  ```

  ```javascript Node theme={null}
  import { readFile } from "node:fs/promises";

  const baseUrl = "https://apis.viggle.ai/v1";
  const headers = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };
  const TERMINAL = new Set(["ready", "failed", "cancelled"]);

  async function createVideo() {
    const form = new FormData();
    form.append("prompt", "keep the same outfit and walk forward");
    form.append("quality", "high");
    form.append("reference_video", new Blob([await readFile("./reference.mp4")], { type: "video/mp4" }), "reference.mp4");
    form.append("duration_s", "5");

    const response = await fetch(`${baseUrl}/videos`, {
      method: "POST",
      headers,
      body: form,
    });
    if (!response.ok) {
      const body = await response.json().catch(() => ({}));
      throw new Error(`HTTP ${response.status}: ${JSON.stringify(body.error ?? body)}`);
    }
    return response.json();
  }

  async function waitForVideo(id) {
    for (let attempt = 0; attempt < 60; attempt++) {
      const response = await fetch(`${baseUrl}/videos/${id}`, { headers });
      if (!response.ok) {
        const body = await response.json().catch(() => ({}));
        throw new Error(`HTTP ${response.status}: ${JSON.stringify(body.error ?? body)}`);
      }
      const video = await response.json();
      if (TERMINAL.has(video.status)) return video;
      await new Promise((resolve) => setTimeout(resolve, 5000));
    }
    throw new Error(`Timed out waiting for video ${id}`);
  }

  const created = await createVideo();
  const video = await waitForVideo(created.id);

  if (video.status !== "ready") {
    throw new Error(`Video ${video.status}: ${JSON.stringify(video.error)}`);
  }
  console.log(video.video_url);
  ```

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

  base_url = "https://apis.viggle.ai/v1"
  headers = {"Authorization": f"Bearer {os.environ['VIGGLE_API_KEY']}"}
  TERMINAL_STATES = {"ready", "failed", "cancelled"}

  with open("./reference.mp4", "rb") as reference_video:
      response = requests.post(
          f"{base_url}/videos",
          headers=headers,
          data={
              "prompt": "keep the same outfit and walk forward",
              "quality": "high",
              "duration_s": 5,
          },
          files={"reference_video": ("reference.mp4", reference_video, "video/mp4")},
          timeout=120,
      )
  response.raise_for_status()
  video_id = response.json()["id"]

  for _ in range(60):
      response = requests.get(f"{base_url}/videos/{video_id}", headers=headers, timeout=30)
      response.raise_for_status()
      video = response.json()
      if video["status"] in TERMINAL_STATES:
          break
      time.sleep(5)
  else:
      raise TimeoutError(f"Timed out waiting for video {video_id}")

  if video["status"] != "ready":
      error = video.get("error") or {}
      raise RuntimeError(f"{video['status']}: {error.get('code')} {error.get('message')}")

  print(video["video_url"])
  ```
</CodeGroup>

## Response

```json theme={null}
{
  "id": "vid_3f2a9c",
  "status": "queued",
  "progress": null,
  "created_at": "2026-08-24T09:12:03Z"
}
```

The create request returns immediately with a video ID. The examples poll every 5 seconds and print `video_url` when `status` is `ready`; they stop on `failed`, `cancelled`, or a polling timeout. If polling times out, you can resume with the same ID using [Get Video](/v1/api-reference/videos/get).

Open the printed URL to view or download your video. The signed URL is valid for 1 hour; fetch Get Video again for a fresh link.

## Use a URL or reference images

* **Hosted video:** replace `reference_video` with `reference_video_url` containing your publicly reachable video URL. Supply at most one reference video across file uploads and URLs.
* **Add images:** include `reference_image` file uploads or `reference_image_url` fields alongside the video. Repeat these fields for up to 4 images in total.
* **Images only:** omit the video and supply at least one reference image. Keep `prompt` and `quality`.

<Note>
  Include at least one reference field; omitting all reference fields selects text-to-video generation. Do not combine reference fields with first/last-frame fields or Viggle-Animate's driving-video and character-image fields.
</Note>

`duration_s` controls the generated video's length (3–15 seconds, default `5`), independently of the reference video's length. See [Pricing and retention](/v1/pricing#h3-video) for generation costs.

<CardGroup cols={2}>
  <Card title="Generate Video (from Reference Video/Image)" icon="clapperboard" href="/v1/api-reference/videos/create-from-reference-video">
    See every parameter, reference-image examples, and validation errors.
  </Card>

  <Card title="Using Viggle-Animate" icon="person-running" href="/v1/api-reference/videos/create-from-character-animation">
    Apply a driving video's motion to character images.
  </Card>
</CardGroup>
