全部產品
Search
文件中心

Alibaba Cloud Model Studio:萬相-映像產生與編輯2.7 API參考

更新時間:Apr 02, 2026

萬相2.7映像產生與編輯模型支援文生圖、文生組圖、圖生組圖、影像編輯、多圖參考產生,滿足多樣化產生與整合需求。

模型概覽

模型名稱

模型簡介

輸出映像規格

wan2.7-image-pro

萬相2.7 image專業版,支援4K高清輸出

圖片格式:PNG。

映像解析度和尺寸請參見size參數

wan2.7-image

萬相2.7 image,產生速度更快

說明

調用前,請查閱各地區支援的模型列表與價格

前提條件

您需要已擷取API Key配置API Key到環境變數(準備下線,併入配置 API Key)。請將範例程式碼中的 DASHSCOPE_API_HOST 替換為擷取的 API Host。

重要

北京和新加坡地區擁有獨立的 API Key 請求地址,不可混用,跨地區調用將導致鑒權失敗或服務報錯。

HTTP同步調用

一次請求即可獲得結果,流程簡單,推薦大多數情境使用。

新加坡

POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

北京

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

請求參數

文生圖

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"text": "一間有著精緻窗戶的花店,漂亮的木質門,擺放著花朵"}
                ]
            }
        ]
    },
    "parameters": {
        "size": "2K",
        "n": 1,
        "watermark": false,
        "thinking_mode": true
    }
}'

影像編輯

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
                    {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
                    {"text": "把圖2的塗鴉噴繪在圖1的汽車上"}
                ]
            }
        ]
    },
    "parameters": {
        "size": "2K",
        "n": 1,
        "watermark": false,
        "thinking_mode": true
    }
}'

互動式編輯

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"image": "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"},
                    {"image": "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"},
                    {"text": "把圖1的鬧鐘放在圖2的框選的位置,保持情境和光線融合自然"}
                ]
            }
        ]
    },
    "parameters": {
        "bbox_list": [[],[[989, 515, 1138, 681]]],
        "size": "2K",
        "n": 1,
        "watermark": false,
        "thinking_mode": true
    }
}'

組圖產生

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"text": "電影感組圖,記錄同一隻流浪橘貓,特徵必須前後一致。第一張:春天,橘貓穿梭在盛開的櫻花樹下;第二張:夏天,橘貓在老街的樹蔭下乘涼避暑;第三張:秋天,橘貓踩在滿地的金色落葉上;第四張:冬天,橘貓在雪地上走留下足跡。"}
                ]
            }
        ]
    },
    "parameters": {
        "enable_sequential": true,
        "n": 4,
        "size": "2K"
    }
}'

要求標頭(Headers)

Content-Type string (必選)

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

Authorization string(必選)

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

請求體(Request Body)

model string (必選)

模型名稱。可選值:wan2.7-image-prowan2.7-image

input object (必選)

輸入的基本資料。

屬性

messages array (必選)

請求內容數組。當前僅支援單輪對話,即傳入一組role、content參數,不支援多輪對話。

屬性

role string (必選)

訊息的角色。此參數固定設定為user

content array (必選)

訊息內容數組。

屬性

text string

使用者輸入提示詞。支援中英文,長度不超過5000個字元,每個漢字、字母、數字或符號計為一個字元,超過部分會自動截斷。

image string

輸入映像的URL或Base64編碼字串。

映像限制:

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

  • 映像解析度:映像的寬高範圍均為[240, 8000]像素,寬高比範圍[1:8, 8:1]。

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

映像數量限制:

  • 可傳入0-9張圖片。

  • 當輸入多張映像時,需在content數組中傳入多個image對象,並按照數組順序定義映像順序。

支援的輸入格式:

  1. 使用公網可訪問URL

    • 支援 HTTP 或 HTTPS 協議。

    • 樣本值:http://wanx.alicdn.com/material/xxx.jpeg

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

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

    • 樣本:data:image/jpeg;base64,GDU7MtCZzEbTbmRZ...(僅示意,實際需傳入完整字串)

    • Base 64 編碼規範請參見映像傳入方式

parameters object (可選)

模型參數配置。

屬性

bbox_list List[List[List[int]]] (可選)

互動式編輯框選地區。

  • 對應關係:列表長度必須與輸入圖片數量一致。若某張圖片無需編輯,請在對應位置傳入空列表 []

  • 座標格式:[x1, y1, x2, y2](左上方 x, 左上方 y, 右下角 x, 右下角 y),使用原圖絕對像素座標,左上方座標為(0,0)。

  • 限制條件:單張圖片最多支援 2 個邊界框。

樣本:輸入 3 張圖片,其中第 2 張無框選,第 1 張有兩個框選:

