全部產品
Search
文件中心

Alibaba Cloud Model Studio:萬相2.7-參考生視頻API參考

更新時間:Jul 03, 2026

萬相-參考生視頻模型支援多模態輸入(圖片、視頻、音頻),產生保持角色形象和音色一致性的視頻,適用於單角色表演或多角色互動情境。

相關文檔使用指南

適用範圍

為確保調用成功,請務必保證模型、Endpoint URL和API Key 均屬於同一地區。跨地區調用將會失敗。

說明

本文的範例程式碼適用於新加坡地區

重要

阿里雲百鍊為華北2(北京)、新加坡地區推出了業務空間專屬網域名稱,能夠為推理請求提供卓越的效能和更高的穩定性,建議遷移至新網域名稱:

  • 華北2(北京)地區:從 https://dashscope.aliyuncs.com 遷移至 https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com

  • 新加坡地區:從 https://dashscope-intl.aliyuncs.com 遷移至 https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com

其中 {WorkspaceId} 為您的業務空間 ID,可在阿里雲百鍊控制台的業務空間詳情頁面查看。現有網域名稱仍可正常使用。

HTTP調用

重要

此介面為新版協議,支援wan2.7模型

由於視頻產生任務耗時較長(通常為1-5分鐘),API採用非同步呼叫。整個流程包含 “建立任務 -> 輪詢擷取” 兩個核心步驟,具體如下:

步驟1:建立任務擷取任務ID

新加坡

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

北京

POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

調用時請將{WorkspaceId}替換為真實的業務空間ID

說明
  • 建立成功後,使用介面返回的 task_id 查詢結果,task_id 有效期間為 24 小時。請勿重複建立任務,輪詢擷取即可。

  • 新手指引請參見Postman

請求參數

多主體參考(映像+視頻+音色)

