通义千问-图像翻译模型(Qwen-MT-Image)可精准翻译图像中的文字,并保留原始排版。该模型还支持领域提示、敏感词过滤、术语干预等自定义功能。
模型概览
效果示例
源语种:中文 |
英文 |
日文 |
韩语 |
西班牙语 |
法语 |
支持的语种
进行图像翻译时,源语种或目标语种必须至少有一种是中文或英文。不支持在两个非中、英语种之间直接翻译(例如,从日语翻译为韩语)。若不确定源语种,可将 source_lang 设置为 auto 进行自动检测。
语种(中文名) | 英文全称 | 编码 | 支持作为源语种 | 支持作为目标语种 |
简体中文 | Chinese | zh | ||
英文 | English | en | ||
韩语 | Korean | ko | ||
日语 | Japanese | ja | ||
俄语 | Russian | ru | ||
西班牙语 | Spanish | es | ||
法语 | French | fr | ||
葡萄牙语 | Portuguese | pt | ||
意大利语 | Italian | it | ||
德语 | Germany | de | ||
越南语 | Vietnamese | vi | ||
马来语 | Malay | ms | ||
泰语 | Thai | th | ||
印尼语 | Indonesian | id | ||
阿拉伯语 | Arabian | ar |
模型与价格
按成功翻译的图像张数计费。计费规则如下:
当任务成功 (
task_status为SUCCEEDED) 并成功生成图像后,会计费。特殊情况:如果图像中无可翻译文本,或在启用图像主体识别后其余部分无文字时,任务仍会成功,正常计费,但会返回
No text detected for translation的提示。因参数错误、服务内部错误或网络连接失败等问题而失败的请求,不产生费用,也不消耗免费额度。
模型名称 | 计费单价 | 限流(主账号与RAM子账号共用) | 免费额度(查看) | |
任务下发接口RPS限制 | 同时处理中任务数量 | |||
qwen-mt-image | 0.003元/张 | 1 | 2 | 100张 有效期:百炼开通后90天内 |
HTTP调用
您需要已获取API Key并配置API Key到环境变量。
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis
图像翻译复用图像合成的API Endpoint。
由于图像翻译耗时较长,HTTP API 采用异步模式,调用流程分两步:
创建任务获取任务ID:发送一个请求创建任务,该请求会返回任务ID(task_id)。
根据任务ID查询结果:使用task_id轮询任务状态,直到任务完成并获得图像URL。
步骤1:创建任务获取任务ID
创建成功后,使用接口返回的
task_id查询结果,task_id 有效期为 24 小时。请勿重复创建任务,轮询获取即可。新手指引请参见Postman。
请求参数 | 图像翻译 |
请求头(Headers) | |
Content-Type 请求内容类型。此参数必须设置为 | |
Authorization 请求身份认证。接口使用阿里云百炼API-Key进行身份认证。示例值:Bearer sk-xxxx。 | |
X-DashScope-Async 异步处理配置参数。HTTP请求只支持异步,必须设置为 重要 缺少此请求头将报错:“current user api does not support synchronous calls”。 | |
请求体(Request Body) | |
model 模型名称,需要设置为 | |
input 输入参数对象,包含以下字段: |
响应参数 | 成功响应请保存 task_id,用于查询任务状态与结果。 异常响应创建任务失败,请参见错误信息进行解决。 |
output 任务输出信息。 | |
request_id 请求唯一标识。可用于请求明细溯源和问题排查。 | |
message 请求失败的详细信息。请求成功时不会返回此参数,详情请参见错误信息。 | |
code 请求失败的错误码。请求成功时不会返回此参数,详情请参见错误信息。 |
步骤2:根据任务ID查询结果
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
请求参数 | 查询任务结果您需要将 |
请求头(Headers) | |
Authorization 请求身份认证。接口使用阿里云百炼API-Key进行身份认证。示例值:Bearer sk-xxxx。 | |
URL路径参数(Path parameters) | |
task_id 任务ID。 |
响应参数 | 任务执行成功任务数据(如任务状态、图像URL等)仅保留24小时,超时后会被自动清除。请您务必及时保存生成的图像。 任务执行失败若任务执行失败,task_status将置为 FAILED,并提供错误码和信息。请参见错误信息进行解决。 |
output 任务输出信息。 | |
usage 输出信息统计。只对成功的结果计数。 | |
request_id 请求唯一标识。可用于请求明细溯源和问题排查。 |
代码示例
除 cURL 外,本节还提供了其他 HTTP 请求的代码示例,通过轮询方式获取结果。如需通过事件通知的方式获取结果,请参考配置异步任务回调。
Python
# 需要安装 requests 依赖
import requests
import time
import json
import os
# 若没有配置环境变量,请将下行替换为:DASHSCOPE_API_KEY="sk-xxx"
DASHSCOPE_API_KEY = os.environ['DASHSCOPE_API_KEY']
POST_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis"
GET_URL_TEMPLATE = "https://dashscope.aliyuncs.com/api/v1/tasks/{}"
# 请求头
headers = {
"X-DashScope-Async": "enable",
"Authorization": f"Bearer {DASHSCOPE_API_KEY}",
"Content-Type": "application/json"
}
# 请求数据
data = {
"model": "qwen-mt-image",
"input": {
"image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250916/ordhsk/1.webp",
"source_lang": "zh",
"target_lang": "en"
}
}
def send_async_request():
"""
发送异步POST请求
"""
print("发送异步POST请求...")
response = requests.post(POST_URL, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
print("请求成功,返回结果:")
print(json.dumps(result, indent=2, ensure_ascii=False))
# 提取task_id
task_id = result.get("output", {}).get("task_id")
if task_id:
return task_id
else:
raise ValueError("响应中未找到task_id")
else:
print(f"请求失败,状态码: {response.status_code}")
print(response.text)
raise Exception(f"POST请求失败: {response.status_code}")
def poll_task_status(task_id, interval=5, max_attempts=10):
"""
轮询任务状态
:param task_id: 任务ID
:param interval: 轮询间隔(秒)
:param max_attempts: 最大轮询次数
:return: 最终任务结果
"""
print(f"\n开始轮询任务状态,task_id: {task_id}")
for attempt in range(1, max_attempts + 1):
print(f"第 {attempt} 次轮询...")
# 构造GET请求URL
get_url = GET_URL_TEMPLATE.format(task_id)
# 发送GET请求
response = requests.get(get_url, headers={"Authorization": f"Bearer {DASHSCOPE_API_KEY}"})
if response.status_code == 200:
result = response.json()
task_status = result.get("output", {}).get("task_status")
print(f"当前任务状态: {task_status}")
# 如果任务完成或失败,返回结果
if task_status == "SUCCEEDED":
print("任务执行完成")
return result
elif task_status == "FAILED":
print("任务执行失败")
return result
elif task_status == "PENDING" or task_status == "RUNNING":
# 继续轮询
print(f"任务仍在进行中,等待 {interval} 秒后继续轮询...")
time.sleep(interval)
else:
print(f"未知任务状态: {task_status}")
time.sleep(interval)
else:
print(f"轮询请求失败,状态码: {response.status_code}")
print(response.text)
time.sleep(interval)
# 超过最大轮询次数
raise TimeoutError("轮询超时,任务未在预期时间内完成")
def main():
task_id = send_async_request()
result = poll_task_status(task_id)
print("\n最终任务结果:")
print(json.dumps(result, indent=2, ensure_ascii=False))
if result.get("output", {}).get("task_status") == "SUCCEEDED":
image_url = result.get("output", {}).get("image_url")
if image_url:
print(f"\n生成的图像URL: {image_url}")
if __name__ == "__main__":
main()
Java
// 需要添加 Gson 依赖
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.nio.charset.StandardCharsets;
public class Main {
private static final String POST_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis";
private static final String GET_URL_TEMPLATE = "https://dashscope.aliyuncs.com/api/v1/tasks/";
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
public static void main(String[] args) {
try {
// 1. 获取 API Key
// 若没有配置环境变量,请将下行替换为:apiKey="sk-xxx"
String apiKey = System.getenv("DASHSCOPE_API_KEY");
if (apiKey == null || apiKey.isEmpty()) {
System.err.println("请设置环境变量 DASHSCOPE_API_KEY");
return;
}
// 2. 发送异步请求
String taskId = sendAsyncRequest(apiKey);
// 3. 轮询任务状态
JsonObject result = pollTaskStatus(apiKey, taskId, 5, 10);
// 4. 输出最终结果
System.out.println("\n最终任务结果:");
System.out.println(gson.toJson(result));
// 5. 如果任务成功,输出图像URL
String taskStatus = result.getAsJsonObject("output").get("task_status").getAsString();
if ("SUCCEEDED".equals(taskStatus)) {
String imageUrl = result.getAsJsonObject("output").get("image_url").getAsString();
System.out.println("\n生成的图像URL: " + imageUrl);
}
} catch (Exception e) {
System.err.println("执行过程中出现错误: " + e.getMessage());
e.printStackTrace();
}
}
/**
* 发送异步POST请求
*/
private static String sendAsyncRequest(String apiKey) throws IOException {
System.out.println("发送异步POST请求...");
// 构建请求数据
Map<String, Object> data = new HashMap<>();
data.put("model", "qwen-mt-image");
Map<String, Object> input = new HashMap<>();
input.put("image_url", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250916/ordhsk/1.webp");
input.put("source_lang", "zh");
input.put("target_lang", "en");
data.put("input", input);
String jsonData = gson.toJson(data);
// 创建连接
URL url = new URL(POST_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置请求头
connection.setRequestMethod("POST");
connection.setRequestProperty("X-DashScope-Async", "enable");
connection.setRequestProperty("Authorization", "Bearer " + apiKey);
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
// 发送请求体
try (OutputStream os = connection.getOutputStream()) {
byte[] inputBytes = jsonData.getBytes(StandardCharsets.UTF_8);
os.write(inputBytes, 0, inputBytes.length);
}
// 读取响应
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
StringBuilder response = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
}
System.out.println("请求成功,返回结果:");
JsonObject jsonResponse = gson.fromJson(response.toString(), JsonObject.class);
System.out.println(gson.toJson(jsonResponse));
// 提取task_id
JsonObject result = gson.fromJson(response.toString(), JsonObject.class);
String taskId = result.getAsJsonObject("output").get("task_id").getAsString();
if (taskId != null && !taskId.isEmpty()) {
return taskId;
} else {
throw new RuntimeException("响应中未找到task_id");
}
} else {
System.out.println("请求失败,状态码: " + responseCode);
StringBuilder errorResponse = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))) {
String responseLine;
while ((responseLine = br.readLine()) != null) {
errorResponse.append(responseLine.trim());
}
}
System.out.println(errorResponse.toString());
throw new RuntimeException("POST请求失败: " + responseCode);
}
}
/**
* 轮询任务状态
*
* @param apiKey API密钥
* @param taskId 任务ID
* @param interval 轮询间隔(秒)
* @param maxAttempts 最大轮询次数
* @return 最终任务结果
*/
private static JsonObject pollTaskStatus(String apiKey, String taskId, int interval, int maxAttempts) throws IOException, InterruptedException {
System.out.println("\n开始轮询任务状态,task_id: " + taskId);
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
System.out.println("第 " + attempt + " 次轮询...");
// 构造GET请求URL
String getUrl = GET_URL_TEMPLATE + taskId;
// 创建连接
URL url = new URL(getUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置请求头
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Bearer " + apiKey);
// 读取响应
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
StringBuilder response = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
}
JsonObject result = gson.fromJson(response.toString(), JsonObject.class);
String taskStatus = result.getAsJsonObject("output").get("task_status").getAsString();
System.out.println("当前任务状态: " + taskStatus);
// 如果任务完成或失败,返回结果
if ("SUCCEEDED".equals(taskStatus) || "FAILED".equals(taskStatus)) {
System.out.println("任务执行完成");
return result;
} else if ("PENDING".equals(taskStatus) || "RUNNING".equals(taskStatus)) {
// 继续轮询
System.out.println("任务仍在进行中,等待 " + interval + " 秒后继续轮询...");
TimeUnit.SECONDS.sleep(interval);
} else {
System.out.println("未知任务状态: " + taskStatus);
TimeUnit.SECONDS.sleep(interval);
}
} else {
System.out.println("轮询请求失败,状态码: " + responseCode);
StringBuilder errorResponse = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))) {
String responseLine;
while ((responseLine = br.readLine()) != null) {
errorResponse.append(responseLine.trim());
}
}
System.out.println(errorResponse.toString());
TimeUnit.SECONDS.sleep(interval);
}
}
// 超过最大轮询次数
throw new RuntimeException("轮询超时,任务未在预期时间内完成");
}
}
返回结果
发送异步POST请求...
请求成功,返回结果:
{
"request_id": "ba607b73-8743-42cb-a605-c4db9688fc6e",
"output": {
"task_id": "9e82f1a9-12f4-4423-93e0-bb49xxxxxxxx",
"task_status": "PENDING"
}
}
开始轮询任务状态,task_id: 9e82f1a9-12f4-4423-93e0-bb49xxxxxxxx
第 1 次轮询...
当前任务状态: RUNNING
任务仍在进行中,等待 5 秒后继续轮询...
第 2 次轮询...
当前任务状态: RUNNING
任务仍在进行中,等待 5 秒后继续轮询...
第 3 次轮询...
当前任务状态: SUCCEEDED
任务执行完成
最终任务结果:
{
"request_id": "a1419de4-3f62-4582-8097-e6a66a843536",
"output": {
"task_id": "9e82f1a9-12f4-4423-93e0-bb49xxxxxxxx",
"task_status": "SUCCEEDED",
"submit_time": "2025-09-13 16:33:14.835",
"scheduled_time": "2025-09-13 16:33:14.861",
"end_time": "2025-09-13 16:33:20.436",
"image_url": "http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx?Expires=xxx",
"message": ""
},
"usage": {
"image_count": 1
}
}
生成的图像URL: http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx?Expires=xxx图像访问权限配置
模型生成的图像存储于阿里云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: 如何将临时的图像链接转为永久链接?
A: 临时链接无法直接转为永久链接。需通过后端服务下载图像,再上传至对象存储服务(如阿里云 OSS)以生成新的永久链接。
Q: 如何查看模型调用量?
A: 模型调用完一小时后,请在模型观测页面,查看模型的调用次数、成功率等指标。如何查看模型调用记录