[
  [[0, 0, 12, 12], [25, 25, 100, 100]],  # 圖 1 (2個框)
  [],                                    # 圖 2 (無框)
  [[10, 10, 50, 50]]                    # 圖 3 (1個框)
]

enable_sequential boolean (可選)

控制生圖模式:

  • false:預設值。

  • true :啟用組圖輸出模式。

size string (可選)

關於輸出圖片解析度參數,支援以下兩種方式,不可混用:

模型:wan2.7-image-pro

  • 方式一:指定輸出圖片的解析度(推薦)

    • 支援 1K、2K(預設)、4K 三種規格

    • 適用範圍

      • 文生圖(無圖片輸入,非組圖產生):支援1K、2K、4K。

      • 其他情境:支援1K、2K。

    • 各規格總像素:1K:1024*1024、2K:2048*2048、4K:4096*4096

    • 映像比例

      • 當有圖片輸入時:輸出寬高比與輸入映像(多圖輸入時為最後一張)一致,並縮放到選定解析度。

      • 當沒有圖片輸入時:輸出為正方形。

  • 方式二:指定產生映像的寬高像素值

    • 文生圖:總像素在 [768*768, 4096*4096] 之間,寬高比範圍為 [1:8, 8:1]。

    • 其他情境:總像素在 [768*768, 2048*2048] 之間,寬高比範圍為 [1:8, 8:1]。

模型:wan2.7-image

  • 方式一:指定輸出圖片的解析度(推薦)

    • 支援1K、2K(預設)兩種規格,不支援4K。

  • 方式二:指定產生映像的寬高像素值

    • 所有情境下,總像素在 [768*768, 2048*2048] 之間,寬高比範圍為 [1:8, 8:1]。

輸出圖片的像素值可能和指定像素值存在微小差異。

n int (可選)

重要

n直接影響費用。費用 = 單價 × 成功產生的圖片張數,請在調用前確認模型價格

  • 關閉組圖模式時,該數值代表產生映像數量,取值範圍 1-4,預設為 4

  • 開啟組圖模式時,該數值代表最大產生映像數量,取值範圍 1-12,預設為 12。實際數量由模型決定且不超過 n。

thinking_mode boolean (可選)

是否開啟思考模式,預設為true(開啟)。僅在關閉組圖模式且無圖片輸入時生效。開啟時,模型將增強推理能力以提升出圖品質,但會增加產生耗時。

color_palette array (可選)

自訂色彩主題,一個包含顏色(hex)和佔比(ratio)的對象數組,需要包含 3 至 10 種顏色,推薦設定為 8 種。

僅當關閉組圖模式(enable_sequential=false)時可用。

屬性

hex string (必選)

十六進位(HEX)格式的色值。

ratio string (必選)

顏色所佔的百分比,需精確到小數點後兩位(如"25.00%")。所有 ratio 值相加總和必須為 100.00%

點擊查看輸入樣本

"color_palette": [
    {
        "hex": "#C2D1E6",
        "ratio": "23.51%"
    },
    {
        "hex": "#CDD8E9",
        "ratio": "20.13%"
    },
    {
        "hex": "#B5C8DB",
        "ratio": "15.88%"
    },
    {
        "hex": "#C0B5B4",
        "ratio": "13.27%"
    },
    {
        "hex": "#DAE0EC",
        "ratio": "10.11%"
    },
    {
        "hex": "#636574",
        "ratio": "8.93%"
    },
    {
        "hex": "#CACAD2",
        "ratio": "5.55%"
    },
    {
        "hex": "#CBD4E4",
        "ratio": "2.62%"
    }
]

watermark boolean (可選)

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

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

  • true:添加浮水印。

seed integer (可選)

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

使用相同的seed參數值可使產生內容保持相對穩定。若不提供,演算法將自動使用隨機數種子。

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

響應參數

任務執行成功

任務資料(如任務狀態、映像URL等)僅保留24小時,逾時後會被自動清除。請您務必及時儲存產生的映像。

{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "content": [
                        {
                            "image": "https://dashscope-xxx.oss-xxx.aliyuncs.com/xxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ],
                    "role": "assistant"
                }
            }
        ],
        "finished": true
    },
    "usage": {
        "image_count": 1,
        "input_tokens": 10867,
        "output_tokens": 2,
        "size": "1488*704",
        "total_tokens": 10869
    },
    "request_id": "71dfc3c6-f796-9972-97e4-bc4efc4faxxx"
}

任務執行異常

如果因為某種原因導致任務執行失敗,將返回相關資訊,可以通過code和message欄位明確指示錯誤原因。請參見錯誤資訊進行解決。

