> ## 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 frame to video

> Animate a still image with Viggle H3. The image becomes the opening frame and your prompt describes what happens next.

First frame to video starts the clip on an image you supply and animates it from there. The opening frame keeps your image's subject, look and composition, and the prompt decides the motion and camera. Output is a 5–15 second MP4 with native audio.

Use it to bring a product shot, an illustration or a generated image to life. If you also know how the shot should end, use [First and last frame to video](https://docs.viggle.ai/v1/video/first-last-frame-to-video.md).

## What you send

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

| Parameter | Required | Notes |
| - | - | - |
| `prompt` | Yes | What should happen after the opening frame. Still required with an image |
| `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` | One of | The image as a file upload |
| `first_frame_image_url` | One of | A public `http(s)://` URL, or a base64 `data:` URI |
| `aspect_ratio` | No | Defaults to `16:9`. Set it to match your image |
| `duration_s` | No | 5–15 seconds. Default `5` |

Send the frame as a file or as a URL, not both. `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

| | Limit |
| - | - |
| Upload size | Up to 20 MiB |
| URL or `data:` URI size | Up to 30 MiB |
| 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 |

A first frame can't be combined with reference images or a reference video. Those belong to [Reference to video](https://docs.viggle.ai/v1/video/reference-to-video.md).

## Price

Same as every Viggle H3 mode: per second by `resolution`, plus $0.01 per second with `enhance` on. The image is 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. They use a sample character image hosted by Viggle; swap in your own URL 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 waves at the camera and starts to dance" \
  -F quality="high" \
  -F first_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-frame.mjs, then run: node first-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 waves at the camera and starts to dance");
form.append("quality", "high");
form.append("first_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 waves at the camera and starts to dance"),
    "quality": (None, "high"),
    "first_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 a local file instead, replace the URL field with `first_frame_image`:

```bash theme={null}
curl https://apis.viggle.ai/v1/videos \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="the character waves at the camera and starts to dance" \
  -F quality=high \
  -F first_frame_image=@first-frame.png
```

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

A bad image (unreadable, too large, or both a file and a URL) is rejected at create with `400 INVALID_REQUEST`, before anything is charged. See [Task lifecycle](https://docs.viggle.ai/v1/concepts/task-lifecycle.md) and [Errors](https://docs.viggle.ai/v1/production/errors.md).

## Tips

* Describe motion, not the picture. The image already sets the scene, so spend the prompt on what moves and how the camera behaves.
* Set `aspect_ratio` to match the image. It defaults to `16:9` whatever shape the image is.

## Next steps

> [card] [First and last frame to video](https://docs.viggle.ai/v1/video/first-last-frame-to-video.md)
>
> Control where the shot starts and where it ends.

> [card] [Reference to video](https://docs.viggle.ai/v1/video/reference-to-video.md)
>
> Keep a subject or style without fixing the opening 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.