全部產品
Search
文件中心

Alibaba Cloud Model Studio:千問-映像產生與編輯3.0 API參考

更新時間:Jul 21, 2026

千問-映像產生與編輯3.0模型同時支援文生圖(T2I)和圖生圖/影像編輯(I2I),可根據文本提示詞直接產生映像,也可基於1-3張參考圖結合編輯指令進行精確編輯。

重要

該模型目前處於邀測階段,您需要前往模型廣場申請開通後方可使用。

模型概覽

模型名稱

模型簡介

輸出映像規格

qwen-image-3.0-pro

千問映像產生與編輯3.0模型,同時支援文生圖(T2I)和圖生圖/影像編輯(I2I)。

映像解析度:

  • 文生圖(T2I):總像素需在512*512至2048*2048之間。

  • 圖生圖(I2I):總像素需在512*512至2048*2048之間。

  • 預設:不指定size時,模型根據提示詞自動推薦解析度。

映像格式:png

前提條件

在調用前,您需要擷取API Key,再配置API Key到環境變數

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

請將範例程式碼中的 DASHSCOPE_API_HOST 替換為擷取的 API Host。
重要

華北2(北京)和新加坡地區擁有獨立的 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調用

新加坡地區:POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

北京地區:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

調用時請將{WorkspaceId}替換為真實的Workspace ID

請求參數

文生圖(T2I)

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "qwen-image-3.0-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "text": "A vertical outdoor portrait photograph with a warm afternoon street atmosphere. Deep green vines and small orange flowers cascade from building eaves across the upper area. A dark blue sign reads 'Il Messaggero' in white Gothic lettering, partially obscured by foliage. Below, a newsstand displays newspapers behind black metal-framed glass, blurred by shallow depth of field. Strong backlight streams from the street's end. Center-right, a young woman in a black spaghetti-strap backless dress looks back at the camera with a warm smile. Her long, thick wavy black hair is outlined by golden rim light. She has fair skin, bright eyes, soft coral-red lips, and holds a large bouquet of orange, apricot, pink and peach roses contrasting with her black dress. The sunlit city street stretches into the blurred background. Warm film-like tones with fine grain, soft contrast and pronounced backlit edge glow create a romantic, bright, urban strolling atmosphere."
                    }
                ]
            }
        ]
    },
    "parameters": {
        "prompt_extend": true
    }
}'

圖生圖/影像編輯(I2I)

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "qwen-image-3.0-pro",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "image": "https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/yBRq1ZPYEaXdyOdv/img/33a80a19-7ac7-4c64-b0fa-7d685b7046a0.png"
                    },
                    {
                        "text": "Generate a sophisticated urban-style female portrait. Perfectly preserve the facial features and smooth black long hair of the young woman in the input image. She changes from her beige knit top into an elegant urban professional outfit: a champagne silk blouse with a well-tailored dark grey casual blazer and matching high-waisted wide-leg trousers. The scene is in a modern minimalist upscale coffee shop with floor-to-ceiling windows showing a bustling city view. Dark wood tables and leather chairs furnish the interior, with a silver laptop, documents, and a steaming Americano on the table. She sits relaxed, leaning slightly back with one arm on the armrest and the other holding a coffee cup, gazing at the camera with calm, slightly languid eyes and an elegant smile. Polished formal makeup with clean base, defined brows, and mauve lipstick. Soft afternoon light enters from the side through the windows, creating delicate light transitions on her face and clothing. Natural bokeh background in earth tones, greys and warm whites, creating a serene, sophisticated urban office atmosphere."
                    }
                ]
            }
        ]
    },
    "parameters": {
        "prompt_extend": true
    }
}'
要求標頭(Headers)

Content-Type string (必選)

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

Authorization string(必選)

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

請求體(Request Body)

model string (必選)

模型名稱,當前可用模型為qwen-image-3.0-pro

input object (必選)

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

屬性

messages array (必選)

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

屬性

role string (必選)

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

content array (必選)

訊息內容數組,根據使用情境有不同的組合方式:

  • 文生圖(T2I):僅包含一個{"text": "..."}對象。

  • 圖生圖(I2I):包含1-3個{"image": "..."}對象和1個{"text": "..."}對象。

屬性

image string (可選)

輸入映像的 URL 或 Base 64 編碼資料。I2I情境下支援傳入1-3張映像。多圖輸入時,按照數組順序定義映像順序。

