# Wan 2.7 Ref2V

> Generate videos from multiple reference images and videos using FlyMyAI's Wan 2.7 Ref2V model.

The `flymyai/wan-2_7-ref2v` model generates a video guided by one or more **reference images and/or videos**, optionally paired with reference audio/voice clips. This lets you condition generation on specific subjects, objects, or characters supplied via the `references` field, instead of (or in addition to) a text prompt.

## Installation

```bash
pip install flymyai
```

## Usage

```python
# Install the FlyMyAI package
# pip install flymyai
from flymyai import client, FlyMyAIPredictException
import json

# Set secret api key. You can find your api key in the profile settings
apikey = "fly-***"

# Set the model name
model = "flymyai/wan-2_7-ref2v"

# Reference images/videos with optional reference voice/audio
references = [
    {
        "type": "reference_image",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/sjuytr/wan-r2v-object-girl.jpg",
        "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3"
    },
    {
        "type": "reference_video",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4",
        "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3"
    },
    {
        "type": "reference_image",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png"
    },
    {
        "type": "reference_image",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png"
    },
    {
        "type": "reference_image",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
    }
]

# Prepare the input data
payload = {
    "prompt": "A cat attempts a daring jump across a gap, but hilariously miscalculates.",
    "negative_prompt": None,
    "duration": 5,
    "shot_type": None,
    "watermark": False,
    "seed": 42,
    "resolution": "1080P",
    "references": json.dumps(references),
    "enable_safety_checker": True
}

# Initialize the client
fma_client = client(apikey=apikey)
try:
    response = fma_client.predict(
        model=model,
        payload=payload
    )
    # Process the output data
    print(f"video_url: {response.output_data['video_url']}")
except FlyMyAIPredictException as e:
    print(e)
    raise e
```

## Input parameters

| Parameter | Type | Required | Description |
|---|---|---|---|
| `prompt` | `string` | No | Text description guiding the generated video. |
| `negative_prompt` | `string` | No | Text describing what to avoid in the generated video. |
| `duration` | `integer` | No | Duration of the generated video, in seconds. |
| `shot_type` | `string` | No | Camera/shot type hint for generation. |
| `watermark` | `boolean` | No | Whether to add a watermark to the output video. Defaults to `false`. |
| `seed` | `integer` | No | Random seed for reproducible generation. |
| `resolution` | `string` | No | Output video resolution, e.g. `"1080P"`. |
| `references` | `string` (JSON-encoded array of objects) | Yes | List of reference images/videos (and optional reference audio) used to condition generation. See [`references` format](#references-format) below. |
| `enable_safety_checker` | `boolean` | No | Whether to run generated output through the safety checker. Defaults to `true`. |

> **Note**
>
> The `references` field must be passed as a **JSON-encoded string**, not a raw Python list/dict. Use `json.dumps(...)` when building the payload, as shown in the example above.

### `references` format

`references` is a JSON array of objects, each describing a single reference asset:

| Field | Type | Required | Description |
|---|---|---|---|
| `type` | `string` | Yes | Type of reference asset. One of `"reference_image"` or `"reference_video"`. |
| `url` | `string` | Yes | Publicly accessible URL to the reference image or video file. |
| `reference_voice` | `string` | No | Publicly accessible URL to a reference audio/voice clip (`.mp3`) associated with this reference. |

Example:

```json
[
    {
        "type": "reference_image",
        "url": "https://example.com/girl.jpg",
        "reference_voice": "https://example.com/girl-voice.mp3"
    },
    {
        "type": "reference_video",
        "url": "https://example.com/role2.mp4",
        "reference_voice": "https://example.com/boy-voice.mp3"
    },
    {
        "type": "reference_image",
        "url": "https://example.com/object3.png"
    }
]
```

- You may mix `reference_image` and `reference_video` entries in the same list.
- `reference_voice` is optional per-entry — omit it if no associated audio is needed for that reference.
- At least one reference entry is required.

## Output

| Field | Type | Description |
|---|---|---|
| `video_url` | `string` | URL of the generated video. |

```python
print(f"video_url: {response.output_data['video_url']}")
```
