All Products
Search
Document Center

Alibaba Cloud Model Studio:Referensi API Pengeditan Video Wan2.7

Last Updated:Jun 04, 2026

Model pengeditan video Wan 2.7 menerima input multimodal (teks, gambar, dan video) untuk pengeditan berbasis instruksi dan style transfer.

Dokumen terkait: Panduan

Berlaku untuk

Model, URL titik akhir, dan Kunci API harus berada dalam Wilayah yang sama. Pemanggilan lintas-Wilayah akan gagal.

Catatan

Contoh kode dalam topik ini menggunakan Singapore.

Penting

Domain lama https://dashscope-intl.aliyuncs.com untuk Wilayah Singapura akan segera ditinggalkan. Segera migrasi ke domain baru https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com.

HTTP

Tugas pengeditan video biasanya memerlukan waktu 1 hingga 5 menit. API menggunakan panggilan asinkron dengan dua langkah utama: Buat tugas → Polling hasil.

Langkah 1: Buat tugas

Singapura

POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

Saat memanggil, ganti WorkspaceId dengan Workspace ID yang sebenarnya.

Beijing

POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

Catatan
  • Setelah tugas dibuat, gunakan task_id yang dikembalikan untuk mengkueri hasilnya. task_id berlaku selama 24 jam. Jangan membuat tugas duplikat. Sebagai gantinya, gunakan polling untuk mengambil hasilnya.

  • Untuk panduan pemula, lihat Postman.

Parameter permintaan