{
    "request_id": "a4d78a5f-655f-9639-8437-xxxxxx",
    "code": "InvalidParameter",
    "message": "num_images_per_prompt must be 1"
}

output object

任務輸出資訊。

屬性

choices array

模型產生的輸出內容。

屬性

finish_reason string

任務停止原因。自然停止時為stop

message object

模型返回的訊息。

屬性

role string

訊息的角色,固定為assistant

content array

屬性

type string

輸出的類型,固定為image。

image string

產生映像的 URL,映像格式為PNG。

連結有效期間為24小時,請及時下載並儲存映像。

finished boolean

任務是否結束。

  • true:已結束。

  • false:未結束。

usage object

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

屬性

image_count integer

產生映像的張數。

size string

產生的映像解析度。樣本值:1376*768。

input_tokens integer

輸入token數量(不計費)。按圖片張數計費。

output_tokens integer

輸出token數量(不計費)。按圖片張數計費。

total_tokens integer

總token數量(不計費)。按圖片張數計費。

request_id string

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

code string

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

message string

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

HTTP非同步呼叫

適用於耗時較長的任務,支援查詢任務狀態和結果。

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

新加坡

POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image-generation/generation

北京

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

請求參數

文生圖

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "X-DashScope-Async: enable" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"text": "一間有著精緻窗戶的花店,漂亮的木質門,擺放著花朵"}
                ]
            }
        ]
    },
    "parameters": {
        "size": "2K",
        "n": 1,
        "watermark": false,
        "thinking_mode": true
    }
}'

影像編輯

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "X-DashScope-Async: enable" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"},
                    {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"},
                    {"text": "把圖2的塗鴉噴繪在圖1的汽車上"}
                ]
            }
        ]
    },
    "parameters": {
        "size": "2K",
        "n": 1,
        "watermark": false,
        "thinking_mode": true
    }
}'

互動式編輯

curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "X-DashScope-Async: enable" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"image": "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"},
                    {"image": "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"},
                    {"text": "把圖1的鬧鐘放在圖2的框選的位置,保持情境和光線融合自然"}
                ]
            }
        ]
    },
    "parameters": {
        "bbox_list": [[],[[989, 515, 1138, 681]]],
        "size": "2K",
        "n": 1,
        "watermark": false,
        "thinking_mode": true
    }
}'

組圖產生

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "X-DashScope-Async: enable" \
--data '{
    "model": "wan2.7-image-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {"text": "電影感組圖,記錄同一隻流浪橘貓,特徵必須前後一致。第一張:春天,橘貓穿梭在盛開的櫻花樹下;第二張:夏天,橘貓在老街的樹蔭下乘涼避暑;第三張:秋天,橘貓踩在滿地的金色落葉上;第四張:冬天,橘貓在雪地上走留下足跡。"}
                ]
            }
        ]
    },
    "parameters": {
        "enable_sequential": true,
        "n": 4,
        "size": "2K"
    }
}'