傳入多張參考素材(映像+視頻),並指定音色產生視頻。

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-r2v-2026-06-12",
        "input": {
            "prompt": "視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 ",
            "media": [
                {
                    "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"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "ratio": "16:9",
            "duration": 10,
            "prompt_extend": false,
            "watermark": true
        }
    }'

單圖參考(多宮格映像)

傳入一張九宮格參考圖,可以控制故事走向、機位構圖與角色設定,產生視頻。

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-r2v-2026-06-12",
        "input": {
            "prompt": "參考圖片,3D卡通冒險電影風,角色Q版但材質細膩,動作流暢,色彩鮮明,保持角色與森林情境一致,不要加入文字。氛圍: 冒險、輕快、神秘、童趣。角色: 小男孩探險家:圓帽、背包、短鬥篷。小夥伴:會飛的小機器人,圓形身體,藍色發光眼。情境: 奇幻森林,巨大樹根、蘑菇、藤蔓、藏寶洞口、陽光光束。分鏡指令碼: 1. 全景:奇幻森林裡高大樹木與光束交錯,環境神秘明亮。 2. 中景:小男孩撥開藤蔓向前探路。 3. 中景:小機器人飛在他身邊,用藍光掃描前方。 4. 特寫:一張舊藏寶圖在男孩手裡展開。 5. 近景:他露出興奮表情,眼睛亮起來。 6. 動作鏡頭:兩人跳過樹根和小溪,繼續深入森林。 7. 中景:藤蔓後方露出一個被苔蘚覆蓋的寶箱。 8. 特寫:寶箱邊緣閃出金色光芒。 9. 收束鏡頭:男孩和小機器人站在寶箱前驚喜對望,冒險感拉滿。",
            "media": [
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/wgjaxy/banana_storyboard_00000020.png"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "duration": 10,
            "prompt_extend": false,
            "watermark": true
        }
    }'
要求標頭(Headers)

Content-Type string (必選)

請求內容類型。此參數必須設定為application/json

Authorization string(必選)

請求身份認證。介面使用阿里雲百鍊API Key進行身份認證。樣本值:Bearer sk-xxxx。

X-DashScope-Async string (必選)

非同步處理配置參數。HTTP請求只支援非同步,必須設定為enable

重要

缺少此要求標頭將報錯:“current user api does not support synchronous calls”。

請求體(Request Body)

model string (必選)

模型名稱。模型列表與價格詳見模型價格

樣本值:wan2.7-r2v、wan2.7-r2v-2026-06-12。

input object (必選)

輸入的基本資料,如提示詞等。

屬性

prompt string (必選)

文本提示詞。用來描述產生視頻中期望包含的元素和視覺特點。

支援中英文,每個漢字、字母、標點佔一個字元,超過部分會自動截斷。

  • wan2.7-r2v、wan2.7-r2v-2026-06-12:不超過5000個字元。

參考指代:當為中文提示詞時,參考圖片時通過“圖1、圖2”這類標識指代,參考視頻時通過“視頻1、視頻2”這類標識指代。英文提示詞則寫為“Image 1”、"Video 1”這類標識。英文字母和數字之間有空格,首字母大寫。順序與media數組順序一致。圖和視頻分別計數,即同時存在圖1、視頻1等標識。若參考素材有且僅有一張圖片或一個視頻,則可簡化表述為”參考圖片”或“參考視頻”。

畫面描述:假設參考圖1是一隻貓,圖2是一個房間,要描述貓在房間裡玩耍,支援兩種寫法:一種是直接使用標識指代(如“圖1在圖2裡玩耍”);另一種是結合主體與情境補充說明(如“圖1的貓在圖2的房間裡玩耍”)。

當參考圖片為多宮格(故事板映像)時,提示詞建議按照多分鏡的形式描述畫面內容。無需描述每個宮格,提供關鍵分鏡內容即可,模型將自動識別宮格邏輯並智能補全鏡頭內容。為達到更好的效果,建議單次僅輸入一張多宮格圖。

提示詞的提示請參見文生視頻/圖生視頻Prompt指南

negative_prompt string (可選)

反向提示詞,用來描述不希望在視頻畫面中出現的內容,可以對視頻畫面進行限制。

支援中英文,長度不超過500個字元,超過部分會自動截斷。

樣本值:低解析度、錯誤、最差品質、低品質、殘缺、多餘的手指、比例不良等。

media array (必選)

媒體素材數組,素材包括映像、視頻和音頻。支援映像/視頻輸入作為視覺參考,映像支援多視圖,常見參考角色、道具、情境等。

  • 數組中每個元素為一個媒體對象,包含 typeurl 欄位。

  • 按照數組順序定義prompt中動作項目參考的順序。圖和視頻分別計數,即可同時存在圖1、視頻1。

    • 數組中的第 1 個reference_video 對應 視頻1,第 2 個對應 視頻2,以此類推。

    • 數組中的第 1 個reference_image對應 圖1,第 2 個對應 圖2,以此類推。

屬性

type string (必選)

媒體素材類型。可選值為:

  • reference_image:參考映像。提供主體角色(人物/動物/物體)和情境參考。

  • reference_video:參考視頻。提供主體角色(人物/動物/物體)和音色參考,不推薦傳入空鏡視頻。

  • first_frame:首幀映像。基於首幀產生視頻,通常包含主體角色(人物/動物/物體)。支援同時傳入首幀圖聯合控制,常見用法如下:

    • 首幀中已經出現待參考主體:此時可以搭配主體參考強化一致性,或進行音色參考。

    • 首幀中未出現待參考主體:此時可以用主體參考來定義視頻動態過程中新出現的主體特徵。

素材限制:

  • 首幀映像,最多傳入1張。

  • 參考映像和參考視頻至少傳入1個,參考映像 + 參考視頻 ≤ 5

  • 參考素材為主體角色時,僅包含單一角色。

url string (必選)

媒體素材URL。每個值可指向一張映像或一段視頻

傳入參考映像(type=reference_image)

參考映像URL或 Base 64 編碼資料。參考圖可以是主體(人物/動物/物體)或者背景。當包含主體時,僅包含一個角色。

映像限制:

  • 格式:JPEG、JPG、PNG(不支援透明通道)、BMP、WEBP。

  • 解析度:寬度和高度範圍為[240, 8000]像素。

  • 寬高比:1:8~8:1。

  • 檔案大小:不超過20MB。

支援輸入的格式:

  1. 公網URL:

    • 支援HTTP或HTTPS協議。

    • 樣本值:https://xxx/xxx.png。

  2. Base 64 編碼映像後的字串:

    • 資料格式:data:{MIME_type};base64,{base64_data}

    • 樣本值:data:image/png;base64,GDU7MtCZzEbTbmRZ......。(編碼字串過長,僅展示片段)

    • 詳情請參見傳入映像

傳入參考視頻(type=reference_video)

參考視頻URL。視頻內容建議包含主體(人物/動物/物體),不建議使用背景或空鏡視頻。當包含主體時,僅包含一個角色。若視頻有聲音,也可以參考音色。

視頻限制:

  • 格式:mp4、mov。

  • 時間長度:1~30s。

  • 解析度:寬度和高度範圍為[240,4096]像素。

  • 寬高比:1:8~8:1。

  • 檔案大小:不超過100MB。

支援輸入的格式:

  1. 公網URL:

    • 支援HTTP和HTTPS協議。

    • 樣本值:https://xxx/xxx.mp4。

reference_voice string (可選)

音頻 URL。用於指定參考素材(映像/視頻)中主體角色的音色。與reference_imagereference_video搭配使用。該音頻僅參考音色,與說話內容無關。建議參考音頻語種與提示詞語種保持一致,匹配效果更佳。

音頻生效邏輯:

  • 預設行為:若 reference_video 本身包含音頻,但未指定 reference_voice,預設使用視頻原聲。

  • 優先順序:若同時傳入 reference_video(含音頻)和 reference_voice,則優先使用 reference_voice 的音色,覆蓋視頻原聲。

音頻限制:

  • 格式:wav、mp3。

  • 時間長度:1~10s。

  • 檔案大小:不超過15MB。

支援輸入的格式:

  1. 公網URL:

    • 支援HTTP和HTTPS協議。

    • 樣本值:https://xxx/xxx.mp3。

parameters object (可選)

視頻處理參數,如設定視頻解析度。

屬性

resolution string (可選)

重要

resolution直接影響費用,請在調用前確認百鍊控制台

產生視頻的解析度檔位,用於控制視頻的清晰度(總像素)。

  • wan2.7-r2v、wan2.7-r2v-2026-06-12:可選值:720P、1080P。預設值為1080P

ratio string (可選)

產生視頻的寬高比。

生效邏輯:

  • 未傳入首幀映像:按指定的 ratio 參數產生視頻。

  • 已傳入首幀映像:自動忽略 ratio 參數,以首幀映像的寬高比產生近似比例的視頻。

可選值為:

  • 16:9(預設值)

  • 9:16

  • 1:1

  • 4:3

  • 3:4

不同寬高比對應的輸出視頻解析度(寬高像素值)見下方表格。

duration integer (可選)

重要

duration直接影響費用,請在調用前確認模型價格

產生視頻的時間長度,單位為秒。

  • wan2.7-r2v、wan2.7-r2v-2026-06-12:預設值為5。

    • 當參考素材中包含視頻時:取值為[2, 10]之間的整數。

    • 當參考素材中不包含視頻時:取值為[2, 15]之間的整數。

prompt_extend boolean (可選)

是否開啟prompt智能改寫。開啟後使用大模型對輸入prompt進行智能改寫。對於較短的prompt產生效果提升明顯,但會增加耗時。

  • true:預設值,開啟智能改寫。

  • false:不開啟智能改寫。

watermark boolean (可選)

是否添加浮水印標識,浮水印位於視頻右下角,文案固定為“AI產生”。

  • false:預設值,不添加浮水印。

  • true:添加浮水印。

seed integer (可選)

隨機數種子,取值範圍為[0, 2147483647]

未指定時,系統自動產生隨機種子。若需提升產生結果的可複現性,建議固定seed值。

請注意,由於模型產生具有機率性,即使使用相同 seed,也不能保證每次產生結果完全一致。

響應參數

成功響應

請儲存 task_id,用於查詢任務狀態與結果。

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

異常響應

建立任務失敗,請參見錯誤碼進行解決。

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

output object

任務輸出資訊。

屬性

task_id string

任務ID。查詢有效期間24小時。

task_status string

任務狀態。

枚舉值

  • PENDING:任務排隊中

  • RUNNING:任務處理中

  • SUCCEEDED:任務執行成功

  • FAILED:任務執行失敗

  • CANCELED:任務已取消

  • UNKNOWN:任務不存在或狀態未知

request_id string

請求唯一標識。可用於請求明細溯源和問題排查。

code string

請求失敗的錯誤碼。請求成功時不會返回此參數,詳情請參見錯誤碼

message string

請求失敗的詳細資料。請求成功時不會返回此參數,詳情請參見錯誤碼

步驟2:根據任務ID查詢結果

新加坡

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

北京

GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}