Pengeditan hanya berbasis instruksi

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-videoedit",
        "input": {
            "prompt": "Convert the entire scene to a claymation style",
            "media": [
                {
                    "type": "video",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/ldnfdf/wan2.7-videoedit-style-change.mp4"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "prompt_extend": true,
            "watermark": true
        }
    }'

Pengeditan berbasis instruksi dan gambar referensi

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-videoedit",
        "input": {
            "prompt": "Replace the girl''s clothes in the video with the clothes from the image",
            "media": [
                {
                    "type": "video",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "prompt_extend": true,
            "watermark": true
        }
    }'

Content-Type string (Wajib)

Tipe konten dari permintaan. Harus berupa application/json.

Authorization string (Wajib)

Mengotentikasi permintaan dengan Kunci API Model Studio. Contoh: Bearer sk-xxxx.

X-DashScope-Async string (Wajib)

Mengaktifkan pemrosesan asinkron. Permintaan HTTP hanya mendukung panggilan asinkron. Harus diatur ke enable.

Penting

Jika header permintaan ini tidak ada, kesalahan "current user api does not support synchronous calls" akan dikembalikan.

Body permintaan

model string (Wajib)

Nama model.

Nilai contoh: wan2.7-videoedit.

input object (Wajib)

Parameter input, termasuk prompt.

Properti

prompt string (Opsional)

Menjelaskan elemen dan fitur visual yang diinginkan dalam video yang dihasilkan.

Bahasa Mandarin dan Inggris didukung. Setiap karakter Mandarin atau huruf Inggris dihitung sebagai satu karakter. Teks yang lebih panjang akan dipotong secara otomatis.

  • wan2.7-videoedit: maksimal 5.000 karakter.

Contoh nilai: Ganti pakaian karakter dengan busana yang keren dan mencolok, lalu tambahkan topi dari gambar referensi.

negative_prompt string (Opsional)

Prompt negatif yang menjelaskan konten yang harus dikecualikan dari video, yang membantu menyempurnakan output.

Bahasa Mandarin dan Inggris didukung. Panjangnya tidak boleh melebihi 500 karakter. Teks yang lebih panjang akan dipotong secara otomatis.

Nilai contoh: low resolution, error, worst quality, low quality, disfigured, extra fingers, bad proportions.

media array (Wajib)

Daftar aset media, seperti gambar dan video, yang digunakan sebagai referensi untuk pembuatan video.

Setiap elemen dalam array adalah objek media yang berisi bidang type dan url.

Properti

type string (Wajib)

Jenis aset media. Nilai yang valid:

  • video: Wajib. Video yang akan diedit.

  • reference_image: Opsional. Gambar referensi.

Batas aset:

  • Hanya satu video yang diperbolehkan.

  • Maksimal empat gambar referensi.

url string (Wajib)

URL atau data yang dikodekan Base64 dari aset media. Aset mencakup video dan gambar.

Video input (type=video)

URL file video yang akan diedit.

Persyaratan video:

  • Format: MP4, MOV.

  • Durasi: 2–10 detik.

  • Resolusi: Lebar dan tinggi harus antara 240 hingga 4096 piksel.

  • Rasio aspek: 1:8 hingga 8:1.

  • Ukuran file: Maksimal 100 MB.

Format input yang didukung:

  1. URL publik:

    • Protokol HTTP dan HTTPS didukung.

    • Nilai contoh: https://xxx/xxx.mp4.

Gambar input (type=reference_image)

URL atau data yang dikodekan Base64 dari gambar referensi.

Persyaratan gambar:

  • Format: JPEG, JPG, PNG (saluran alfa tidak didukung), BMP, WEBP.

  • Resolusi: Lebar dan tinggi harus antara 240 hingga 8000 piksel.

  • Rasio aspek: 1:8 hingga 8:1.

  • Ukuran file: Maksimal 20 MB.

Format input yang didukung:

  1. URL publik:

    • Protokol HTTP dan HTTPS didukung.

    • Nilai contoh: https://xxx/xxx.png.

  2. String yang dikodekan Base64:

    • Format data: data:{MIME_type};base64,{base64_data}.

    • Nilai contoh: data:image/png;base64,GDU7MtCZzEbTbmRZ...... (Contoh ini dipotong untuk keperluan demonstrasi).

    Format data yang dikodekan Base64

    Format: data:{MIME_type};base64,{base64_data} .

    • {base64_data}: String yang dikodekan Base64 dari file gambar.

    • {MIME_type}: Jenis media gambar, yang harus sesuai dengan format file.

    Format gambar

    Jenis MIME

    JPEG

    image/jpeg

    JPG

    image/jpeg

    PNG

    image/png

    BMP

    image/bmp

    WEBP

    image/webp

parameters object (Opsional)

Parameter untuk pemrosesan video, seperti resolusi, durasi, penulisan ulang prompt cerdas, dan watermark.

Properti

resolution string (Opsional)

Tingkat resolusi video yang dihasilkan, yang mengontrol kejernihannya (total piksel).

  • wan2.7-videoedit: Nilai yang valid adalah 720P dan 1080P. Nilai default adalah 1080P.

ratio string (Opsional)

Rasio aspek video yang dihasilkan.

Perilaku:

  • Jika Anda tidak menentukan parameter ratio, model akan menghasilkan video dengan rasio aspek yang mirip dengan video input.

  • Jika Anda menentukan parameter ratio, model akan menghasilkan video dengan ratio yang ditentukan.

Nilai yang valid:

  • 16:9

  • 9:16

  • 1:1

  • 4:3

  • 3:4

Lihat tabel di bawah ini untuk resolusi video output (lebar × tinggi) untuk berbagai rasio aspek.

Tingkat resolusi

Rasio aspek

Resolusi video output (lebar*tinggi)

720P

16:9

1280*720

9:16

720*1280

1:1

960*960

4:3

1104*832

3:4

832*1104

1080P

16:9

1920*1080

9:16

1080*1920

1:1

1440*1440

4:3

1648*1248

3:4

1248*1648

duration integer (Opsional)

Durasi video yang dihasilkan, dalam detik.

Rekomendasi: Tetapkan parameter ini hanya untuk memotong video. Untuk mempertahankan durasi yang sama dengan video input, abaikan parameter ini atau gunakan nilai default 0.

Aturan penggunaan:

  • Perilaku default: Nilai default adalah 0, yang berarti durasi video input digunakan tanpa pemotongan.

  • Pemotongan: Saat durasi tertentu diberikan, sistem akan memotong video asli dari detik ke-0 hingga panjang yang ditentukan oleh durasi.

  • Rentang nilai: Bilangan bulat dalam rentang [2, 10].

audio_setting string (Opsional)

Pengaturan suara video.

  • auto (Default): Model secara cerdas menentukan audio berdasarkan prompt. Jika prompt menggambarkan suara, audio baru mungkin dihasilkan. Jika tidak, audio asli dari aset input mungkin dipertahankan.

  • origin: Memaksa mempertahankan audio asli dari video input tanpa regenerasi.

prompt_extend boolean (Opsional)

Mengaktifkan penulisan ulang prompt cerdas. Saat diaktifkan, model besar akan menulis ulang prompt input, secara signifikan meningkatkan kualitas generasi untuk prompt yang lebih pendek dengan biaya peningkatan waktu pemrosesan.

  • true: Nilai default. Mengaktifkan penulisan ulang cerdas.

  • false: Menonaktifkan penulisan ulang cerdas.

watermark boolean (Opsional)

Apakah akan menambahkan Watermark. Watermark berada di pojok kanan bawah video dengan teks "AI Generated".

  • false (default)

  • true

Contoh: false.

seed integer (Opsional)

Seed bilangan acak harus berupa bilangan bulat dalam rentang [0, 2147483647].

Jika tidak ditentukan, seed acak akan dihasilkan. Seed tetap meningkatkan kemampuan reproduksi.

Karena generasi model bersifat probabilistik, seed yang sama tidak menjamin hasil yang identik.

Parameter respons

Respons berhasil

Simpan task_id untuk mengkueri status dan hasil tugas.

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

Respons kesalahan

Pembuatan tugas gagal. Lihat Kode kesalahan.

{
    "code": "InvalidApiKey",
    "message": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

output object

Berisi output tugas.

Properti

task_id string

ID tugas. Berlaku untuk kueri selama 24 jam.

task_status string

Status tugas.

Nilai enumerasi

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: Tugas tidak ada atau statusnya tidak diketahui.

request_id string

Identifier permintaan unik untuk pelacakan dan troubleshooting.

code string

Kode kesalahan. Hanya dikembalikan untuk permintaan yang gagal. Lihat Kode kesalahan.

message string

Pesan kesalahan detail. Hanya dikembalikan untuk permintaan yang gagal. Lihat Kode kesalahan.

Langkah 2: Kueri hasil

Singapura

GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}

Saat memanggil, ganti WorkspaceId dengan Workspace ID yang sebenarnya.

Beijing

GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}

Catatan
  • Rekomendasi polling: Pembuatan video memerlukan beberapa menit. Gunakan mekanisme polling dengan interval yang masuk akal, misalnya 15 detik.

  • Transisi status tugas: PENDING → RUNNING → SUCCEEDED atau FAILED.

  • Tautan hasil: Setelah tugas berhasil, URL video yang berlaku selama 24 jam akan dikembalikan. Unduh dan simpan video ke penyimpanan permanen, seperti OSS.

  • task_id masa berlaku: 24 jam. Setelah periode ini, kueri akan mengembalikan status tugas sebagai UNKNOWN.

Parameter permintaan

Kueri hasil

Ganti {task_id} dengan nilai task_id yang dikembalikan oleh panggilan API sebelumnya. task_id berlaku untuk kueri selama 24 jam.

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Header

Authorization string (Wajib)

Mengotentikasi permintaan menggunakan Kunci API Model Studio. Contoh: Bearer sk-xxxx.

Parameter path

task_id string (Wajib)

ID tugas.

Parameter respons

Task succeeded

URL video hanya berlaku selama 24 jam, lalu secara otomatis dipurge. Segera simpan video yang dihasilkan.

{
    "request_id": "f16ae7e9-d518-92f8-a02c-xxxxxx",
    "output": {
        "task_id": "05e68c7e-850c-49e4-b866-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-04-03 00:08:03.576",
        "scheduled_time": "2026-04-03 00:08:13.408",
        "end_time": "2026-04-03 00:11:57.286",
        "orig_prompt": "Replace the girl''s clothes in the video with the clothes from the image",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?xxxx"
    },
    "usage": {
        "duration": 10.04,
        "input_video_duration": 5.02,
        "output_video_duration": 5.02,
        "video_count": 1,
        "SR": 720
    }
}

Task failed

Jika task gagal, task_status bernilai FAILED disertai kode kesalahan dan pesan. Lihat Error codes.

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The size is not match xxxxxx"
    }
}