要求標頭(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-image-prowan2.7-image

input object (必選)

輸入的基本資料。

屬性

messages array (必選)

請求內容數組。當前僅支援單輪對話,即傳入一組role、content參數,不支援多輪對話。

屬性

role string (必選)

訊息的角色。此參數固定設定為user

content array (必選)

訊息內容數組。

屬性

text string

使用者輸入提示詞。支援中英文,長度不超過5000個字元,每個漢字、字母、數字或符號計為一個字元,超過部分會自動截斷。

image string

輸入映像的URL或Base64編碼字串。

映像限制:

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

  • 映像解析度:映像的寬高範圍均為[240, 8000]像素,寬高比範圍[1:8, 8:1]。

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

映像數量限制:

  • 可傳入0-9張圖片。

  • 當輸入多張映像時,需在content數組中傳入多個image對象,並按照數組順序定義映像順序。

支援的輸入格式:

  1. 使用公網可訪問URL

    • 支援 HTTP 或 HTTPS 協議。

    • 樣本值:http://wanx.alicdn.com/material/xxx.jpeg

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

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

    • 樣本:data:image/jpeg;base64,GDU7MtCZzEbTbmRZ...(僅示意,實際需傳入完整字串)

    • Base 64 編碼規範請參見映像傳入方式

parameters object (可選)

模型參數配置。

屬性

bbox_list List[List[List[int]]] (可選)

互動式編輯框選地區。

  • 對應關係:列表長度必須與輸入圖片數量一致。若某張圖片無需編輯,請在對應位置傳入空列表 []

  • 座標格式:[x1, y1, x2, y2](左上方 x, 左上方 y, 右下角 x, 右下角 y),使用原圖絕對像素座標,左上方座標為(0,0)。

  • 限制條件:單張圖片最多支援 2 個邊界框。

樣本:輸入 3 張圖片,其中第 2 張無框選,第 1 張有兩個框選:

[
  [[0, 0, 12, 12], [25, 25, 100, 100]],  # 圖 1 (2個框)
  [],                                    # 圖 2 (無框)
  [[10, 10, 50, 50]]                    # 圖 3 (1個框)
]

enable_sequential boolean (可選)

控制生圖模式:

  • false:預設值。

  • true :啟用組圖輸出模式。

size string (可選)

關於輸出圖片解析度參數,支援以下兩種方式,不可混用:

模型:wan2.7-image-pro

  • 方式一:指定輸出圖片的解析度(推薦)

    • 支援 1K、2K(預設)、4K 三種規格

    • 適用範圍

      • 文生圖(無圖片輸入,非組圖產生):支援1K、2K、4K。

      • 其他情境:支援1K、2K。

    • 各規格總像素:1K:1024*1024、2K:2048*2048、4K:4096*4096

    • 映像比例

      • 當有圖片輸入時:輸出寬高比與輸入映像(多圖輸入時為最後一張)一致,並縮放到選定解析度。

      • 當沒有圖片輸入時:輸出為正方形。

  • 方式二:指定產生映像的寬高像素值

    • 文生圖:總像素在 [768*768, 4096*4096] 之間,寬高比範圍為 [1:8, 8:1]。

    • 其他情境:總像素在 [768*768, 2048*2048] 之間,寬高比範圍為 [1:8, 8:1]。

模型:wan2.7-image

  • 方式一:指定輸出圖片的解析度(推薦)

    • 支援1K、2K(預設)兩種規格,不支援4K。

  • 方式二:指定產生映像的寬高像素值

    • 所有情境下,總像素在 [768*768, 2048*2048] 之間,寬高比範圍為 [1:8, 8:1]。

輸出圖片的像素值可能和指定像素值存在微小差異。

n int (可選)

重要

n直接影響費用。費用 = 單價 × 成功產生的圖片張數,請在調用前確認模型價格

  • 關閉組圖模式時,該數值代表產生映像數量,取值範圍 1-4,預設為 4

  • 開啟組圖模式時,該數值代表最大產生映像數量,取值範圍 1-12,預設為 12。實際數量由模型決定且不超過 n。

thinking_mode boolean (可選)

是否開啟思考模式,預設為true(開啟)。僅在關閉組圖模式且無圖片輸入時生效。開啟時,模型將增強推理能力以提升出圖品質,但會增加產生耗時。

color_palette array (可選)

自訂色彩主題,一個包含顏色(hex)和佔比(ratio)的對象數組,需要包含 3 至 10 種顏色,推薦設定為 8 種。

僅當關閉組圖模式(enable_sequential=false)時可用。

屬性

hex string (必選)

十六進位(HEX)格式的色值。

ratio string (必選)

顏色所佔的百分比,需精確到小數點後兩位(如"25.00%")。所有 ratio 值相加總和必須為 100.00%

點擊查看輸入樣本

"color_palette": [
    {
        "hex": "#C2D1E6",
        "ratio": "23.51%"
    },
    {
        "hex": "#CDD8E9",
        "ratio": "20.13%"
    },
    {
        "hex": "#B5C8DB",
        "ratio": "15.88%"
    },
    {
        "hex": "#C0B5B4",
        "ratio": "13.27%"
    },
    {
        "hex": "#DAE0EC",
        "ratio": "10.11%"
    },
    {
        "hex": "#636574",
        "ratio": "8.93%"
    },
    {
        "hex": "#CACAD2",
        "ratio": "5.55%"
    },
    {
        "hex": "#CBD4E4",
        "ratio": "2.62%"
    }
]

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://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}

北京

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

請求參數

查詢任務結果

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

curl -X GET https://dashscope-intl.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": "810fa5f5-334c-91f3-aaa4-ed89cf0caxxx",
    "output": {
        "task_id": "a81ee7cb-014c-473d-b842-76e98311cxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-03-26 17:16:01.663",
        "scheduled_time": "2026-03-26 17:16:01.716",
        "end_time": "2026-03-26 17:16:22.961",
        "finished": true,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-xxx.oss-xxx.aliyuncs.com/xxx.png?Expires=xxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "size": "2976*1408",
        "total_tokens": 11017,
        "image_count": 1,
        "output_tokens": 2,
        "input_tokens": 11015
    }
}

任務執行異常

如果因為某種原因導致任務執行失敗,將返回相關資訊,可以通過code和message欄位明確指示錯誤原因。請參見錯誤資訊進行解決。

