Model pengeditan gambar Qwen mendukung input dan output multi-gambar. Model ini dapat memodifikasi teks dalam gambar secara akurat, menambahkan atau menghapus objek, menyesuaikan pose subjek, mentransfer gaya gambar, serta meningkatkan detail gambar.
Ikhtisar model
Gambar input 1 | Gambar input 2 | Gambar input 3 | Gambar output (beberapa gambar) | |
|
|
|
|
|
Prompt input: Gadis pada Gambar 1 mengenakan gaun hitam dari Gambar 2 dan duduk dalam pose dari Gambar 3.
Model | Deskripsi | Spesifikasi gambar output |
qwen-image-2.0-pro Saat ini memiliki kemampuan yang sama dengan qwen-image-2.0-pro-2026-03-03 | Seri Qwen Pro untuk pembuatan dan pengeditan gambar. Menawarkan peningkatan kemampuan dalam rendering teks, tekstur realistis, dan kepatuhan semantik. Untuk pembuatan gambar, lihat Qwen - teks-ke-gambar. | Resolusi gambar:
Format gambar: PNG Jumlah gambar: 1 hingga 6 |
qwen-image-2.0-pro-2026-03-03 | ||
qwen-image-2.0 Saat ini memiliki kemampuan yang sama dengan qwen-image-2.0-2026-03-03 | Versi akselerasi dari model pembuatan dan pengeditan gambar Qwen yang menyeimbangkan performa dan kecepatan respons. Untuk pembuatan gambar, lihat Qwen - teks-ke-gambar. | |
qwen-image-2.0-2026-03-03 | ||
qwen-image-edit-max Saat ini memiliki kemampuan yang sama dengan qwen-image-edit-max-2026-01-16 | Seri Qwen image editing Max. Menawarkan peningkatan kemampuan untuk desain industri, penalaran geometris, dan konsistensi karakter. | Resolusi gambar:
Format gambar: PNG Jumlah gambar: 1 hingga 6 |
qwen-image-edit-max-2026-01-16 | ||
qwen-image-edit-plus Saat ini memiliki kemampuan yang sama dengan qwen-image-edit-plus-2025-10-30 | Seri Qwen image editing Plus mendukung output multi-gambar dan resolusi kustom. | |
qwen-image-edit-plus-2025-12-15 | ||
qwen-image-edit-plus-2025-10-30 | ||
qwen-image-edit | Mendukung pengeditan gambar tunggal dan fusi multi-gambar. | Resolusi gambar: Tidak dapat dikustomisasi. Resolusi output mengikuti perilaku bawaan yang dijelaskan di atas. Format gambar: PNG Jumlah gambar: 1 |
Sebelum memanggil API, lihat Model untuk setiap wilayah.
Prasyarat
Sebelum melakukan panggilan, dapatkan Kunci API dan ekspor Kunci API sebagai variabel lingkungan.
Untuk memanggil API menggunakan SDK, instal DashScope SDK. SDK tersedia untuk Python dan Java.
Wilayah Beijing dan Singapura memiliki Kunci API dan titik akhir permintaan yang terpisah. Jangan menggunakannya secara bergantian. Pemanggilan lintas-wilayah akan menyebabkan kegagalan autentikasi atau kesalahan layanan.
HTTP
Singapura: POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
Beijing: POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
Parameter permintaan | Pengeditan gambar tunggalContoh ini menunjukkan cara menggunakan model Fusi multi-gambarContoh ini menunjukkan cara menggunakan model |
Header | |
Content-Type Tipe konten permintaan. Harus berupa | |
Authorization Kredensial autentikasi menggunakan Kunci API Model Studio. Contoh: | |
Isi permintaan | |
model Nama model. Contoh nilai: qwen-image-2.0-pro. | |
input Objek input, yang berisi bidang-bidang berikut: | |
parameters Parameter tambahan untuk mengontrol pembuatan gambar. |
Parameter respons | Respons BerhasilData tugas (status tugas dan URL gambar) hanya disimpan selama 24 jam, lalu secara otomatis dihapus. Segera simpan gambar yang dihasilkan. Respons KesalahanJika tugas gagal, respons akan mengembalikan informasi terkait. Anda dapat mengidentifikasi penyebab kegagalan dari bidang kode dan pesan. Untuk informasi lebih lanjut tentang cara menyelesaikan kesalahan, lihat Kode kesalahan. |
output Hasil yang dihasilkan oleh model. | |
usage Penggunaan resource untuk permintaan ini. Parameter ini hanya dikembalikan saat permintaan berhasil. | |
request_id Pengidentifikasi unik untuk permintaan. Gunakan untuk pelacakan dan troubleshooting masalah. | |
code Kode kesalahan. Hanya dikembalikan saat permintaan gagal. Lihat kode kesalahan untuk detailnya. | |
message Pesan kesalahan detail. Hanya dikembalikan saat permintaan gagal. Lihat kode kesalahan untuk detailnya. |
DashScope SDK
Nama parameter SDK sebagian besar konsisten dengan API HTTP. Untuk daftar lengkap parameter, lihat referensi API Qwen.
Python SDK
Instal versi terbaru DashScope Python SDK. Jika tidak, kesalahan waktu proses dapat terjadi: Instal atau upgrade SDK.
API asinkron tidak didukung.
Contoh permintaan
Kirim gambar menggunakan URL publik
import json
import os
import dashscope
from dashscope import MultiModalConversation
# Berikut adalah URL untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# Model mendukung satu hingga tiga gambar 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": "Make the girl from Image 1 wear the black dress from Image 2 and sit in the pose from Image 3."}
]
}
]
# Wilayah Singapura dan Beijing menggunakan Kunci API yang terpisah. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# Ganti dengan Kunci API Anda jika variabel lingkungan belum diatur: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")
# Seri qwen-image-2.0, qwen-image-edit-max, dan qwen-image-edit-plus mendukung output 1 hingga 6 gambar. Contoh ini menunjukkan cara menghasilkan 2 gambar.
response = MultiModalConversation.call(
api_key=api_key,
model="qwen-image-2.0-pro",
messages=messages,
stream=False,
n=2,
watermark=False,
negative_prompt=" ",
prompt_extend=True,
size="1024*1536",
)
if response.status_code == 200:
# Untuk melihat respons lengkap, hapus komentar baris berikut.
# print(json.dumps(response, ensure_ascii=False))
for i, content in enumerate(response.output.choices[0].message.content):
print(f"URL of output image {i+1}: {content['image']}")
else:
print(f"HTTP status code: {response.status_code}")
print(f"Error code: {response.code}")
print(f"Error message: {response.message}")
print("For more information, see the documentation: https://www.alibabacloud.com/help/en/model-studio/error-code")
Kirim gambar menggunakan pengkodean Base64
import json
import os
import dashscope
from dashscope import MultiModalConversation
import base64
import mimetypes
# Berikut adalah URL untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# --- Untuk pengkodean Base64 ---
# Format: 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("Unsupported or unrecognized image format")
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"Error reading file: {file_path}, Error: {str(e)}")
# Dapatkan pengkodean Base64 gambar.
# Panggil fungsi pengkodean. Ganti "/path/to/your/image.png" dengan path ke file gambar lokal Anda.
image = encode_file("/path/to/your/image.png")
messages = [
{
"role": "user",
"content": [
{"image": image},
{"text": "Generate an image that matches the depth map, following this description: A dilapidated red bicycle is parked on a muddy path with a dense primeval forest in the background."}
]
}
]
# Wilayah Singapura dan Beijing menggunakan Kunci API yang terpisah. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# Ganti dengan Kunci API Anda jika variabel lingkungan belum diatur: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")
# Seri qwen-image-2.0, qwen-image-edit-max, dan qwen-image-edit-plus mendukung output 1 hingga 6 gambar. Contoh ini menunjukkan cara menghasilkan 2 gambar.
response = MultiModalConversation.call(
api_key=api_key,
model="qwen-image-2.0-pro",
messages=messages,
stream=False,
n=2,
watermark=False,
negative_prompt=" ",
prompt_extend=True,
size="1536*1024",
)
if response.status_code == 200:
# Untuk melihat respons lengkap, hapus komentar baris berikut.
# print(json.dumps(response, ensure_ascii=False))
for i, content in enumerate(response.output.choices[0].message.content):
print(f"URL of output image {i+1}: {content['image']}")
else:
print(f"HTTP status code: {response.status_code}")
print(f"Error code: {response.code}")
print(f"Error message: {response.message}")
print("For more information, see the documentation: https://www.alibabacloud.com/help/en/model-studio/error-code")
Unduh gambar dari URL
# Instal library requests untuk mengunduh gambar: pip install requests
import requests
def download_image(image_url, save_path='output.png'):
try:
response = requests.get(image_url, stream=True, timeout=300) # Atur timeout
response.raise_for_status() # Bangkitkan pengecualian jika kode status HTTP bukan 200
with open(save_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Image downloaded successfully to: {save_path}")
except requests.exceptions.RequestException as e:
print(f"Image download failed: {e}")
image_url = "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
download_image(image_url, save_path='output.png')
Contoh respons
Tautan gambar berlaku selama 24 jam. Unduh gambar segera.
input_tokensdanoutput_tokensadalah bidang kompatibilitas yang saat ini bernilai tetap 0.
{
"status_code": 200,
"request_id": "fa41f9f9-3cb6-434d-a95d-4ae6b9xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com/xxx.png?Expires=xxx"
},
{
"image": "https://dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com/xxx.png?Expires=xxx"
}
]
}
}
],
"audio": null
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"characters": 0,
"height": 1536,
"image_count": 2,
"width": 1024
}
}Java SDK
Instal versi terbaru DashScope Java SDK. Jika tidak, kesalahan waktu proses dapat terjadi. Lihat Instal atau upgrade SDK.
Contoh permintaan
Kirim gambar menggunakan URL publik
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 berikut untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Wilayah Singapura dan Beijing menggunakan Kunci API yang terpisah. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Anda: apiKey="sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void call() throws ApiException, NoApiKeyException, UploadFileException, IOException {
MultiModalConversation conv = new MultiModalConversation();
// Model mendukung satu hingga tiga gambar input.
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", "Make the girl from Image 1 wear the black dress from Image 2 and sit in the pose from Image 3.")
)).build();
// Seri qwen-image-2.0, qwen-image-edit-max, dan qwen-image-edit-plus mendukung output 1 hingga 6 gambar. Contoh ini menunjukkan cara menghasilkan 2 gambar.
Map<String, Object> parameters = new HashMap<>();
parameters.put("watermark", false);
parameters.put("negative_prompt", " ");
parameters.put("n", 2);
parameters.put("prompt_extend", true);
parameters.put("size", "1024*1536");
MultiModalConversationParam param = MultiModalConversationParam.builder()
.apiKey(apiKey)
.model("qwen-image-2.0-pro")
.messages(Collections.singletonList(userMessage))
.parameters(parameters)
.build();
MultiModalConversationResult result = conv.call(param);
// Untuk melihat respons lengkap, hapus komentar baris berikut.
// 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("URL of output image " + imageIndex + ": " + content.get("image"));
imageIndex++;
}
}
}
public static void main(String[] args) {
try {
call();
} catch (ApiException | NoApiKeyException | UploadFileException | IOException e) {
System.out.println(e.getMessage());
}
}
}Kirim gambar menggunakan pengkodean 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 berikut untuk wilayah Singapura. Jika Anda menggunakan model di wilayah Beijing, ganti URL dengan: https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Wilayah Singapura dan Beijing menggunakan Kunci API yang terpisah. Dapatkan Kunci API: https://www.alibabacloud.com/help/en/model-studio/get-api-key
// Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan Kunci API Anda: apiKey="sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void call() throws ApiException, NoApiKeyException, UploadFileException, IOException {
// Ganti "/path/to/your/image.png" dengan path ke file gambar lokal Anda.
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", "Generate an image that matches the depth map, following this description: A dilapidated red bicycle is parked on a muddy path with a dense primeval forest in the background.")
)).build();
// Seri qwen-image-2.0, qwen-image-edit-max, dan qwen-image-edit-plus mendukung output 1 hingga 6 gambar. Contoh ini menunjukkan cara menghasilkan 2 gambar.
Map<String, Object> parameters = new HashMap<>();
parameters.put("watermark", false);
parameters.put("negative_prompt", " ");
parameters.put("n", 2);
parameters.put("prompt_extend", true);
parameters.put("size", "1536*1024");
MultiModalConversationParam param = MultiModalConversationParam.builder()
.apiKey(apiKey)
.model("qwen-image-2.0-pro")
.messages(Collections.singletonList(userMessage))
.parameters(parameters)
.build();
MultiModalConversationResult result = conv.call(param);
// Untuk melihat respons lengkap, hapus komentar baris berikut.
// 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("URL of output image " + imageIndex + ": " + content.get("image"));
imageIndex++;
}
}
}
/**
* Mengkodekan file menjadi string Base64.
* @param filePath Path file.
* @return String Base64 dalam format: data:{mime_type};base64,{base64_data}
*/
public static String encodeFile(String filePath) {
Path path = Paths.get(filePath);
if (!Files.exists(path)) {
throw new IllegalArgumentException("File does not exist: " + filePath);
}
// Deteksi tipe MIME.
String mimeType = null;
try {
mimeType = Files.probeContentType(path);
} catch (IOException e) {
throw new IllegalArgumentException("Unable to detect file type: " + filePath);
}
if (mimeType == null || !mimeType.startsWith("image/")) {
throw new IllegalArgumentException("Unsupported or unrecognized image format");
}
// Baca konten file dan enkode.
byte[] fileBytes = null;
try{
fileBytes = Files.readAllBytes(path);
} catch (IOException e) {
throw new IllegalArgumentException("Unable to read file content: " + 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());
}
}
}Unduh gambar dari 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("Image downloaded successfully to: " + savePath);
} catch (Exception e) {
System.err.println("Image download failed: " + 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);
}
}Contoh respons
Tautan gambar berlaku selama 24 jam. Unduh gambar segera.
{
"requestId": "46281da9-9e02-941c-ac78-be88b8xxxxxx",
"usage": {
"image_count": 2,
"width": 1024,
"height": 1536
},
"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"
}
]
}
}
]
}
}Kode kesalahan
Jika pemanggilan model gagal dan mengembalikan pesan kesalahan, lihat Pesan Kesalahan untuk informasi penyelesaiannya.
Penagihan dan pembatasan laju
Untuk harga model dan kuota gratis, lihat Daftar model dan harga.
Untuk batas laju, lihat Batas laju.
Deskripsi penagihan: Anda dikenai biaya berdasarkan jumlah gambar yang berhasil dihasilkan. Pemanggilan model yang gagal atau kesalahan pemrosesan tidak dikenai biaya dan tidak mengurangi kuota gratis.
FAQ
T: Bahasa apa saja yang didukung oleh model pengeditan gambar Qwen?
J: Model ini secara resmi mendukung Bahasa Tionghoa Sederhana dan English. Bahasa lain mungkin berfungsi, tetapi hasilnya tidak dijamin.
T: Bagaimana cara melihat metrik pemanggilan model?
J: Satu jam setelah pemanggilan model selesai, buka halaman Monitoring (Singapura) atau Monitoring (China (Beijing)) untuk melihat metrik seperti jumlah pemanggilan dan tingkat keberhasilan. Untuk informasi lebih lanjut, lihat Kueri tagihan dan manajemen biaya.
T: Bagaimana cara mendapatkan daftar putih nama domain untuk penyimpanan gambar?
J: Gambar yang dihasilkan oleh model disimpan di OSS. API mengembalikan URL publik sementara. Untuk mengonfigurasi daftar putih firewall untuk URL unduhan ini, perhatikan hal berikut: Penyimpanan dasar dapat berubah secara dinamis. Topik ini tidak menyediakan daftar putih nama domain OSS tetap untuk mencegah masalah akses akibat informasi yang kedaluwarsa. Jika Anda memiliki persyaratan kontrol keamanan, hubungi manajer akun Anda untuk mendapatkan daftar nama domain OSS terbaru.




