模型概览及对比
模型概览
您可以选择全面升级的通义万相-文生图V2系列模型进行文生图创作,请使用通义万相官网体验效果。

基础文生图模型,支持设置文生图的风格,支持基于参考图像进行二次创作,生成相似风格的图像。

模型版本 | 模型名称 | 模型简介 |
通义万相文生图2.1 (文生图V2版) | wanx2.1-t2i-plus | 全面升级版本。生成图像细节更丰富,速度稍慢。对应通义万相官网2.1专业模型。 |
wanx2.1-t2i-turbo | 全面升级版本。生成速度快、效果全面、综合性价比高。对应通义万相官网2.1极速模型。 |
通义万相文生图2.0 (文生图V2版) | wanx2.0-t2i-turbo | 擅长质感人像,速度中等、成本较低。对应通义万相官网2.0极速模型。 |
通义万相文生图1.0 (文生图V1版) | wanx-v1 | 基础文生图模型。对应通义万相官网1.0通用模型。 |
模型名称 | 计费单价 | 限流(主账号与RAM子账号共用) | 免费额度 |
任务下发接口RPS限制 | 同时处理中任务数量 |
模型名称 | 计费单价 | 限流(主账号与RAM子账号共用) | 免费额度 |
任务下发接口RPS限制 | 同时处理中任务数量 |
wanx2.1-t2i-plus | 0.20元/张 | 2 | 2 | 免费额度:500张 有效期:阿里云百炼开通后180天内 |
wanx2.1-t2i-turbo | 0.14元/张 | 2 | 2 |
wanx2.0-t2i-turbo | 0.04元/张 | 2 | 2 |
wanx-v1 | 0.16元/张 | 2 | 1 |
模型效果对比
下表对比了文生图三个模型的生成效果,仅调整prompt,其他参数均使用API默认值。
模型建议:推荐优先选择文生图V2版模型。
文生图2.1(wanx2.1-t2i-turbo) | 文生图2.0(wanx2.0-t2i-turbo) | 文生图1.0(wanx- v1) |
文生图2.1(wanx2.1-t2i-turbo) | 文生图2.0(wanx2.0-t2i-turbo) | 文生图1.0(wanx- v1) |
prompt = "生成一张新年祝福贺卡,背景有白雪,放鞭炮的小孩,蛇形成文案2025,并写上HAPPY NEW YEAR。" 效果对比:文生图2.1模型的文字生成能力更强,适合创意设计场景。 |

| 
| 
|
prompt = "一个用针毡制作的圣诞老人手持礼物,旁边站着一只白色的猫咪,背景中有许多五颜六色的礼物。整个场景应该是可爱、温暖和舒适的,并且背景中还有一些绿色植物。" 效果对比:文生图2.1模型的语义理解更加准确(如手持礼物),生成的图像质量更高。 |

| 
| 
|
prompt = "中国女孩,圆脸,看着镜头,优雅的民族服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。 " 效果对比:文生图2.0模型在质感人像生成方面表现出色,其成本仅为文生图2.1模型的三分之一,性价比高。 |

| 
| 
|
prompt = "高清摄影写真,一只布偶猫慵懒地躺在复古木质窗台上。它拥有一身柔软的银白色长毛,深蓝色宝石般的眼睛,粉嫩的小鼻头和肉垫。猫咪眼神温柔地望向镜头,嘴角似乎带着一抹满足的微笑。午后阳光透过半开的窗户洒在它身上,营造出温馨而宁静的氛围。背景是模糊的绿色植物和老式窗帘,增添了几分生活气息。近景特写,自然光影效果。" 效果对比:文生图2.1模型在动物图像的生成和理解方面更具优势,其他两个模型没有生成布偶猫,1.0模型生成的动物图像质量较差。 |