{
    "request_id": "a4d78a5f-655f-9639-8437-xxxxxx",
    "code": "InvalidParameter",
    "message": "num_images_per_prompt must be 1"
}

output object

任務輸出資訊。

屬性

task_id string

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

task_status string

任務狀態。

枚舉值

  • PENDING:任務排隊中

  • RUNNING:任務處理中

  • SUCCEEDED:任務執行成功

  • FAILED:任務執行失敗

  • CANCELED:任務已取消

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

輪詢過程中的狀態流轉:

  • PENDING(排隊中) → RUNNING(處理中)→ SUCCEEDED(成功)/ FAILED(失敗)。

  • 初次查詢狀態通常為 PENDING(排隊中)或 RUNNING(處理中)。

  • 當狀態變為 SUCCEEDED 時,響應中將包含產生的映像url。

  • 若狀態為 FAILED,請檢查錯誤資訊並重試。

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。

finished boolean

任務是否結束。

  • true:已結束。

  • false:未結束。

choices array

模型產生的輸出內容。

屬性

finish_reason string

任務停止原因,自然停止時為stop

message object

模型返回的訊息。

屬性

role string

訊息的角色,固定為assistant

content array

屬性

type string

輸出的類型,枚舉值為text、image。

text string

產生的文字。

image string

產生映像的 URL,映像格式為PNG。

連結有效期間為24小時,請及時下載並儲存映像。

usage object

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

屬性

image_count integer

產生映像的張數。

size string

產生的映像解析度。樣本值:1376*768。

input_tokens integer

輸入token數量(不計費)。按圖片張數計費。

output_tokens integer

輸出token數量(不計費)。按圖片張數計費。

total_tokens integer

總token數量(不計費)。按圖片張數計費。

request_id string

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

code string

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

message string

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

Python SDK調用

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

由於任務耗時較長,SDK 在底層封裝了 HTTP 非同步呼叫流程,支援同步、非同步兩種調用方式。

具體耗時受限於排隊任務數和服務執行情況,請在擷取結果時耐心等待。
重要

請確保 DashScope Python SDK 版本不低於 1.25.15,再運行以下代碼。更新請參考安裝SDK

各地區的base_url和 API Key 不通用,以下樣本以新加坡地區為例進行調用:

新加坡

https://dashscope-intl.aliyuncs.com/api/v1

北京

https://dashscope.aliyuncs.com/api/v1

影像編輯

同步調用

請求樣本
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message

# 以下為新加坡地區base_url,各地區的base_url不同
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

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

message = Message(
    role="user",
    # 支援本地檔案 如 "image": "file://car.png"
    content=[
        {
            "text": "把圖2的塗鴉噴繪在圖1的汽車上"
        },
        {
            "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"
        },
        {
            "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp"
        }
    ]
)
print("----sync call, please wait a moment----")
rsp = ImageGeneration.call(
        model='wan2.7-image-pro',
        api_key=api_key,
        messages=[message],
        watermark=False,
        n=1,
        size="2K"
    )

print(rsp)
響應樣本
url 有效期間24小時,請及時下載映像。
{
    "status_code": 200,
    "request_id": "81d868c6-6ce1-92d8-a90d-d2ee71xxxxxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "audio": null,
        "finished": true
    },
    "usage": {
        "input_tokens": 18790,
        "output_tokens": 2,
        "characters": 0,
        "image_count": 1,
        "size": "2985*1405",
        "total_tokens": 18792
    }
}

非同步呼叫

請求樣本
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message
from http import HTTPStatus

# 以下為新加坡地區base_url,各地區的base_url不同
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

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