調用時請將{WorkspaceId}替換為真實的業務空間ID

說明
  • 輪詢建議:視頻產生過程約需數分鐘,建議採用輪詢機制,並設定合理的查詢間隔(如 15 秒)來擷取結果。

  • 任務狀態流轉:PENDING(排隊中)→ RUNNING(處理中)→ SUCCEEDED(成功)/ FAILED(失敗)。

  • 結果連結:任務成功後返回視頻連結,有效期間為 24 小時。建議在擷取連結後立即下載並轉存至永久儲存(如阿里雲 OSS)。

  • task_id 有效期間24小時,逾時後將無法查詢結果,介面將返回任務狀態為UNKNOWN

請求參數

查詢任務結果

{task_id}完整替換為上一步介面返回的task_id的值。task_id查詢有效期間為24小時。

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
要求標頭(Headers)

Authorization string(必選)

請求身份認證。介面使用阿里雲百鍊API Key進行身份認證。樣本值:Bearer sk-xxxx。

URL路徑參數(Path parameters)

task_id string(必選)

任務ID。

響應參數

任務執行成功

視頻URL僅保留24小時,逾時後會被自動清除,請及時儲存產生的視頻。

{
    "request_id": "52cade0d-905e-9b7d-a01e-xxxxxx",
    "output": {
        "task_id": "18814247-f944-4102-aa4a-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-04-02 22:53:19.537",
        "scheduled_time": "2026-04-02 22:53:30.427",
        "end_time": "2026-04-02 23:00:39.287",
        "orig_prompt": "視頻2抱著圖片3在咖啡廳裡彈奏一支舒緩的美式鄉村民謠,視頻1笑著看著視頻2,並緩緩向他走去",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?xxxx"
    },
    "usage": {
        "duration": 15,
        "input_video_duration": 5,
        "output_video_duration": 10,
        "video_count": 1,
        "SR": 720,
        "ratio": "16:9"
    }
}