| 
| 
|
文生图2.1(wanx2.1-t2i-turbo)
文生图2.0(wanx2.0-t2i-turbo)
文生图1.0(wanx- v1)
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx2.1-t2i-turbo",
"input": {
"prompt": "生成一张新年祝福贺卡,背景有白雪,放鞭炮的小孩,蛇形成文案2025,并写上HAPPY NEW YEAR。"
}
}'
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx2.0-t2i-turbo",
"input": {
"prompt": "生成一张新年祝福贺卡,背景有白雪,放鞭炮的小孩,蛇形成文案2025,并写上HAPPY NEW YEAR。"
}
}'
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx-v1",
"input": {
"prompt": "生成一张新年祝福贺卡,背景有白雪,放鞭炮的小孩,蛇形成文案2025,并写上HAPPY NEW YEAR。"
}
}'
前期准备
文生图V2和V1版模型API均支持通过HTTP和DashScope SDK进行调用。
下面展示文生图V2版和V1版的HTTP请求参数。
{
"model": "",
"input": {
"prompt": "",
"negative_prompt": ""
},
"parameters": {
"size": "1024*1024",
"n": 4,
"prompt_extend": true,
"watermark": false,
"seed": 42
}
}
{
"model": "",
"input": {
"prompt": "",
"negative_prompt": "",
"ref_img": ""
},
"parameters": {
"style": "<auto>",
"size": "1024*1024",
"n": 4,
"ref_strength": 0.5,
"ref_mode": "repaint",
"seed": 42
}
}
提示词
文生图模型需要使用一段文字描述生成的图片。提示词(prompt)描述越完整、精确和丰富,生成的图像品质越高,越贴近期望生成的内容。
提示词撰写技巧请参见文生图Prompt指南。
关键能力-文生图V2版
通义万相-文生图V2版模型的升级要点如下所示。参数说明请参见通义万相-文生图V2版。
prompt智能改写:默认开启智能改写,对于较短的输入prompt生成效果提升明显。推荐使用默认值。
按任意分辨率生成图像:文生图V1版模型仅支持4种输出图像分辨率,V2版模型支持设置任意分辨率,最高可达200万像素。
添加水印:开放水印参数,可为输出图像添加水印。默认不添加水印。
prompt智能改写
通过prompt_extend
控制是否开启prompt智能改写。默认开启智能改写,开启后会使用大模型(qwen模型)对输入prompt进行智能改写。对于较短的输入prompt生成效果提升明显,但会增加3-4秒耗时。
下面展示两个开启prompt智能改写的前后对比示例,模型使用wanx2.1-t2i-turbo
。
不开启智能改写 | 开启智能改写 | 改写后的prompt |

| 
| 废土风格的火星城市,画面中可以看到荒凉的红色沙地和破败的建筑。城市中散布着废弃的车辆和机械残骸,天空呈现出暗淡的橙黄色。远处有几座破损的高楼,表面覆盖着尘土和裂痕。近景处有一群穿着厚重防护服的探险者,他们手持武器,警惕地观察四周。整体色调偏暗,充满末日氛围。长焦镜头拍摄,细节丰富。 |

| 
| 废土风格的火星城市,荒凉的红色地表上散布着废弃的建筑和残破的机械。城市的天际线被尘暴笼罩,远处可见几座破损的高塔。街道上散落着锈迹斑斑的车辆和碎片。画面整体色调偏暗,充满末日氛围。近景中有一辆破旧的越野车停在路边,驾驶舱内坐着一位穿着厚重防护服的探险者,他/她正凝视前方。长焦镜头,写实摄影风格。 |
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
prompt = "火星上的城市,废土风格。"
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model="wanx2.1-t2i-turbo",
prompt=prompt,
n=2,
prompt_extend=True,
size='1024*1024')
print('response: %s' % rsp)
if rsp.status_code == HTTPStatus.OK:
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
public class Main {
public static void basicCall() throws ApiException, NoApiKeyException {
String prompt = "火星上的城市,废土风格。";
HashMap<String,Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("wanx2.1-t2i-turbo")
.prompt(prompt)
.n(2)
.size("1024*1024")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args){
try{
basicCall();
}catch(ApiException|NoApiKeyException e){
System.out.println(e.getMessage());
}
}
}
HTTP调用仅支持异步获取模型结果,您需要发起两个请求。
创建任务
此接口返回任务ID,可根据任务ID查询图像生成的结果。
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx2.1-t2i-turbo",
"input": {
"prompt": "火星上的城市,废土风格。"
},
"parameters": {
"size": "1024*1024",
"n": 2,
"prompt_extend": true
}
}'
根据任务ID查询结果
curl -X GET https://dashscope.aliyuncs.com/api/v1/tasks/{your_task_id} \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
注意:需要将{your_task_id}
替换为真实的任务ID。
prompt = "外景,香水瓶,产品照片,暖色调"
不开启智能改写 | 开启智能改写 | 改写后的prompt |

| 
| 暖色调外景产品照片,一瓶精致的香水瓶置于画面中央。香水瓶身透明,内部液体呈淡金色,瓶盖为金色金属质感。背景是温暖的夕阳下,绿树成荫的小径和远处的建筑。光线柔和,营造出温馨舒适的氛围。高清写实摄影,近景特写构图。 |