# 建立非同步任務
def create_async_task():
    print("Creating async task...")
    message = Message(
        role="user",
        content=[
            {'text': '把圖2的塗鴉噴繪在圖1的汽車上'},
            {'image': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp'},
            {'image': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp'}
        ]
    )
    response = ImageGeneration.async_call(
        model="wan2.7-image-pro",
        api_key=api_key,
        messages=[message],
        watermark=False,
        n=1,
        size="2K"
    )
    
    if response.status_code == 200:
        print("Task created successfully:", response)
        return response  # 返回任務ID
    else:
        raise Exception(f"Failed to create task: {response.code} - {response.message}")

# 等待任務完成
def wait_for_completion(task_response):
    print("Waiting for task completion...")
    status = ImageGeneration.wait(task=task_response, api_key=api_key)
    
    if status.output.task_status == "SUCCEEDED":
        print("Task succeeded!")
        print("Response:", status)
    else:
        raise Exception(f"Task failed with status: {status.output.task_status}")

# 擷取非同步任務資訊
def fetch_task_status(task):
    print("Fetching task status...")
    status = ImageGeneration.fetch(task=task, api_key=api_key)
    
    if status.status_code == HTTPStatus.OK:
        print("Task status:", status.output.task_status)
        print("Response details:", status)
    else:
        print(f"Failed to fetch status: {status.code} - {status.message}")

# 取消非同步任務
def cancel_task(task):
    print("Canceling task...")
    response = ImageGeneration.cancel(task=task, api_key=api_key)
    
    if response.status_code == HTTPStatus.OK:
        print("Task canceled successfully:", response.output.task_status)
    else:
        print(f"Failed to cancel task: {response.code} - {response.message}")

# 主執行流程
if __name__ == "__main__":
    task = create_async_task()
    wait_for_completion(task)
響應樣本

1、建立任務的響應樣本

{
    "status_code": 200,
    "request_id": "4fb3050f-de57-4a24-84ff-e37ee5xxxxxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": null,
        "audio": null,
        "task_id": "127ec645-118f-4884-955d-0eba8dxxxxxx",
        "task_status": "PENDING"
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "characters": 0
    }
}

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

url 有效期間24小時,請及時下載映像。
{
    "status_code": 200,
    "request_id": "3b99aae5-d26f-9059-8dd0-ee9ca4804xxx",
    "code": null,
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "audio": null,
        "task_id": "127ec645-118f-4884-955d-0eba8dxxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-03-31 22:58:47.646",
        "scheduled_time": "2026-03-31 22:58:47.683",
        "end_time": "2026-03-31 22:58:59.642",
        "finished": true
    },
    "usage": {
        "input_tokens": 18711,
        "output_tokens": 2,
        "characters": 0,
        "size": "2985*1405",
        "total_tokens": 18713,
        "image_count": 1
    }
}

組圖產生

同步調用

請求樣本
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message

# 以下為新加坡地區base_url,各地區的base_url不同
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

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

message = Message(
    role="user",
    content=[
        {
            "text": "電影感組圖,記錄同一隻流浪橘貓,特徵必須前後一致。第一張:春天,橘貓穿梭在盛開的櫻花樹下;第二張:夏天,橘貓在老街的樹蔭下乘涼避暑;第三張:秋天,橘貓踩在滿地的金色落葉上;第四張:冬天,橘貓在雪地上走留下足跡。"
        }
    ]
)

print("----sync call, please wait a moment----")
rsp = ImageGeneration.call(
        model='wan2.7-image-pro',
        api_key=api_key,
        messages=[message],
        enable_sequential=True,
        n=4,
        size="2K"
    )

print(rsp)
響應樣本
url 有效期間24小時,請及時下載映像。
{
    "status_code": 200,
    "request_id": "56e318fd-ed60-99e8-8ca1-cdef25ca4xxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "audio": null,
        "finished": true
    },
    "usage": {
        "input_tokens": 720,
        "output_tokens": 11,
        "characters": 0,
        "image_count": 4,
        "size": "2048*2048",
        "total_tokens": 731
    }
}

非同步呼叫

請求樣本
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message

# 以下為新加坡地區base_url,各地區的base_url不同
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

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


def main():
    message = Message(
        role="user",
        content=[
            {"text": "電影感組圖,記錄同一隻流浪橘貓,特徵必須前後一致。第一張:春天,橘貓穿梭在盛開的櫻花樹下;第二張:夏天,橘貓在老街的樹蔭下乘涼避暑;第三張:秋天,橘貓踩在滿地的金色落葉上;第四張:冬天,橘貓在雪地上走留下足跡。"}
        ]
    )
    
    # 提交非同步任務
    print("提交非同步任務...")
    response = ImageGeneration.async_call(
        model="wan2.7-image-pro",
        api_key=api_key,
        messages=[message],
        enable_sequential=True,
        n=4,
        size="2K"
    )
    
    if response.status_code == 200:
        print(f"任務提交成功,任務ID: {response.output.task_id}")
        
        # 等待任務完成
        status = ImageGeneration.wait(task=response, api_key=api_key)
        
        if status.output.task_status == "SUCCEEDED":
            print("任務完成!")
            print(f"結果:")
            print(status)
        else:
            print(f"任務失敗,狀態: {status.output.task_status}")
    else:
        print(f"任務建立失敗: {response.code} - {response.message}")


if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        print(f"錯誤: {e}")
響應樣本

1、建立任務的響應樣本

{
    "status_code": 200,
    "request_id": "4fb3050f-de57-4a24-84ff-e37ee5xxxxxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": null,
        "audio": null,
        "task_id": "77093787-a217-4c29-9cd4-ca7b5ac86xxx",
        "task_status": "PENDING"
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "characters": 0
    }
}

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

