Skip to main content
First frame

Wan — animate from first frame

Submit image-to-video task

POST
https://ap-southeast-1.maas.qwencloudapi.com/api/v1/services/aigc/video-generation/video-synthesis
import base64
import os
import mimetypes
import dashscope

# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = dashscope.Client(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://ap-southeast-1.maas.qwencloudapi.com/api/v1",
)

# --- Helper function: For Base64 encoding ---
# Format: data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
  mime_type, _ = mimetypes.guess_type(file_path)
  if not mime_type or not mime_type.startswith("image/"):
    raise ValueError("Unsupported or unrecognized image format")
  with open(file_path, "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
  return f"data:{mime_type};base64,{encoded_string}"

"""
Image input methods:
Choose one of the following three methods,

1. Use a public URL - Suitable for publicly accessible images
2. Use a local file - Suitable for local development and testing
3. Use Base64 encoding - Suitable for private images or scenarios requiring encrypted transmission
"""

# [Method 1] Use a publicly accessible image URL
# Example: Use a public image URL
img_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"

# [Method 2] Use a local file (supports absolute and relative paths)
# Format requirement: file:// + file path
# Example (absolute path):
# img_url = "file://" + "/path/to/your/img.png"    # Linux/macOS
# img_url = "file://" + "/C:/path/to/your/img.png"  # Windows
# Example (relative path):
# img_url = "file://" + "./img.png"                # Relative to the current executable file's path

# [Method 3] Use a Base64-encoded image
# img_url = encode_file("./img.png")

# Set audio URL
audio_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"

def sample_call_i2v():
  # Synchronous call, returns result directly
  print('please wait...')
  job = client.videos.generate(
    model='wan2.6-i2v-flash',
    prompt='A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life from a concrete wall. He raps an English song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The lighting comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.',
    image_url=img_url,
    extra_input={'audio_url': audio_url, 'negative_prompt': ""},
    resolution="720P",
    duration=10,
    prompt_extend=True,
    watermark=False,
    seed=12345)
  print(job)
  print("video_url:", job.video_url)

if __name__ == '__main__':
  sample_call_i2v()
{
  "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx",
  "output": {
    "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx",
    "task_status": "PENDING"
  }
}
Generate a video from a first-frame image and text prompt.

Authorizations

string
header
required

DashScope API Key. Create one in the QwenCloud console.

Header Parameters

enum<string>
required

Must be set to enable. HTTP requests support only asynchronous processing. Omitting this header returns a "current user api does not support synchronous calls" error.

enable

Body

application/json
enum<string>
required

Model name. For Wan 2.1 in China North 2 (Beijing) (cn-beijing), use the wanx2.1-* form: wanx2.1-i2v-plus and wanx2.1-i2v-turbo.

wan2.6-i2v-flash,wan2.6-i2v,wan2.5-i2v-preview,wan2.2-i2v-flash,wan2.2-i2v-plus,wan2.1-i2v-turbo,wan2.1-i2v-plus,wanx2.1-i2v-plus,wanx2.1-i2v-turbo
wan2.6-i2v-flash
object
required

Input data including the first-frame image, prompt, and optional audio.

object

Video generation parameters.

Response

200-application/json
string

Unique request identifier for tracing and troubleshooting.

4909100c-7b5a-9f92-bfe5-xxxxxx
object