千問-映像產生與編輯3.0模型同時支援文生圖(T2I)和圖生圖/影像編輯(I2I),可根據文本提示詞直接產生映像,也可基於1-3張參考圖結合編輯指令進行精確編輯。
該模型目前處於邀測階段,您需要前往模型廣場申請開通後方可使用。
模型概覽
模型名稱 | 模型簡介 | 輸出映像規格 |
qwen-image-3.0-pro | 千問映像產生與編輯3.0模型,同時支援文生圖(T2I)和圖生圖/影像編輯(I2I)。 | 映像解析度:
映像格式: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)圖生圖/影像編輯(I2I) |
要求標頭(Headers) | |
Content-Type 請求內容類型。此參數必須設定為 | |
Authorization 請求身份認證。介面使用阿里雲百鍊API Key進行身份認證。樣本值:Bearer sk-xxxx。 | |
請求體(Request Body) | |
model 模型名稱,當前可用模型為 | |
input 輸入參數對象,包含以下欄位: | |
parameters 控製圖像產生的附加參數。 |
響應參數 | 任務執行成功任務資料(如任務狀態、映像URL等)僅保留24小時,逾時後會被自動清除。請您務必及時儲存產生的映像。 任務執行異常如果因為某種原因導致任務執行失敗,將返回相關資訊,可以通過code和message欄位明確指示錯誤原因。請參見錯誤碼進行解決。 |
output 包含模型產生結果。 | |
usage 本次調用的資源使用方式,僅調用成功時返回。 | |
request_id 請求唯一標識。可用於請求明細溯源和問題排查。 | |
code 請求失敗的錯誤碼。請求成功時不會返回此參數,詳情請參見錯誤碼。 | |
message 請求失敗的詳細資料。請求成功時不會返回此參數,詳情請參見錯誤碼。 |
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;
}
}錯誤碼
如果模型調用失敗並返回報錯資訊,請參見錯誤碼進行解決。