url 有效期間24小時,請及時下載映像。
{
    "status_code": 200,
    "request_id": "56e318fd-ed60-99e8-8ca1-cdef25ca4xxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "audio": null,
        "task_id": "77093787-a217-4c29-9cd4-ca7b5ac86xxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-03-31 23:04:46.166",
        "scheduled_time": "2026-03-31 23:04:46.208",
        "end_time": "2026-03-31 23:05:11.664",
        "finished": true
    },
    "usage": {
        "input_tokens": 720,
        "output_tokens": 11,
        "characters": 0,
        "size": "2048*2048",
        "total_tokens": 731,
        "image_count": 4
    }
}

Java SDK調用

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

由於任務耗時較長,SDK 在底層封裝了 HTTP 非同步呼叫流程,支援同步、非同步兩種調用方式。

重要

請確保 DashScope Java SDK 版本不低於 2.22.13,否則可能不支援本文所用的部分參數。

新加坡

https://dashscope-intl.aliyuncs.com/api/v1

北京

https://dashscope.aliyuncs.com/api/v1

影像編輯

同步調用

請求樣本
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.Arrays;
import java.util.Collections;

/**
 * wan2.7-image-pro 影像編輯 - 同步調用樣本
 */
public class Main {

    static {
        // 以下為新加坡地區url,各地區的base_url不同
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }

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

