> ## 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.

# Reference to video

> Guide Viggle H3 with up to 6 reference images and 1 reference video to carry a subject or style into a new shot.

Reference to video generates a new shot that carries a subject, outfit or style from your own media. You give Viggle H3 a reference video, reference images, or both, plus a prompt for the new shot. Unlike the frame modes, no reference is pinned to a specific frame. Output is a 5–15 second MP4 with native audio.

Use it to keep a character consistent across shots, or to put a product or person from your photos into a scene you describe. To replace the people in an existing video while keeping its motion, use [Viggle Remake](https://docs.viggle.ai/v1/video/remake.md) instead.

## What you send

`POST /v1/videos` as `multipart/form-data`. Sending any reference field selects this mode.

| Parameter | Required | Notes |
| - | - | - |
| `prompt` | Yes | The new shot, and what to keep from the references |
| `quality` | Yes | `low` (faster) or `high` (higher fidelity), same price. Or [`ultrafast`](https://docs.viggle.ai/v1/video/generate-video#ultrafast), the fastest tier, priced separately |
| `reference_video` or `reference_video_url` | At least one reference | Up to 1 reference video in total, as a file or a URL |
| `reference_image` or `reference_image_url` | At least one reference | Up to 6 reference images in total. Repeat the field for each image; files and URLs can mix |
| `duration_s` | No | 5–15 seconds, default `5`. Independent of the reference video's length |

`resolution`, `aspect_ratio`, `enhance`, `seed` and `watermark` work as in every mode; see [Common parameters](https://docs.viggle.ai/v1/video/generate-video#common-parameters).

> [!NOTE]
>
> References can't be combined with `first_frame_image` or `last_frame_image` fields (`400`). Sending `driving_video` or `character_image` fields switches the request to [Viggle Remake](https://docs.viggle.ai/v1/video/remake.md).

### Media limits

| Input | Limit |
| - | - |
| Reference video | Up to 100 MiB, 0.5–600 seconds, at least 64×64 pixels, even width and height |
| Reference image upload | Up to 20 MiB each |
| Reference image URL or `data:` URI | Up to 30 MiB each |
| Image formats | JPEG, PNG, WebP, GIF, BMP, TIFF, HEIC |
| URLs | Public `http(s)://` URLs, or base64 `data:` URIs |

## Price

Same as every Viggle H3 mode: per second of output by `resolution`, plus $0.01 per second with `enhance` on. With `low` or `high`, references are free, and a long reference video costs the same as a short one. With [`ultrafast`](https://docs.viggle.ai/v1/video/generate-video#ultrafast), each second of reference video is billed, reference videos must be 2–15 seconds, and reference images past the fifth cost extra. The example below (5 seconds, 768p, enhance on) costs 10 credits ($0.10). See the [rate table](https://docs.viggle.ai/v1/video/generate-video#price).

## Generate a video

Export `VIGGLE_API_KEY` and run one of these as-is. They send a sample character image hosted by Viggle as the only reference; swap in your own media when you're ready. Each script polls every 5 seconds and prints the video URL. The cURL version needs `jq`.

```bash cURL theme={null}
#!/usr/bin/env bash
set -euo pipefail
API="https://apis.viggle.ai/v1"

video_id=$(curl -sS --fail-with-body "$API/videos" \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="this character skateboarding down a sunny hill, same outfit and colors" \
  -F quality="high" \
  -F reference_image_url="https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp" \
  -F duration_s="5" | jq -er '.id')
echo "Submitted $video_id"

for _ in $(seq 1 1440); do
  video=$(curl -sS --fail-with-body "$API/videos/$video_id" \
    -H "Authorization: Bearer $VIGGLE_API_KEY")
  case $(echo "$video" | jq -r '.status') in
    ready) echo "$video" | jq -r '.video_url'; exit 0 ;;
    failed|cancelled) echo "$video" | jq -c '.error' >&2; exit 1 ;;
  esac
  sleep 5
done
echo "Timed out waiting for $video_id" >&2; exit 1
```

```javascript Node.js theme={null}
// Node.js 20+. Save as reference-to-video.mjs, then run: node reference-to-video.mjs
const API = "https://apis.viggle.ai/v1";
const headers = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };

async function call(path, init = {}) {
  const res = await fetch(`${API}${path}`, { ...init, headers });
  const body = await res.json();
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${JSON.stringify(body.error)}`);
  return body;
}

const form = new FormData();
form.append("prompt", "this character skateboarding down a sunny hill, same outfit and colors");
form.append("quality", "high");
form.append("reference_image_url", "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp");
form.append("duration_s", "5");
const { id } = await call("/videos", { method: "POST", body: form });
console.log(`Submitted ${id}`);

for (let i = 0; i < 1440; i++) {
  const video = await call(`/videos/${id}`);
  if (video.status === "ready") {
    console.log(video.video_url);
    process.exit(0);
  }
  if (video.status === "failed" || video.status === "cancelled") {
    throw new Error(`${video.status}: ${JSON.stringify(video.error)}`);
  }
  await new Promise((resolve) => setTimeout(resolve, 5000));
}
throw new Error(`Timed out waiting for ${id}`);
```

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

import requests

API = "https://apis.viggle.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['VIGGLE_API_KEY']}"}


def check(resp):
    if not resp.ok:
        raise RuntimeError(f"HTTP {resp.status_code}: {resp.text}")
    return resp.json()


# Passing fields through files= makes requests send multipart/form-data.
video = check(requests.post(f"{API}/videos", headers=HEADERS, timeout=300, files={
    "prompt": (None, "this character skateboarding down a sunny hill, same outfit and colors"),
    "quality": (None, "high"),
    "reference_image_url": (None, "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp"),
    "duration_s": (None, "5"),
}))
print("Submitted", video["id"])

for _ in range(1440):
    video = check(requests.get(f"{API}/videos/{video['id']}", headers=HEADERS))
    if video["status"] == "ready":
        print(video["video_url"])
        break
    if video["status"] in ("failed", "cancelled"):
        raise RuntimeError(f"{video['status']}: {video['error']}")
    time.sleep(5)
else:
    raise TimeoutError(f"Timed out waiting for {video['id']}")
```

> [!WARNING]
>
> If your balance can't cover the job, the request is still accepted, and the job then ends `failed` with `error.code: "INSUFFICIENT_CREDITS"`. Check `GET /v1/credits` before large batches.

## Other ways to send references

Repeat a field to send several values. Files and URLs can mix, as long as the totals stay within 1 video and 6 images.

```bash Video file theme={null}
curl https://apis.viggle.ai/v1/videos \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="keep the same outfit and walk forward through a neon-lit street" \
  -F quality=low \
  -F reference_video=@reference.mp4
```

```bash Video and images theme={null}
curl https://apis.viggle.ai/v1/videos \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="the character from the photos performing the dance from the clip" \
  -F quality=low \
  -F reference_video_url=https://assets.viggle.ai/pub/www/developers/sample-motion-97bb074a.mp4 \
  -F reference_image=@character-front.png \
  -F reference_image=@character-side.png
```

## Get the result

The create call returns a `vid_` ID with `status: "queued"`. Poll `GET /v1/videos/{video_id}` until `status` is `ready`, then download `video_url`.

* The link is valid for one hour, and every read returns a fresh one.
* The video is deleted 24 hours after the job finishes. Copy it to your own storage.
* Only the API key that created the job can read it.

More than 1 reference video or 6 reference images, or references mixed with frame fields, is rejected at create with `400 INVALID_REQUEST`. See [Task lifecycle](https://docs.viggle.ai/v1/concepts/task-lifecycle.md) and [Errors](https://docs.viggle.ai/v1/production/errors.md).

## Next steps

> [card] [Viggle Remake](https://docs.viggle.ai/v1/video/remake.md)
>
> Keep a video's motion and replace the people in it.

> [card] [First frame to video](https://docs.viggle.ai/v1/video/first-frame-to-video.md)
>
> Pin the opening frame to an exact image.

> [card] [Viggle H3 overview](https://docs.viggle.ai/v1/video/generate-video)
>
> All four modes, common parameters and prices.

> [card] [Create a video (API reference)](https://docs.viggle.ai/v1/api-reference/videos/create-a-video.md)
>
> Every field, limit and error for `POST /v1/videos`.


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