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

# First and last frame to video

> Give Viggle H3 an opening and a closing frame and it generates the motion between them, with native audio.

First and last frame to video generates the shot between two images you supply. The clip opens on the first image, ends on the last, and the prompt describes how it gets from one to the other. Output is a 5–15 second MP4 with native audio.

Use it for transitions, before-and-after reveals, or a move between two known poses or camera positions. If only the opening matters, use [First frame to video](https://docs.viggle.ai/v1/video/first-frame-to-video.md).

## What you send

`POST /v1/videos` as `multipart/form-data`. Sending both a first frame and a last frame selects this mode.

| Parameter | Required | Notes |
| - | - | - |
| `prompt` | Yes | How the shot moves from the first frame to the last |
| `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 |
| `first_frame_image` or `first_frame_image_url` | Yes | The opening frame, as a file or a URL |
| `last_frame_image` or `last_frame_image_url` | Yes | The closing frame, as a file or a URL |
| `aspect_ratio` | No | Defaults to `16:9`. Set it to match your images |
| `duration_s` | No | 5–15 seconds. Default `5` |

Each frame is a file or a URL, not both, and the two frames can mix (for example an uploaded first frame and a hosted last frame). A last frame without a first frame is rejected with `400`. `resolution`, `enhance`, `seed` and `watermark` work as in every mode; see [Common parameters](https://docs.viggle.ai/v1/video/generate-video#common-parameters).

### Image limits

Both frames follow the same rules.

| | Limit |
| - | - |
| Upload size | Up to 20 MiB per image |
| URL or `data:` URI size | Up to 30 MiB per image. URLs must be public `http(s)://` |
| Formats | JPEG, PNG, WebP, GIF, BMP, TIFF, HEIC |
| Very large images | Images with a long edge of 3840 px or more, or a short edge of 2160 px or more, are scaled down to fit 1920×1080 (1080×1920 for portrait images), keeping their shape |

Frames can't be combined with reference images or a reference video.

## Price

Same as every Viggle H3 mode: per second by `resolution`, plus $0.01 per second with `enhance` on. The two images are free. 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. To stay runnable with no files of your own, they use the same sample image as both frames, which makes a loop that starts and ends on one pose. Swap in your own two URLs 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="the character spins around once and ends facing the camera again" \
  -F quality="low" \
  -F first_frame_image_url="https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp" \
  -F last_frame_image_url="https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp" | 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 first-last-frame.mjs, then run: node first-last-frame.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", "the character spins around once and ends facing the camera again");
form.append("quality", "low");
form.append("first_frame_image_url", "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp");
form.append("last_frame_image_url", "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp");
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, "the character spins around once and ends facing the camera again"),
    "quality": (None, "low"),
    "first_frame_image_url": (None, "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp"),
    "last_frame_image_url": (None, "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp"),
}))
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']}")
```

To upload local files instead, send `first_frame_image=@first.png` and `last_frame_image=@last.png` in place of the URL fields.

> [!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.

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

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] [First frame to video](https://docs.viggle.ai/v1/video/first-frame-to-video.md)
>
> Fix only the opening frame and let the prompt lead.

> [card] [Reference to video](https://docs.viggle.ai/v1/video/reference-to-video.md)
>
> Keep a subject or style without fixing any frame.

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