| 
| 暖色调外景产品照片,一瓶精致的香水瓶置于画面中央。香水瓶身透明,内装淡粉色液体,瓶颈装饰有金色细节。背景是柔和的自然景观,可见蓝天、白云和远处的树木。光线温暖,营造出温馨浪漫的氛围。高清写实摄影,近景特写构图。 |
按任意分辨率生成图像
通过设置 size
参数来控制输出图像的分辨率。
升级版的文生图V2版模型支持自定义设置图像分辨率,图像宽高边长的像素范围为:[768, 1440],默认值是1024*1024。
下面展示常见的输出图像分辨率尺寸,模型使用wanx2.1-t2i-plus
。
size=768*1024(3:4) | size=1024*768(4:3) | size=1024*1024(1:1) |
size=768*1024(3:4) | size=1024*768(4:3) | size=1024*1024(1:1) |

| 
| 
|
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
prompt = "国漫风格穿越少女,在古代宫廷中烛光照耀下学习礼仪一举一动皆显古风优雅"
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model="wanx2.1-t2i-plus",
prompt=prompt,
n=2,
prompt_extend=True,
size='768*1024')
print('response: %s' % rsp)
if rsp.status_code == HTTPStatus.OK:
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
public class Main {
public static void basicCall() throws ApiException, NoApiKeyException {
String prompt = "国漫风格穿越少女,在古代宫廷中烛光照耀下学习礼仪一举一动皆显古风优雅";
HashMap<String,Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("wanx2.1-t2i-plus")
.prompt(prompt)
.n(2)
.size("768*1024")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args){
try{
basicCall();
}catch(ApiException|NoApiKeyException e){
System.out.println(e.getMessage());
}
}
}
HTTP调用仅支持异步获取模型结果,您需要发起两个请求。
创建任务
此接口返回任务ID,可根据任务ID查询图像生成的结果。
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx2.1-t2i-plus",
"input": {
"prompt": "国漫风格穿越少女,在古代宫廷中烛光照耀下学习礼仪一举一动皆显古风优雅"
},
"parameters": {
"size": "768*1024",
"n": 2,
"prompt_extend": true
}
}'
根据任务ID查询结果
curl -X GET https://dashscope.aliyuncs.com/api/v1/tasks/{your_task_id} \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
注意:需要将{your_task_id}
替换为真实的任务ID。
添加水印
通过watermark
为输出图像添加水印标识,水印位于图片右下角,文案为“AI生成”。默认值为false,表示不添加水印。
下面展示添加水印的效果,模型使用wanx2.1-t2i-turbo
。
watermark=false(不添加水印) | watermark=true(添加水印) |
watermark=false(不添加水印) | watermark=true(添加水印) |

| 
|
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
prompt = "浅水彩,咖啡馆外,明亮的白色背景,梦幻,吉卜力工作室。"
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model="wanx2.1-t2i-turbo",
prompt=prompt,
n=2,
prompt_extend=True,
watermark=True,
size='1024*1024')
print('response: %s' % rsp)
if rsp.status_code == HTTPStatus.OK:
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
public class Main {
public static void basicCall() throws ApiException, NoApiKeyException {
String prompt = "浅水彩,咖啡馆外,明亮的白色背景,梦幻,吉卜力工作室。";
HashMap<String,Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", true);
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("wanx2.1-t2i-turbo")
.prompt(prompt)
.n(1)
.size("1024*1024")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args){
try{
basicCall();
}catch(ApiException|NoApiKeyException e){
System.out.println(e.getMessage());
}
}
}
HTTP调用仅支持异步获取模型结果,您需要发起两个请求。
创建任务
此接口返回任务ID,可根据任务ID查询图像生成的结果。
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx2.1-t2i-turbo",
"input": {
"prompt": "浅水彩,咖啡馆外,明亮的白色背景,梦幻,吉卜力工作室。"
},
"parameters": {
"size": "1024*1024",
"n": 1,
"prompt_extend": true,
"watermark": true
}
}'
根据任务ID查询结果
curl -X GET https://dashscope.aliyuncs.com/api/v1/tasks/{your_task_id} \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
注意:需要将{your_task_id}
替换为真实的任务ID。
关键能力-文生图V1版
通义万相-文生图V1版模型支持:根据输入文本生成图像、根据输入文本和参考图像生成相似图。参数说明请参见通义万相-文生图V1版。
文生图V1版模关键能力包括:
使用反向提示词
通过正向提示词描述期望的图像元素和风格,使用反向提示词来描述不希望在图像中看到的内容。例如,设置negative_prompt
以限制输出图像中不要使用红色元素。
prompt = "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。"
negative_prompt = "红色元素"