Expired query

task_id berlaku selama 24 jam. Setelah periode tersebut, kueri mengembalikan kesalahan berikut.

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

output object

Berisi output task.

Properties

task_id string

ID task. Berlaku untuk kueri selama 24 jam.

task_status string

Status task.

Enumeration values

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: Task tidak ada atau statusnya tidak diketahui.

State transitions during polling:

  • PENDING → RUNNING → SUCCEEDED atau FAILED.

  • Status kueri awal biasanya PENDING atau RUNNING.

  • Ketika status berubah menjadi SUCCEEDED, respons berisi URL video yang dihasilkan.

  • Jika statusnya FAILED, periksa pesan kesalahan dan coba ulang task tersebut.

submit_time string

Waktu saat task diajukan. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

scheduled_time string

Waktu saat task dieksekusi. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

end_time string

Waktu saat task selesai. Waktu dalam UTC+8 dan formatnya YYYY-MM-DD HH:mm:ss.SSS.

video_url string

URL video yang dihasilkan. Hanya dikembalikan jika task_status bernilai SUCCEEDED.

Berlaku selama 24 jam. Video dalam format MP4 dengan encoding H.264.

orig_prompt string

Prompt input asli, sesuai dengan parameter permintaan prompt.

code string

Kode kesalahan. Hanya dikembalikan untuk permintaan yang gagal. Lihat Error codes.

message string

Pesan kesalahan detail. Hanya dikembalikan untuk permintaan yang gagal. Lihat Error codes.

usage object

Statistik penggunaan untuk penagihan. Hanya task yang berhasil yang dikenai biaya.

Properties

input_video_duration float

Durasi video input, dalam detik.

output_video_duration float

Durasi video output, dalam detik.

duration float

Total durasi video, yang digunakan untuk penagihan.

Rumus penagihan: duration=input_video_duration+output_video_duration.

SR integer

Tingkat resolusi video output. Contoh nilai: 720.

video_count integer

Jumlah video yang dihasilkan. Nilai ini tetap 1.

request_id string

Identifier unik permintaan untuk pelacakan dan troubleshooting.

SDK DashScope

Nama parameter dalam SDK sebagian besar konsisten dengan API HTTP, tetapi struktur parameternya mengikuti konvensi masing-masing bahasa.

Pengeditan video biasanya memerlukan waktu 1 hingga 5 menit. SDK menangani proses panggilan HTTP asinkron secara internal, mendukung panggilan sinkron maupun asinkron.

Waktu pemrosesan aktual bergantung pada jumlah tugas dalam antrian dan status layanan. Tunggu hingga hasil selesai.

SDK Python

Penting

Pastikan Anda menggunakan SDK Python DashScope versi 1.25.16 atau lebih baru.

Menggunakan versi lama dapat memicu kesalahan seperti "url error, please check url!". Lihat Instal SDK untuk memperbarui versi Anda.

Tetapkan base_http_api_url berdasarkan Wilayah layanan:

Singapura

dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

Saat memanggil, ganti WorkspaceId dengan Workspace ID yang sebenarnya.

China (Beijing)

dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'

Panggilan sinkron

Contoh permintaan
import base64
import mimetypes
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# Berikut adalah URL untuk Wilayah Singapura. URL ini bersifat spesifik per Wilayah.
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# Jika variabel lingkungan DASHSCOPE_API_KEY belum diatur, masukkan Kunci API Model Studio Anda di sini: api_key="sk-xxx"
# Kunci API bersifat spesifik per Wilayah. Untuk mendapatkan Kunci API, kunjungi https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

# Formatnya adalah 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("Format gambar tidak didukung atau tidak dikenali.")
    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}"

# Parameter reference_image_url mendukung tiga metode input berikut.

# Metode 1: Gunakan URL publik gambar.
reference_image_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png"

# Metode 2: Gunakan file lokal (jalur absolut maupun relatif didukung).
# Format: file:// + jalur file
# Contoh (jalur absolut):
# reference_image_url = "file://" + "/path/to/image.png"     # Linux/macOS
# reference_image_url = "file://" + "C:/path/to/image.png"    # Windows
# Contoh (jalur relatif):
# reference_image_url = "file://" + "./image.png"             # Relatif terhadap lokasi skrip saat ini.

# Metode 3: String yang dikodekan Base64.
# reference_image_url = encode_file("/path/to/image.png")

def sample_sync_call_videoedit():
    # Panggil API secara sinkron; hasil akan langsung dikembalikan.
    print('Please wait...')
    rsp = VideoSynthesis.call(
        api_key=api_key,
        model='wan2.7-videoedit',
        prompt='Replace the clothes of the girl in the video with the clothes from the image.',
        media=[
            {
                "type": "video",
                "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4"
            },
            {
                "type": "reference_image",
                "url": reference_image_url
            }
        ],
        resolution='720P',
        prompt_extend=True,
        watermark=True)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

if __name__ == '__main__':
    sample_sync_call_videoedit()
Contoh respons
video_url berlaku selama 24 jam. Harap segera unduh video tersebut.
{
    "status_code": 200,
    "request_id": "d6c3c865-34e9-98a9-a53d-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "1de7c853-755a-454a-91bc-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
        "submit_time": "2026-04-10 17:16:30.821",
        "scheduled_time": "2026-04-10 17:16:46.379",
        "end_time": "2026-04-10 17:24:59.352",
        "orig_prompt": "Replace the clothes of the girl in the video with the clothes from the image."
    },
    "usage": {
        "video_count": 1,
        "video_duration": 0,
        "video_ratio": "",
        "duration": 10,08,
        "input_video_duration": 5,04,
        "output_video_duration": 5,04,
        "SR": 720
    }
}

Panggilan asinkron

Contoh permintaan
import base64
import mimetypes
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# Berikut adalah URL untuk Wilayah Singapura. URL ini bersifat spesifik per Wilayah.
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# Jika variabel lingkungan DASHSCOPE_API_KEY tidak diatur, masukkan Kunci API Model Studio Anda di sini: api_key="sk-xxx"
# Kunci API bersifat spesifik per Wilayah. Untuk mendapatkan Kunci API, kunjungi https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

# Formatnya adalah 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("Format gambar tidak didukung atau tidak dikenali.")
    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}"

# Parameter reference_image_url mendukung tiga metode input berikut.

# Metode 1: Gunakan URL publik gambar.
reference_image_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png"

# Metode 2: Gunakan file lokal (jalur absolut dan relatif didukung).
# Format: file:// + jalur file
# Contoh (jalur absolut):
# reference_image_url = "file://" + "/path/to/image.png"     # Linux/macOS
# reference_image_url = "file://" + "C:/path/to/image.png"    # Windows
# Contoh (jalur relatif):
# reference_image_url = "file://" + "./image.png"             # Relatif terhadap lokasi skrip saat ini.

# Metode 3: String yang dikodekan Base64.
# reference_image_url = encode_file("/path/to/image.png")

def sample_async_call_videoedit():
    # Panggil API asinkron, yang mengembalikan informasi tugas.
    # Anda kemudian dapat memeriksa status tugas menggunakan ID tugas yang dikembalikan.
    rsp = VideoSynthesis.async_call(
        api_key=api_key,
        model='wan2.7-videoedit',
        prompt='Replace the clothes of the girl in the video with the clothes from the image.',
        media=[
            {
                "type": "video",
                "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4"
            },
            {
                "type": "reference_image",
                "url": reference_image_url
            }
        ],
        resolution='720P',
        prompt_extend=True,
        watermark=True)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print("task_id: %s" % rsp.output.task_id)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

    # Dapatkan informasi tugas, yang mencakup status tugas.
    status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)  # Periksa status tugas.
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

    # Tunggu hingga tugas selesai. Metode ini melakukan polling secara berkala hingga tugas selesai.
    rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

if __name__ == '__main__':
    sample_async_call_videoedit()
Contoh respons
  1. Respons pembuatan tugas

    {
        "status_code": 200,
        "request_id": "f16ae7e9-d518-92f8-a02c-xxxxxx",
        "code": "",
        "message": "",
        "output": {
            "task_id": "05e68c7e-850c-49e4-b866-xxxxxx",
            "task_status": "PENDING",
            "video_url": ""
        },
        "usage": null
    }
  2. Respons kueri tugas

    video_url berlaku selama 24 jam. Harap segera unduh video tersebut.
    {
        "status_code": 200,
        "request_id": "d6c3c865-34e9-98a9-a53d-xxxxxx",
        "code": null,
        "message": "",
        "output": {
            "task_id": "1de7c853-755a-454a-91bc-xxxxxx",
            "task_status": "SUCCEEDED",
            "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
            "submit_time": "2026-04-10 17:16:30.821",
            "scheduled_time": "2026-04-10 17:16:46.379",
            "end_time": "2026-04-10 17:24:59.352",
            "orig_prompt": "Ganti pakaian gadis pada video dengan pakaian dari gambar."
        },
        "usage": {
            "video_count": 1,
            "video_duration": 0,
            "video_ratio": "",
            "duration": 10.08,
            "input_video_duration": 5.04,
            "output_video_duration": 5.04,
            "SR": 720
        }
    }