任務執行失敗

若任務執行失敗,task_status將置為 FAILED,並提供錯誤碼和資訊。請參見錯誤碼進行解決。

{
    "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"
    }
}

任務查詢到期

task_id查詢有效期間為 24 小時,逾時後將無法查詢,返回以下報錯資訊。

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

output object

任務輸出資訊。

屬性

task_id string(必選)

任務ID。

task_status string

任務狀態。

枚舉值

  • PENDING:任務排隊中

  • RUNNING:任務處理中

  • SUCCEEDED:任務執行成功

  • FAILED:任務執行失敗

  • CANCELED:任務已取消

  • UNKNOWN:任務不存在或狀態未知

submit_time string

任務提交時間。時區為UTC+8,格式為 YYYY-MM-DD HH:mm:ss.SSS。

scheduled_time string

任務執行時間。時區為UTC+8,格式為 YYYY-MM-DD HH:mm:ss.SSS。

end_time string

任務完成時間。時區為UTC+8,格式為 YYYY-MM-DD HH:mm:ss.SSS。

video_url string

視頻URL。僅在 task_status 為 SUCCEEDED 時返回。

連結有效期間24小時,可通過此URL下載視頻。視頻格式為MP4(H.264 編碼)。

orig_prompt string

原始輸入的prompt,對應請求參數prompt

code string

請求失敗的錯誤碼。請求成功時不會返回此參數,詳情請參見錯誤碼

message string

請求失敗的詳細資料。請求成功時不會返回此參數,詳情請參見錯誤碼

usage object

輸出資訊統計。只對成功的結果計數。

屬性

input_video_duration integer

輸入視頻的時間長度,單位秒。

output_video_duration integer

輸出視頻的時間長度,單位秒。

duration integer

總視頻時間長度。計費按duration時間長度計算。

計算公式:duration = input_video_duration + output_video_duration

SR integer

產生視頻的解析度檔位。樣本值:720。

ratio string

產生視頻的寬高比。樣本值:16:9。

video_count integer

產生視頻的數量。固定為1。

request_id string

請求唯一標識。可用於請求明細溯源和問題排查。

DashScope SDK調用

SDK 的參數命名與HTTP介面基本一致,參數結構根據語言特性進行封裝。

參考生視頻任務通常需要1–5分鐘。SDK 封裝了HTTP非同步呼叫流程,支援同步和非同步兩種調用方式。

實際耗時取決於排隊任務數和服務運行狀態。

Python SDK調用

重要

運行以下代碼前,請確保 DashScope Python SDK版本 ≥1.25.16

版本過低可能會觸發 "url error, please check url!" 等錯誤。請參考安裝SDK進行更新。

根據模型所在地區設定 base_http_api_url:

新加坡

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

北京

dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'

調用時請將{WorkspaceId}替換為真實的業務空間ID

同步調用

同步調用會阻塞直到視頻產生完成,直接返回結果。