映像要求:

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

  • 映像解析度:建議映像的寬和高均在384像素至2048像素之間。

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

支援的輸入格式

  1. 公網URL:支援 HTTP 和 HTTPS 協議。

  2. Base 64 編碼:格式為data:{MIME_type};base64,{base64_data}

text string (必選)

正向提示詞,用於描述您期望產生或編輯的映像內容、風格和構圖。支援中英文。

注意:僅支援傳入一個text,不傳或傳入多個將報錯。

parameters object (可選)

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

屬性

prompt_extend boolean (可選)

是否開啟提示詞智能改寫,預設值為 true(建議開啟)。開啟後,模型會最佳化正向提示詞,對描述較簡單的提示詞效果提升明顯。

n integer (可選)

輸出映像的數量,支援輸出1-6張圖片,預設值為1。

size string (可選)

設定輸出映像的解析度,格式為寬*高,例如"1024*1024"。未指定時由模型根據提示詞自動推薦解析度。

  • 文生圖(T2I):像素範圍512*512至2048*2048。

  • 圖生圖(I2I):像素範圍512*512至2048*2048。

negative_prompt string (可選)

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

seed integer (可選)

隨機數種子,取值範圍[0, 2147483647]。固定種子可使產生結果相對穩定。

watermark boolean (可選)

是否添加浮水印,預設值為 false

響應參數

任務執行成功

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

{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ],
                    "role": "assistant"
                }
            }
        ]
    },
    "usage": {
        "width": 1024,
        "height": 1024,
        "image_count": 1
    },
    "request_id": "571ae02f-5c9d-436c-83c2-f221e6df0xxx"
}

任務執行異常

如果因為某種原因導致任務執行失敗,將返回相關資訊,可以通過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,格式為PNG。連結有效期間為24小時,請及時下載並儲存映像。

usage object

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

屬性

width integer

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

height integer

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

image_count integer

產生映像的張數。

request_id string

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

code string

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

message string

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

SDK調用

以下以圖生圖/影像編輯(I2I)為樣本,展示Python和Java SDK的調用方式。

Python

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

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

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

# [方法一] 使用公網映像URL
image_url = "https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/yBRq1ZPYEaXdyOdv/img/33a80a19-7ac7-4c64-b0fa-7d685b7046a0.png"

# [方法二] 使用Base64編碼映像
# image_url = encode_file("./your_image.png")

response = MultiModalConversation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen-image-3.0-pro",
    messages=[{
        "role": "user",
        "content": [
            {"image": image_url},
            {"text": "幫我產生一張充滿進階感的都市風格女性寫真,畫面中人物完美保留輸入圖片中這位年輕女性的面部特徵與一頭柔順的黑色長髮。人物換上一套彰顯高雅氣質的都市職場穿搭,情境設定在一家裝修現代簡約的高端咖啡店內。"}
        ]
    }],
    prompt_extend=True
)

print(response)
if response.status_code == 200:
    url = response.output.choices[0].message.content[0]["image"]
    print(f"Generated image URL: {url}")
else:
    print(f"Error: {response.code} - {response.message}")

Java

import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
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.utils.Constants;

public class ImageEditExample {
    public static void main(String[] args) {
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";

        // [方法一] 使用公網映像URL
        String imageUrl = "https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/yBRq1ZPYEaXdyOdv/img/33a80a19-7ac7-4c64-b0fa-7d685b7046a0.png";

        // [方法二] 使用Base64編碼映像
        // String imageUrl = encodeFile("/path/to/your/image.png");

        MultiModalConversation conv = new MultiModalConversation();
        MultiModalMessage userMessage = MultiModalMessage.builder()
            .role(Role.USER.getValue())
            .content(Arrays.asList(
                Collections.singletonMap("image", imageUrl),
                Collections.singletonMap("text", "幫我產生一張充滿進階感的都市風格女性寫真,畫面中人物完美保留輸入圖片中這位年輕女性的面部特徵與一頭柔順的黑色長髮。人物換上一套彰顯高雅氣質的都市職場穿搭,情境設定在一家裝修現代簡約的高端咖啡店內。")
            ))
            .build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
            .apiKey(System.getenv("DASHSCOPE_API_KEY"))
            .model("qwen-image-3.0-pro")
            .messages(Arrays.asList(userMessage))
            .parameter("prompt_extend", true)
            .build();
        try {
            MultiModalConversationResult result = conv.call(param);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

錯誤碼

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