SDK Java

Penting

Pastikan Anda menggunakan SDK Java DashScope versi 2.22.14 atau lebih baru.

Penggunaan versi lama dapat memicu kesalahan seperti "url error, please check url!". Lihat Instal SDK untuk memperbarui versi Anda.

Tetapkan Constants.baseHttpApiUrl berdasarkan Wilayah layanan:

Singapura

Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";

Saat memanggil, ganti WorkspaceId dengan Workspace ID yang sebenarnya.

China (Beijing)

Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";

Panggilan sinkron

Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;

public class VideoEdit {

    static {
        // Berikut adalah URL untuk Wilayah Singapura. URL ini bersifat spesifik per Wilayah.
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // Jika variabel lingkungan DASHSCOPE_API_KEY tidak diatur, masukkan Kunci API Model Studio Anda di sini: apiKey="sk-xxx"
    // Kunci API bersifat spesifik per Wilayah. Untuk mendapatkan Kunci API, kunjungi https://www.alibabacloud.com/help/en/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    // Parameter referenceImageUrl mendukung tiga metode input berikut.

    // Metode 1: Gunakan URL publik gambar.
    static String referenceImageUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png";

    // Metode 2: Gunakan file lokal (jalur absolut maupun relatif didukung).
    // Format: file:// + jalur file
    // Contoh (jalur absolut):
    // static String referenceImageUrl = "file://" + "/path/to/image.png";     // Linux/macOS
    // static String referenceImageUrl = "file://" + "C:/path/to/image.png";   // Windows
    // Contoh (jalur relatif):
    // static String referenceImageUrl = "file://" + "./image.png";             // Relatif terhadap direktori eksekusi saat ini.

    // Metode 3: Gunakan encoding Base64.
    // static String referenceImageUrl = encodeFile("/path/to/image.png");

    // Formatnya adalah data:{MIME_type};base64,{base64_data}
    public static String encodeFile(String filePath) {
        Path path = Paths.get(filePath);
        if (!Files.exists(path)) {
            throw new IllegalArgumentException("File does not exist: " + filePath);
        }
        String mimeType = null;
        try {
            mimeType = Files.probeContentType(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot detect file type: " + filePath);
        }
        if (mimeType == null || !mimeType.startsWith("image/")) {
            throw new IllegalArgumentException("Unsupported or unrecognized image format.");
        }
        byte[] fileBytes = null;
        try {
            fileBytes = Files.readAllBytes(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot read file content: " + filePath);
        }
        String encodedString = Base64.getEncoder().encodeToString(fileBytes);
        return "data:" + mimeType + ";base64," + encodedString;
    }

    public static void videoEdit() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4")
                    .type("video")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url(referenceImageUrl)
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("prompt_extend", true);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-videoedit")
                        .prompt("Replace the clothes of the girl in the video with the clothes from the image.")
                        .media(media)
                        .parameters(parameters)
                        .build();
        System.out.println("Please wait...");
        VideoSynthesisResult result = vs.call(param);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            videoEdit();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
Contoh respons
video_url berlaku selama 24 jam. Harap segera unduh video tersebut.
{
    "request_id": "0a15ad3c-cde7-9f7e-b8d2-xxxxxx",
    "output": {
        "task_id": "0025d1e1-009a-4f53-9c27-xxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "orig_prompt": "Ganti pakaian gadis di video dengan pakaian dari gambar.",
        "submit_time": "2026-04-10 17:21:01.719",
        "scheduled_time": "2026-04-10 17:21:13.182",
        "end_time": "2026-04-10 17:31:41.286"
    },
    "usage": {
        "video_count": 1,
        "duration": 10.08,
        "input_video_duration": 5.04,
        "output_video_duration": 5.04,
        "SR": "720"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

Panggilan asinkron

Contoh permintaan
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;

public class VideoEdit {

    static {
        // Berikut ini adalah URL untuk Wilayah Singapura. URL bersifat spesifik per Wilayah.
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // Jika variabel lingkungan DASHSCOPE_API_KEY tidak diatur, masukkan Kunci API Model Studio Anda di sini: apiKey="sk-xxx"
    // Kunci API bersifat spesifik per Wilayah. Untuk mendapatkan Kunci API, kunjungi https://www.alibabacloud.com/help/en/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    // Parameter referenceImageUrl mendukung tiga metode input berikut.

    // Metode 1: Gunakan URL publik gambar.
    static String referenceImageUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png";

    // Metode 2: Gunakan file lokal (jalur absolut dan relatif didukung).
    // Format: file:// + jalur file
    // Contoh (jalur absolut):
    // static String referenceImageUrl = "file://" + "/path/to/image.png";     # Linux/macOS
    // static String referenceImageUrl = "file://" + "C:/path/to/image.png";   # Windows
    // Contoh (jalur relatif):
    // static String referenceImageUrl = "file://" + "./image.png";             # Relatif terhadap direktori eksekusi saat ini.

    // Metode 3: Gunakan encoding Base64.
    // static String referenceImageUrl = encodeFile("/path/to/image.png");

    // Formatnya adalah data:{MIME_type};base64,{base64_data}
    public static String encodeFile(String filePath) {
        Path path = Paths.get(filePath);
        if (!Files.exists(path)) {
            throw new IllegalArgumentException("File does not exist: " + filePath);
        }
        String mimeType = null;
        try {
            mimeType = Files.probeContentType(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot detect file type: " + filePath);
        }
        if (mimeType == null || !mimeType.startsWith("image/")) {
            throw new IllegalArgumentException("Unsupported or unrecognized image format.");
        }
        byte[] fileBytes = null;
        try {
            fileBytes = Files.readAllBytes(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot read file content: " + filePath);
        }
        String encodedString = Base64.getEncoder().encodeToString(fileBytes);
        return "data:" + mimeType + ";base64," + encodedString;
    }

    public static void videoEdit() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4")
                    .type("video")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url(referenceImageUrl)
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("prompt_extend", true);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-videoedit")
                        .prompt("Replace the clothes of the girl in the video with the clothes from the image.")
                        .media(media)
                        .parameters(parameters)
                        .build();

        // Lakukan panggilan asinkron.
        VideoSynthesisResult task = vs.asyncCall(param);
        System.out.println(JsonUtils.toJson(task));
        System.out.println("Please wait...");

        // Tunggu hingga tugas selesai dan ambil hasil akhirnya.
        VideoSynthesisResult result = vs.wait(task, apiKey);
        System.out.println(JsonUtils.toJson(result));
    }

    // Ambil daftar tugas.
    public static void listTask() throws ApiException, NoApiKeyException {
        VideoSynthesis is = new VideoSynthesis();
        AsyncTaskListParam param = AsyncTaskListParam.builder().build();
        param.setApiKey(apiKey);
        VideoSynthesisListResult result = is.list(param);
        System.out.println(result);
    }

    // Ambil hasil satu tugas.
    public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
        VideoSynthesis is = new VideoSynthesis();
        // apiKey bisa null jika variabel lingkungan DASHSCOPE_API_KEY telah diatur.
        VideoSynthesisResult result = is.fetch(taskId, apiKey);
        System.out.println(result.getOutput());
        System.out.println(result.getUsage());
    }

    public static void main(String[] args) {
        try {
            videoEdit();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
Contoh respons
  1. Respons pembuatan tugas

    {
        "request_id": "f16ae7e9-d518-92f8-a02c-xxxxxx",
        "output": {
            "task_id": "05e68c7e-850c-49e4-b866-xxxxxx",
            "task_status": "PENDING",
            "video_url": ""
        },
        "usage": null,
        "status_code": 200,
        "code": "",
        "message": ""
    }
  2. Respons kueri tugas

    video_url berlaku selama 24 jam. Harap segera unduh video tersebut.
    {
        "request_id": "0a15ad3c-cde7-9f7e-b8d2-xxxxxx",
        "output": {
            "task_id": "0025d1e1-009a-4f53-9c27-xxxxx",
            "task_status": "SUCCEEDED",
            "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
            "orig_prompt": "Replace the clothes of the girl in the video with the clothes from the image.",
            "submit_time": "2026-04-10 17:21:01.719",
            "scheduled_time": "2026-04-10 17:21:13.182",
            "end_time": "2026-04-10 17:31:41.286"
        },
        "usage": {
            "video_count": 1,
            "duration": 10,08,
            "input_video_duration": 5,04,
            "output_video_duration": 5,04,
            "SR": "720"
        },
        "status_code": 200,
        "code": "",
        "message": ""
    }

Kode kesalahan

Jika pemanggilan model gagal, lihat Kode Kesalahan untuk troubleshooting.