from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
prompt = "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。"
negative_prompt = "红色元素"
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model=ImageSynthesis.Models.wanx_v1,
prompt=prompt,
negative_prompt=negative_prompt,
n=1,
style='<auto>',
size='1024*1024')
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
import com.alibaba.dashscope.aigc.imagesynthesis.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
public void syncCall() {
String prompt = "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。";
String negativePrompt = "红色元素";
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model(ImageSynthesis.Models.WANX_V1)
.prompt(prompt)
.negativePrompt(negativePrompt)
.style("<auto>")
.n(1)
.size("1024*1024")
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args){
Main main = new Main();
main.syncCall();
}
}
HTTP调用仅支持异步获取模型结果,您需要发起两个请求。
创建任务
此接口返回任务ID,可根据任务ID查询图像生成的结果。
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx-v1",
"input": {
"prompt": "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。",
"negative_prompt": "红色元素"
},
"parameters": {
"style": "<auto>",
"size": "1024*1024",
"n": 1
}
}'
根据任务ID查询结果
curl -X GET https://dashscope.aliyuncs.com/api/v1/tasks/{your_task_id} \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
基于参考图生成相似图
基于参考图生成图像涉及两个参数:ref_strength
参数和ref_mode
参数。
设置相似度
您可以使用ref_strength
参数来控制输出图像与参考图的相似度。它的取值范围是[0.0, 1.0],默认值为0.5。取值越大表示跟参考图像越相似。

from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
prompt = "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。"
ref_img = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241031/rguyzt/girl.png"
sketch_image_url = './girl.png'
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model=ImageSynthesis.Models.wanx_v1,
prompt=prompt,
n=1,
style='<auto>',
ref_img=ref_img,
ref_mode='repaint',
ref_strength=0.0,
size='1024*1024')
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
import com.alibaba.dashscope.aigc.imagesynthesis.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
public class Main {
public void syncCall() {
String prompt = "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。";
String refImage = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241031/rguyzt/girl.png";
HashMap<String,Object> parameters = new HashMap<>();
parameters.put("ref_strength", 0.0);
parameters.put("ref_mode", "repaint");
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model(ImageSynthesis.Models.WANX_V1)
.prompt(prompt)
.style("<auto>")
.n(1)
.size("1024*1024")
.refImage(refImage)
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args){
Main main = new Main();
main.syncCall();
}
}
HTTP调用仅支持异步获取模型结果,您需要发起两个请求。
1、创建文生图任务
此接口返回任务ID,可根据任务ID查询图像生成的结果。
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx-v1",
"input": {
"prompt": "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。",
"ref_image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241031/rguyzt/girl.png"
},
"parameters": {
"style": "<auto>",
"size": "1024*1024",
"n": 1,
"ref_strength": 0.0,
"ref_mode": "repaint"
}
}'
2、根据任务ID查询结果
curl -X GET https://dashscope.aliyuncs.com/api/v1/tasks/{your_task_id} \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
设置相似图的生成方式
您可以通过ref_mode
参数来控制如何基于参考图像生成相似图。

from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
prompt = "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。"
ref_img = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241031/rguyzt/girl.png"
sketch_image_url = './girl.png'
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model=ImageSynthesis.Models.wanx_v1,
prompt=prompt,
n=4,
style='<auto>',
ref_img=ref_img,
ref_mode='repaint',
ref_strength=1.0,
size='1024*1024')
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
import com.alibaba.dashscope.aigc.imagesynthesis.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
public class Main {
public void syncCall() {
String prompt = "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。";
String refImage = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241031/rguyzt/girl.png";
HashMap<String,Object> parameters = new HashMap<>();
parameters.put("ref_strength", 1.0);
parameters.put("ref_mode", "repaint");
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model(ImageSynthesis.Models.WANX_V1)
.prompt(prompt)
.style("<auto>")
.n(1)
.size("1024*1024")
.refImage(refImage)
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args){
Main main = new Main();
main.syncCall();
}
}
HTTP调用仅支持异步获取模型结果,您需要发起两个请求。
创建任务
此接口返回任务ID,可根据任务ID查询图像生成的结果。
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "wanx-v1",
"input": {
"prompt": "近景镜头,18岁的中国女孩,古代服饰,圆脸,正面看着镜头,民族优雅的服装,商业摄影,室外,电影级光照,半身特写,精致的淡妆,锐利的边缘。",
"ref_image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241031/rguyzt/girl.png"
},
"parameters": {
"style": "<auto>",
"size": "1024*1024",
"n": 1,
"ref_strength": 1.0,
"ref_mode": "repaint"
}
}'
2、根据任务ID查询结果
curl -X GET https://dashscope.aliyuncs.com/api/v1/tasks/{your_task_id} \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \