全部產品
Search
文件中心

Alibaba Cloud Model Studio:通義千問-影像編輯API參考

更新時間:Dec 03, 2025

通義千問-影像編輯模型(qwen-image-edit-plus)支援多圖輸入和多圖輸出,可精確修改圖內文字、增刪或移動物體、改變主體動作、遷移圖片風格及增強畫面細節。

效果展示

多圖融合

image99

image98

image89

image100

imageout2

輸入圖1

輸入圖2

輸入圖3

圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下

image83

image103

1

2

imageout2

輸入圖1

輸入圖2

輸入圖3

圖1中的女生戴著圖2中的項鏈,左肩挎著圖3中的包

單圖編輯

image36

image38

image

image

原圖

產生一張符合深度圖的映像,遵循以下描述:一輛紅色的破舊的單車停在一條泥濘的小路上,背景是茂密的原始森林

原圖

將字母塊上的單詞“HEALTH INSURANCE”替換為“明天會更好”

5

5out

6

6out

原圖

用淺藍色襯衫替換圓點襯衫

原圖

將圖中背景改為南極

HTTP調用

在調用前,您需要擷取與配置 API Key,再配置API Key到環境變數(準備下線,併入配置 API Key)

如需通過SDK進行調用,請安裝DashScope SDK。目前,該SDK已支援Python和Java。

重要

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

新加坡地區: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

請求參數

單圖編輯

此處以使用qwen-image-edit-plus模型輸出2張圖片為例。

以下為新加坡地區 URL ,若使用北京地區的模型,需將 URL 替換為: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": "qwen-image-edit-plus",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/fpakfo/image36.webp"
                    },
                    {
                        "text": "產生一張符合深度圖的映像,遵循以下描述:一輛紅色的破舊的單車停在一條泥濘的小路上,背景是茂密的原始森林"
                    }
                ]
            }
        ]
    },
    "parameters": {
        "n": 2,
        "negative_prompt": " ",
        "prompt_extend": true,
        "watermark": false
    }
}'

多圖融合

此處以使用qwen-image-edit-plus模型輸出2張圖片為例。

以下為新加坡地區 URL ,若使用北京地區的模型,需將 URL 替換為: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": "qwen-image-edit-plus",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"
                    },
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/iclsnx/input2.png"
                    },
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/gborgw/input3.png"
                    },
                    {
                        "text": "圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下"
                    }
                ]
            }
        ]
    },
    "parameters": {
        "n": 2,
        "negative_prompt": " ",
        "prompt_extend": true,
        "watermark": false
    }
}'
要求標頭(Headers)

Content-Type string (必選)

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

Authorization string(必選)

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

請求體(Request Body)

model string (必選)

模型名稱,可選以下模型:

qwen-image-edit-plusqwen-image-edit-plus-2025-10-30:支援輸出1-6張圖片。

qwen-image-edit:僅支援輸出1張圖片。

input object (必選)

輸入參數對象,包含以下欄位:

屬性

messages array (必選)

請求內容數組。當前僅支援單輪對話,因此數組內有且只有一個對象,該對象包含rolecontent兩個屬性。

屬性

role string (必選)

訊息寄件者角色,必須設定為user

content array (必選)

訊息內容,包含1-3張映像,格式為 {"image": "..."};以及單個編輯指令,格式為 {"text": "..."}

屬性

image string (必選)

輸入映像的 URL 或 Base 64 編碼資料。支援傳入1-3張映像。當傳入多張映像時,輸出映像的比例以最後一張為準。

映像要求:

  • 映像格式:JPG、JPEG、PNG、BMP、TIFF、WEBP。

  • 映像解析度:映像的寬度和高度均需在384-3072像素範圍內。

  • 映像大小:不超過10MB。

  • URL地址若包含中文等非ASCII字元,需進行URL編碼後再傳入。

    URL編碼

    from urllib.parse import quote
    
    # 請替換下面的URL為需要編碼的URL
    url = "https://example.com/搜尋?q=測試&page=1"
    encoded_url = quote(url, safe=':/?#[]@!$&\'()*+,;=%')
    print(f"原始URL: {url}")
    print(f"編碼後的URL: {encoded_url}")

傳入方式1:公網URL:公網可訪問的HTTP或HTTPS映像地址。

  • 樣本值:https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/fpakfo/image36.webp