    public static void basicCall() throws ApiException, NoApiKeyException, UploadFileException {
        // 構建多圖輸入訊息
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Arrays.asList(
                        // 支援多圖輸入,可以提供多張參考圖片
                        Collections.singletonMap("text", "把圖2的塗鴉噴繪在圖1的汽車上"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp")
                )).build();

        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.7-image-pro")
                .messages(Collections.singletonList(message))
                .n(1)
                .size("2K")
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        ImageGenerationResult result = null;
        try {
            System.out.println("---sync call for image editing, please wait a moment----");
            result = imageGeneration.call(param);
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e.getMessage());
        }
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            basicCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
    }
}
響應樣本
url 有效期間24小時,請及時儲存。
{
    "requestId": "1bf6173a-e8de-9f75-94d3-5e618f875xxx",
    "usage": {
        "input_tokens": 18790,
        "output_tokens": 2,
        "total_tokens": 18792,
        "image_count": 1,
        "size": "2985*1405"
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "finished": true
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

非同步呼叫

請求樣本
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.Arrays;
import java.util.Collections;

/**
 * wan2.7-image-pro 影像編輯 - 非同步呼叫樣本
 */
public class Main {

    static {
        // 以下為新加坡地區url,各地區的base_url不同
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }

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

    public static void asyncCall() throws ApiException, NoApiKeyException, UploadFileException {
        // 構建多圖輸入訊息
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Arrays.asList(
                        // 支援多圖輸入,可以提供多張參考圖片
                        Collections.singletonMap("text", "把圖2的塗鴉噴繪在圖1的汽車上"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/pjeqdf/car.webp"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251229/xsunlm/paint.webp")
                )).build();

        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.7-image-pro")
                .n(1)
                .size("2K")
                .messages(Arrays.asList(message))
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        ImageGenerationResult result = null;
        try {
            System.out.println("---async call for image editing, creating task----");
            result = imageGeneration.asyncCall(param);
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e.getMessage());
        }
        System.out.println("任務建立結果:");
        System.out.println(JsonUtils.toJson(result));

        String taskId = result.getOutput().getTaskId();
        // 等待任務完成
        waitTask(taskId);
    }

    public static void waitTask(String taskId) throws ApiException, NoApiKeyException {
        ImageGeneration imageGeneration = new ImageGeneration();
        System.out.println("\n---waiting for task completion----");
        ImageGenerationResult result = imageGeneration.wait(taskId, apiKey);
        System.out.println("任務完成結果:");
        System.out.println(JsonUtils.toJson(result));
    }

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

1、建立任務的響應樣本

{
    "requestId": "ccf4b2f4-bf30-9e13-9461-3a28c6a7bxxx",
    "output": {
        "task_id": "8811b4a4-00ac-4aa2-a2fd-017d3b90cxxx",
        "task_status": "PENDING"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

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

url 有效期間24小時,請及時儲存。
{
    "requestId": "60a08540-f1c1-9e76-8cd3-d5949db8cxxx",
    "usage": {
        "input_tokens": 18711,
        "output_tokens": 2,
        "total_tokens": 18713,
        "image_count": 1,
        "size": "2985*1405"
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "task_id": "8811b4a4-00ac-4aa2-a2fd-017d3b90cxxx",
        "task_status": "SUCCEEDED",
        "finished": true,
        "submit_time": "2026-03-31 19:57:58.840",
        "scheduled_time": "2026-03-31 19:57:58.877",
        "end_time": "2026-03-31 19:58:11.563"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

組圖產生

同步調用

請求樣本
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.Collections;

/**
 * wan2.7-image-pro 組圖產生 - 同步調用樣本(新加坡地區)
 */
public class Main {

    static {
        // 以下為新加坡地區url,各地區的base_url不同
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }

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

    public static void basicCall() throws ApiException, NoApiKeyException, UploadFileException {
        // 構建文本輸入訊息(支援文生組圖以及圖生組圖,此處以文生組圖為例)
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Collections.singletonList(
                        Collections.singletonMap("text", "電影感組圖,記錄同一隻流浪橘貓,特徵必須前後一致。第一張:春天,橘貓穿梭在盛開的櫻花樹下;第二張:夏天,橘貓在老街的樹蔭下乘涼避暑;第三張:秋天,橘貓踩在滿地的金色落葉上;第四張:冬天,橘貓在雪地上走留下足跡。")
                )).build();

        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.7-image-pro")
                .messages(Collections.singletonList(message))
                .enableSequential(true)
                .n(4)
                .size("2K")
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        ImageGenerationResult result = null;
        try {
            System.out.println("----sync call, please wait a moment----");
            result = imageGeneration.call(param);
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e.getMessage());
        }
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            basicCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
    }
}
響應樣本
url 有效期間24小時,請及時儲存。
{
    "requestId": "4678c314-b37a-91c9-a2ae-2d3cd54bbxxx",
    "usage": {
        "input_tokens": 720,
        "output_tokens": 11,
        "total_tokens": 731,
        "image_count": 4,
        "size": "2048*2048"
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "finished": true
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

非同步呼叫

請求樣本
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.Collections;

/**
 * wan2.7-image-pro 組圖產生 - 非同步呼叫樣本(新加坡地區)
 */
public class Main {

    static {
        // 以下為新加坡地區url,各地區的base_url不同
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }

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

    public static ImageGenerationResult waitTask(String taskId)
            throws ApiException, NoApiKeyException {
        ImageGeneration imageGeneration = new ImageGeneration();
        return imageGeneration.wait(taskId, apiKey);
    }

    public static void asyncCall() throws ApiException, NoApiKeyException, UploadFileException {
        // 構建文本輸入訊息(支援文生組圖以及圖生組圖,此處以文生組圖為例)
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Collections.singletonList(
                        Collections.singletonMap("text", "電影感組圖,記錄同一隻流浪橘貓,特徵必須前後一致。第一張:春天,橘貓穿梭在盛開的櫻花樹下;第二張:夏天,橘貓在老街的樹蔭下乘涼避暑;第三張:秋天,橘貓踩在滿地的金色落葉上;第四張:冬天,橘貓在雪地上走留下足跡。")
                )).build();

        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.7-image-pro")
                .messages(Collections.singletonList(message))
                .enableSequential(true)
                .n(4)
                .size("2K")
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        ImageGenerationResult taskResult = null;
        try {
            System.out.println("----async call, creating task----");
            taskResult = imageGeneration.asyncCall(param);
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e.getMessage());
        }
        System.out.println("Task created: " + JsonUtils.toJson(taskResult));

        // 等待任務完成
        String taskId = taskResult.getOutput().getTaskId();
        ImageGenerationResult result = waitTask(taskId);
        System.out.println(JsonUtils.toJson(result));
    }

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

1、建立任務的響應樣本

{
    "requestId": "7d026dc1-e8c9-9caa-84ac-e82e2da97xxx",
    "output": {
        "task_id": "2de18c56-c151-4b80-8105-1d164733exxx",
        "task_status": "PENDING"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

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

url 有效期間24小時,請及時儲存。
{
    "requestId": "daea7295-4ce0-928a-9a11-4d2bea058xxx",
    "usage": {
        "input_tokens": 720,
        "output_tokens": 11,
        "total_tokens": 731,
        "image_count": 4,
        "size": "2048*2048"
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        },
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "task_id": "2de18c56-c151-4b80-8105-1d164733exxx",
        "task_status": "SUCCEEDED",
        "finished": true,
        "submit_time": "2026-03-31 19:49:53.124",
        "scheduled_time": "2026-03-31 19:49:53.175",
        "end_time": "2026-03-31 19:50:53.160"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

計費與限流

  • 模型免費額度和計費單價請參見模型價格

  • 模型限流請參見萬相

  • 計費說明:按成功產生的 映像張數 計費。模型調用失敗或處理錯誤不產生任何費用,也不消耗新人免費額度

錯誤碼

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