請求樣本
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 以下為新加坡地區URL,調用時請將{WorkspaceId}替換為真實的業務空間ID,各地區的URL不同。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_sync_call_r2v():
    # 同步調用,直接返回結果
    print('please wait...')
    rsp = VideoSynthesis.call(
        api_key=api_key,
        model='wan2.7-r2v-2026-06-12',
        prompt='視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 ',
        media=[
            {
                "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"
            }
        ],
        resolution='720P',
        ratio='16:9',
        duration=10,
        prompt_extend=False,
        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_r2v()
響應樣本
video_url 有效期間24小時,請及時下載視頻。
{
    "status_code": 200,
    "request_id": "b040d446-f9b6-977f-b9ad-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "5dab3291-393e-424d-929b-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "submit_time": "2026-04-17 17:12:49.076",
        "scheduled_time": "2026-04-17 17:13:00.384",
        "end_time": "2026-04-17 17:29:43.386",
        "orig_prompt": "視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 "
    },
    "usage": {
        "video_count": 1,
        "video_duration": 0,
        "video_ratio": "",
        "duration": 15,
        "input_video_duration": 5,
        "output_video_duration": 10,
        "SR": 720,
        "ratio": "16:9"
    }
}

非同步呼叫

非同步呼叫立即返回任務ID,需自行輪詢或等待任務完成。

請求樣本
import os
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope

# 以下為新加坡地區URL,調用時請將{WorkspaceId}替換為真實的業務空間ID,各地區的URL不同。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
# 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

def sample_async_call_r2v():
    # 非同步呼叫,返回一個task_id
    rsp = VideoSynthesis.async_call(
        api_key=api_key,
        model='wan2.7-r2v-2026-06-12',
        prompt='視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 ',
        media=[
            {
                "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"
            }
        ],
        resolution='720P',
        ratio='16:9',
        duration=10,
        prompt_extend=False,
        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))

    # 擷取非同步任務資訊
    status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

    # 等待非同步任務結束
    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_r2v()
響應樣本

1、建立任務的響應樣本

{
    "status_code": 200,
    "request_id": "6dc3bf6c-be18-9268-9c27-xxxxxx",
    "code": "",
    "message": "",
    "output": {
        "task_id": "686391d9-7ecf-4290-a8e9-xxxxxx",
        "task_status": "PENDING",
        "video_url": ""
    },
    "usage": null
}

2、查詢任務結果的響應樣本

video_url 有效期間24小時,請及時下載視頻。
{
    "status_code": 200,
    "request_id": "b040d446-f9b6-977f-b9ad-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "5dab3291-393e-424d-929b-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "submit_time": "2026-04-17 17:12:49.076",
        "scheduled_time": "2026-04-17 17:13:00.384",
        "end_time": "2026-04-17 17:29:43.386",
        "orig_prompt": "視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 "
    },
    "usage": {
        "video_count": 1,
        "video_duration": 0,
        "video_ratio": "",
        "duration": 15,
        "input_video_duration": 5,
        "output_video_duration": 10,
        "SR": 720,
        "ratio": "16:9"
    }
}

Java SDK調用

重要

運行以下代碼前,請確保 DashScope Java SDK版本 ≥2.22.14

版本過低可能會觸發 "url error, please check url!" 等錯誤。請參考安裝SDK進行更新。

根據模型所在地區設定 baseHttpApiUrl:

新加坡

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

北京

Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";

調用時請將{WorkspaceId}替換為真實的業務空間ID

同步調用

同步調用會阻塞直到視頻產生完成,直接返回結果。

請求樣本
// 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;

public class Ref2Video {

    static {
        // 以下為新加坡地區URL,調用時請將{WorkspaceId}替換為真實的業務空間ID,各地區的URL不同。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
    // 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void ref2video() 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/20260408/sjuytr/wan-r2v-object-girl.jpg")
                    .type("reference_image")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4")
                    .type("reference_video")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png")
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("ratio", "16:9");
        parameters.put("prompt_extend", false);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-r2v-2026-06-12")
                        .prompt("視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 ")
                        .media(media)
                        .duration(10)
                        .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 {
            ref2video();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
響應樣本
video_url 有效期間24小時,請及時下載視頻。
{
    "request_id": "f6365287-336f-9f2b-ab59-xxxxxx",
    "output": {
        "task_id": "cb7f1da5-a987-41de-b0a4-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
        "orig_prompt": "視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 ",
        "submit_time": "2026-04-17 17:15:11.536",
        "scheduled_time": "2026-04-17 17:15:20.316",
        "end_time": "2026-04-17 17:29:44.277"
    },
    "usage": {
        "video_count": 1,
        "duration": 15.0,
        "input_video_duration": 5.0,
        "output_video_duration": 10.0,
        "SR": "720"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

非同步呼叫

非同步呼叫立即返回任務ID,需自行輪詢或等待任務完成。

請求樣本
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
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.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;

public class Ref2VideoAsync {

    static {
        // 以下為新加坡地區URL,調用時請將{WorkspaceId}替換為真實的業務空間ID,各地區的URL不同。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey="sk-xxx"
    // 各地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/en/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void asyncRef2video() throws ApiException, NoApiKeyException, InputRequiredException, InterruptedException {
        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/20260408/sjuytr/wan-r2v-object-girl.jpg")
                    .type("reference_image")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4")
                    .type("reference_video")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png")
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("ratio", "16:9");
        parameters.put("prompt_extend", false);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-r2v-2026-06-12")
                        .prompt("視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 ")
                        .media(media)
                        .duration(10)
                        .parameters(parameters)
                        .build();
        // 提交非同步任務
        VideoSynthesisResult result = vs.asyncCall(param);
        System.out.println("task_id: " + result.getOutput().getTaskId());
        System.out.println(JsonUtils.toJson(result));

        // 等待任務完成
        result = vs.wait(result, null);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            asyncRef2video();
        } catch (ApiException | NoApiKeyException | InputRequiredException | InterruptedException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
響應樣本

1、建立任務的響應樣本

{
    "request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
    "output": {
        "task_id": "7277e20e-aa01-4709-xxxxxxxx",
        "task_status": "PENDING"
    }
}

2、查詢任務結果的響應樣本

video_url 有效期間24小時,請及時下載視頻。
{
    "request_id": "f6365287-336f-9f2b-ab59-xxxxxx",
    "output": {
        "task_id": "cb7f1da5-a987-41de-b0a4-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
        "orig_prompt": "視頻1抱著圖3,在圖4的椅子上彈奏一支舒緩的鄉村民謠,並說道:“今天的陽光真好。”圖1手中拿著圖2,路過視頻1,把手中的圖2放到視頻1旁邊的桌子上,並說道:“真好聽,能不能再唱一遍”。 ",
        "submit_time": "2026-04-17 17:15:11.536",
        "scheduled_time": "2026-04-17 17:15:20.316",
        "end_time": "2026-04-17 17:29:44.277"
    },
    "usage": {
        "video_count": 1,
        "duration": 15.0,
        "input_video_duration": 5.0,
        "output_video_duration": 10.0,
        "SR": "720"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

錯誤碼

如果模型調用失敗並返回報錯資訊,請參見錯誤碼進行解決。

常見問題

從 wan2.6 升級到 wan2.7,代碼需要改哪些地方?

主要區別如下:

  1. 提示詞的參考引用寫法不同

    wan2.7 不再使用 character1、character2 這類標識,需要改為按類型分別指代:映像用“圖n”(如圖1、圖2),視頻用“視頻n”(如視頻1、視頻2)。英文提示詞則寫為“Image 1”、"Video 1”這類標識。提示詞說明詳見prompt參數

  2. 多鏡頭控制方式不同

    • wan2.7:不支援 shot_type 參數,通過在 prompt 中描述分鏡指令碼來實現多鏡頭效果。

    • wan2.6:通過設定 shot_type 為 multi 來產生多鏡頭視頻。

  3. 請求參數結構不同

    • 參考素材傳入方式:wan2.7 使用 media(對象數組,每個元素含 type 和 url),替代 wan2.6 的 reference_urls(字串數組)。

    • 解析度參數:wan2.7 使用 resolution(如 720P),替代 wan2.6 的 size(如 1280*720)。

    • audio 參數:wan2.7 預設產生有聲視頻,無需設定。wan2.6 需要顯式設定 audio 為 true 或 false

如何為主體配音(音色參考)?

僅 wan2.7 支援。在 media 中通過 reference_voice 傳入音頻 URL,可為參考映像或參考視頻指定參考音色。

{
    "media": [
        {
            "type": "reference_image",
            "url": "<參考映像URL>",
            "reference_voice": "<音頻URL>"
        },
        {
            "type": "reference_video",
            "url": "<參考視頻URL>",
            "reference_voice": "<音頻URL>"
        }
    ]
}