傳入方式2:Base64編碼:字串需遵循data:{mime_type};base64,{base64_data}格式。

  • {mime_type}:映像的媒體類型,需與檔案格式對應。

  • {base64_data}:檔案經過 Base 64 編碼後的字串。

  • 映像格式與{mime_type}類型對應關係:

    • JPEG/JPG:image/jpeg

    • PNG:image/png

    • BMP:image/bmp

    • TIFF:image/tiff

    • WEBP:image/webp

  • 點擊查看圖片Base64編碼程式碼範例

    import os
    import base64
    import mimetypes
    
    # 格式為 data:{mime_type};base64,{base64_data}
    def encode_file(file_path):
        mime_type, _ = mimetypes.guess_type(file_path)
        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}"
            
            
    # 調用編碼函數,請將 "/path/to/your/image.png" 替換為您的本地圖片檔案路徑,否則無法運行
    image = encode_file("/path/to/your/image.png")
  • 樣本值:data:image/jpeg;base64,GDU7MtCZz...(樣本已截斷,僅做示範)

完整範例程式碼請參見Python SDK調用Java SDK調用

text string (必選)

影像編輯指令,即正向提示詞,用來描述產生映像中期望包含的元素和視覺特點。

進行多影像編輯時,編輯指令中需要使用“圖1”、“圖2”、“圖3”等描述來指代相應的圖片,否則會出現不符合預期的編輯結果。

支援中英文,長度上限800個字元,每個漢字/字母佔一個字元,超過部分會自動截斷。

樣本值:圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下,保持其服裝、髮型和表情不變,動作自然流暢。

parameters object (可選)

控製圖像產生的附加參數。

屬性

n integer (可選)

輸出映像的數量,預設值為1。

對於qwen-image-edit-plusqwen-image-edit-plus-2025-10-30,可選擇輸出1-6張圖片。

對於qwen-image-edit,僅支援輸出1張圖片。

negative_prompt string (可選)

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

支援中英文,長度上限500個字元,每個漢字/字母佔一個字元,超過部分會自動截斷。

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

size string (可選)

設定輸出映像的解析度,格式為寬*高,例如"1024*2048"。寬和高的取值範圍均為[512, 2048]像素。

預設行為:若不設定,輸出映像將保持與原圖相似的長寬比接近1024*1024解析度。

使用限制:該參數僅在輸出映像數量 n 為 1 時可用,否則將報錯。

支援模型:僅qwen-image-edit-plusqwen-image-edit-plus-2025-10-30模型支援。

prompt_extend bool (可選)

是否開啟prompt智能改寫。開啟後,將使用大模型最佳化正向提示詞,對描述性不足、較為簡單的prompt提升效果較明顯。

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

  • false:不開啟智能改寫。

支援模型:僅qwen-image-edit-plusqwen-image-edit-plus-2025-10-30模型支援。

watermark bool (可選)

是否在映像右下角添加 "Qwen-Image" 浮水印。預設值為 false。浮水印樣式如下:

1

seed integer (可選)

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

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

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

響應參數

任務執行成功

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

{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        },
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "width": 1248,
        "image_count": 2,
        "height": 832
    },
    "request_id": "bf37ca26-0abe-98e4-8065-xxxxxx"
}

任務執行異常

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

{
    "request_id": "31f808fd-8eef-9004-xxxxx",
    "code": "InvalidApiKey",
    "message": "Invalid API-key provided."
}

output object

包含模型產生結果。

屬性

choices array

結果選項列表。

屬性

finish_reason string

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

message object

模型返回的訊息。

屬性

role string

訊息的角色,固定為assistant

content array

訊息內容,包含產生的映像資訊。

屬性

image string

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

映像格式為PNG,與原圖的長寬比保持一致,接近1024*1024解析度。

usage object

本次調用的資源使用方式,僅調用成功時返回。

屬性

image_count integer

產生的映像數量,等於選擇輸出圖片的數量。

width integer

產生映像的寬度(像素)。

height integer

產生映像的高度(像素)。

request_id string

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

code string

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

message string

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

DashScope SDK調用

SDK 的參數命名與HTTP介面基本一致,參數結構根據語言特性進行封裝,完整參數列表請參見通義千問 API 參考

Python SDK調用

說明
  • 推薦安裝最新版DashScope Python SDK,否則可能運行報錯:安裝或升級SDK

  • 不支援非同步介面。

請求樣本

此處以使用qwen-image-edit-plus模型輸出2張圖片為例。

通過公網URL傳入圖片

import json
import os
import dashscope
from dashscope import MultiModalConversation

# 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# 模型支援輸入1-3張圖片
messages = [
    {
        "role": "user",
        "content": [
            {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"},
            {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/iclsnx/input2.png"},
            {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/gborgw/input3.png"},
            {"text": "圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下"}
        ]
    }
]

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

# qwen-image-edit-plus支援輸出1-6張圖片,此處以2張為例
response = MultiModalConversation.call(
    api_key=api_key,
    model="qwen-image-edit-plus",
    messages=messages,
    stream=False,
    n=2,
    watermark=False,
    negative_prompt=" ",
    prompt_extend=True,
    # 僅當輸出映像數量n=1時支援設定size參數,否則會報錯
    # size="1024*2048",
)

if response.status_code == 200:
    # 如需查看完整響應,請取消下行注釋
    # print(json.dumps(response, ensure_ascii=False))
    for i, content in enumerate(response.output.choices[0].message.content):
        print(f"輸出映像{i+1}的URL:{content['image']}")
else:
    print(f"HTTP返回碼:{response.status_code}")
    print(f"錯誤碼:{response.code}")
    print(f"錯誤資訊:{response.message}")
    print("請參考文檔:https://www.alibabacloud.com/help/zh/model-studio/error-code")

通過Base64編碼傳入圖片

import json
import os
import dashscope
from dashscope import MultiModalConversation
import base64
import mimetypes

# 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'


# ---用於 Base 64 編碼 ---
# 格式為 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("不支援或無法識別的映像格式")

    try:
        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}"
    except IOError as e:
        raise IOError(f"讀取檔案時出錯: {file_path}, 錯誤: {str(e)}")


# 擷取映像的 Base 64 編碼
# 調用編碼函數,請將 "/path/to/your/image.png" 替換為您的本地圖片檔案路徑,否則無法運行
image = encode_file("/path/to/your/image.png")

messages = [
    {
        "role": "user",
        "content": [
            {"image": image},
            {"text": "產生一張符合深度圖的映像,遵循以下描述:一輛紅色的破舊的單車停在一條泥濘的小路上,背景是茂密的原始森林"}
        ]
    }
]

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

# qwen-image-edit-plus支援輸出1-6張圖片,此處以2張為例
response = MultiModalConversation.call(
    api_key=api_key,
    model="qwen-image-edit-plus",
    messages=messages,
    stream=False,
    n=2,
    watermark=False,
    negative_prompt=" ",
    prompt_extend=True,
    # 僅當輸出映像數量n=1時支援設定size參數,否則會報錯
    # size="2048*1024",
)

if response.status_code == 200:
    # 如需查看完整響應,請取消下行注釋
    # print(json.dumps(response, ensure_ascii=False))
    for i, content in enumerate(response.output.choices[0].message.content):
        print(f"輸出映像{i+1}的URL:{content['image']}")
else:
    print(f"HTTP返回碼:{response.status_code}")
    print(f"錯誤碼:{response.code}")
    print(f"錯誤資訊:{response.message}")
    print("請參考文檔:https://www.alibabacloud.com/help/zh/model-studio/error-code")

通過URL下載映像

# 需要安裝requests以下載映像: pip install requests
import requests


def download_image(image_url, save_path='output.png'):
    try:
        response = requests.get(image_url, stream=True, timeout=300)  # 設定逾時
        response.raise_for_status()  # 如果HTTP狀態代碼不是200,則引發異常
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print(f"映像已成功下載到: {save_path}")

    except requests.exceptions.RequestException as e:
        print(f"映像下載失敗: {e}")


image_url = "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
download_image(image_url, save_path='output.png')

響應樣本

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

input_tokensoutput_tokens為相容欄位,當前固定為0。
{
    "status_code": 200,
    "request_id": "121d8c7c-360b-4d22-a976-6dbb8bxxxxxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        },
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "height": 1248,
        "image_count": 2,
        "width": 832
    }
}

Java SDK調用

說明

推薦安裝最新版DashScope Java SDK,否則可能運行報錯:安裝或升級SDK

請求樣本

此處以使用qwen-image-edit-plus模型輸出2張圖片為例。

通過公網URL傳入圖片

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

public class QwenImageEdit {

    static {
        // 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }
    
    // 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    // 若沒有配置環境變數,請用百鍊 API Key 將下行替換為:apiKey="sk-xxx"
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void call() throws ApiException, NoApiKeyException, UploadFileException, IOException {

        MultiModalConversation conv = new MultiModalConversation();

        // 模型支援輸入1-3張圖片
        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
                .content(Arrays.asList(
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/iclsnx/input2.png"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/gborgw/input3.png"),
                        Collections.singletonMap("text", "圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下")
                )).build();
        // qwen-image-edit-plus支援輸出1-6張圖片,此處以2張為例
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("watermark", false);
        parameters.put("negative_prompt", " ");
        parameters.put("n", 2);
        parameters.put("prompt_extend", true);
        // 僅當輸出映像數量n=1時支援設定size參數,否則會報錯
        // parameters.put("size", "1024*2048");

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(apiKey)
                .model("qwen-image-edit-plus")
                .messages(Collections.singletonList(userMessage))
                .parameters(parameters)
                .build();

        MultiModalConversationResult result = conv.call(param);
        // 如需查看完整響應,請取消下行注釋
        // System.out.println(JsonUtils.toJson(result));
        List<Map<String, Object>> contentList = result.getOutput().getChoices().get(0).getMessage().getContent();
        int imageIndex = 1;
        for (Map<String, Object> content : contentList) {
            if (content.containsKey("image")) {
                System.out.println("輸出映像" + imageIndex + "的URL:" + content.get("image"));
                imageIndex++;
            }
        }
    }

    public static void main(String[] args) {
        try {
            call();
        } catch (ApiException | NoApiKeyException | UploadFileException | IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

通過Base64編碼傳入圖片

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

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

public class QwenImageEdit {

    static {
        // 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }
    
    // 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    // 若沒有配置環境變數,請用百鍊 API Key 將下行替換為:apiKey="sk-xxx"
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void call() throws ApiException, NoApiKeyException, UploadFileException, IOException {

        // 請將 "/path/to/your/image.png" 替換為您的本地圖片檔案路徑,否則無法運行
        String image = encodeFile("/path/to/your/image.png");

        MultiModalConversation conv = new MultiModalConversation();

        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
                .content(Arrays.asList(
                        Collections.singletonMap("image", image),
                        Collections.singletonMap("text", "產生一張符合深度圖的映像,遵循以下描述:一輛紅色的破舊的單車停在一條泥濘的小路上,背景是茂密的原始森林")
                )).build();
        // qwen-image-edit-plus支援輸出1-6張圖片,此處以2張為例
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("watermark", false);
        parameters.put("negative_prompt", " ");
        parameters.put("n", 2);
        parameters.put("prompt_extend", true);
        // 僅當輸出映像數量n=1時支援設定size參數,否則會報錯
        // parameters.put("size", "2048*1024");

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(apiKey)
                .model("qwen-image-edit-plus")
                .messages(Collections.singletonList(userMessage))
                .parameters(parameters)
                .build();

        MultiModalConversationResult result = conv.call(param);
        // 如需查看完整響應,請取消下行注釋
        // System.out.println(JsonUtils.toJson(result));
        List<Map<String, Object>> contentList = result.getOutput().getChoices().get(0).getMessage().getContent();
        int imageIndex = 1;
        for (Map<String, Object> content : contentList) {
            if (content.containsKey("image")) {
                System.out.println("輸出映像" + imageIndex + "的URL:" + content.get("image"));
                imageIndex++;
            }
        }
    }

    /**
     * 將檔案編碼為Base64字串
     * @param filePath 檔案路徑
     * @return Base64字串,格式為 data:{mime_type};base64,{base64_data}
     */
    public static String encodeFile(String filePath) {
        Path path = Paths.get(filePath);
        if (!Files.exists(path)) {
            throw new IllegalArgumentException("檔案不存在: " + filePath);
        }
        // 檢測MIME類型
        String mimeType = null;
        try {
            mimeType = Files.probeContentType(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("無法檢測檔案類型: " + filePath);
        }
        if (mimeType == null || !mimeType.startsWith("image/")) {
            throw new IllegalArgumentException("不支援或無法識別的映像格式");
        }
        // 讀取檔案內容並編碼
        byte[] fileBytes = null;
        try{
            fileBytes = Files.readAllBytes(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("無法讀取檔案內容: " + filePath);
        }

        String encodedString = Base64.getEncoder().encodeToString(fileBytes);
        return "data:" + mimeType + ";base64," + encodedString;
    }

    public static void main(String[] args) {
        try {
            call();
        } catch (ApiException | NoApiKeyException | UploadFileException | IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

通過URL下載映像

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
 
public class ImageDownloader {
    public static void downloadImage(String imageUrl, String savePath) {
        try {
            URL url = new URL(imageUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(300000);
            connection.setRequestMethod("GET");
            InputStream inputStream = connection.getInputStream();
            FileOutputStream outputStream = new FileOutputStream(savePath);
            byte[] buffer = new byte[8192];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            inputStream.close();
            outputStream.close();
 
            System.out.println("映像已成功下載到: " + savePath);
        } catch (Exception e) {
            System.err.println("映像下載失敗: " + e.getMessage());
        }
    }
 
    public static void main(String[] args) {
        String imageUrl = "http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx?Expires=xxx";
        String savePath = "output.png";
        downloadImage(imageUrl, savePath);
    }
}

響應樣本

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

{
    "requestId": "46281da9-9e02-941c-ac78-be88b8xxxxxx",
    "usage": {
        "image_count": 2,
        "width": 1216,
        "height": 864
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        },
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ]
                }
            }
        ]
    }
}

計費與限流

新加坡地區

模型名稱

計費單價

限流(主帳號與RAM子帳號共用)

免費額度(查看)

每秒請求數(RPS)限制

同時處理中任務數量

qwen-image-edit-plus

當前與qwen-image-edit-plus-2025-10-30能力相同

$0.03/張

2

同步介面無限制

100張

qwen-image-edit-plus-2025-10-30

$0.03/張

2

同步介面無限制

100張

qwen-image-edit

$0.045/張

2

同步介面無限制

100張

北京地區

模型名稱

計費單價

限流(主帳號與RAM子帳號共用)

免費額度(查看)

每秒請求數(RPS)限制

同時處理中任務數量

qwen-image-edit-plus

當前與qwen-image-edit-plus-2025-10-30能力相同

$0.028671/張

2

同步介面無限制

無免費額度

qwen-image-edit-plus-2025-10-30

$0.028671/張

2

同步介面無限制

qwen-image-edit

$0.043/張

2

同步介面無限制

計費說明:

  • 按成功產生的 映像張數 計費(單次請求如果返回n張圖片,則當次費用為n*單價)。

  • 模型調用失敗或處理錯誤不產生任何費用,也不消耗免費額度

  • 您可開啟“免費額度用完即停”功能,以避免免費額度耗盡後產生額外費用。詳情請參見免費額度

映像存取權限配置

模型產生的映像儲存於阿里雲OSS,每張映像會被分配一個OSS連結,如https://dashscope-result-xx.oss-cn-xxxx.aliyuncs.com/xxx.png。OSS連結允許公開訪問,可以使用此連結查看或者下載圖片,連結僅在 24 小時內有效。

如果您的業務對安全性要求較高,無法訪問阿里雲OSS連結,則需要單獨配置外網訪問白名單。請將以下網域名稱添加到您的白名單中,以便順利訪問圖片連結。

dashscope-result-bj.oss-cn-beijing.aliyuncs.com
dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com
dashscope-result-sh.oss-cn-shanghai.aliyuncs.com
dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com
dashscope-result-zjk.oss-cn-zhangjiakou.aliyuncs.com
dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com
dashscope-result-hy.oss-cn-heyuan.aliyuncs.com
dashscope-result-cd.oss-cn-chengdu.aliyuncs.com
dashscope-result-gz.oss-cn-guangzhou.aliyuncs.com
dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com

錯誤碼

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

常見問題

Q: qwen-image-edit 支援多輪對話式編輯嗎?

A: 不支援。qwen-image-edit模型本身的設計是單輪執行,即每次調用都是一個獨立的、無狀態的編輯任務,不會記憶之前的編輯歷史。若想實現連續編輯,需將上次編輯產生的圖片作為新的輸入圖片,再次調用服務。

Q:qwen-image 和 qwen-image-plus 系列模型支援哪些語言?

A:目前正式支援簡體中文和英文;其他語言可自行嘗試,但效果未經充分驗證,可能存在不確定性。

Q:上傳多張不同比例的參考圖時,輸出映像的比例以哪張為準?

A:輸出映像會以最後一張上傳的參考圖的比例為準。

Q: 如何查看模型調用量?

A: 模型的調用資訊存在小時級延遲,在模型調用完一小時後,請在模型觀測(新加坡北京頁面,查看調用量、調用次數、成功率等指標。如何查看模型調用記錄