wanx-style-repaint-v1 模型支持两种风格重绘模式:选择预置风格(style_index 0-6)或上传风格参考图自定义风格(style_index=-1)。
模型概览
| 模型名称 | 计费单价 | QPS 限制 | 同时处理任务数 | 免费额度 |
|---|
| wanx-style-repaint-v1 | 0.12 元/张 | 2 | 1 | 500 张 |
预置风格效果示例:
快速开始
该 API 仅支持 HTTP 调用,采用异步模式:提交任务(POST)→ 轮询结果(GET)。
提交任务
以预置风格为例,设置 style_index 选择风格:
curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "wanx-style-repaint-v1",
"input": {
"image_url": "https://vigen-video.oss-cn-shanghai.aliyuncs.com/demo_image/image_demo_input.png",
"style_index": 3
}
}'
响应示例:
{
"output": {
"task_status": "PENDING",
"task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
},
"request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
查询结果
用返回的 task_id 轮询任务状态:
curl -X GET 'https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
任务完成后,results 中包含生成图像的 URL(有效期 24 小时):
{
"output": {
"task_id": "316c7af0-e91f-476f-99bd-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{"url": "http://oss.aliyuncs.com/xxx/abc.jpg"}
]
},
"usage": {"image_count": 1}
}
自定义风格重绘
上传风格参考图(style_ref_url),设置 style_index=-1,模型将以参考图的风格重绘人像。
提交任务时使用以下 curl 命令(设置 style_ref_url 并将 style_index 设为 -1):
curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "wanx-style-repaint-v1",
"input": {
"image_url": "https://vigen-video.oss-cn-shanghai.aliyuncs.com/demo_image/input_example.png",
"style_ref_url": "https://vigen-video.oss-cn-shanghai.aliyuncs.com/demo_image/style_example.png",
"style_index": -1
}
}'
查询结果的方式与预置风格相同。
Python 示例
import os
import requests
import time
from http import HTTPStatus
api_key = os.getenv("DASHSCOPE_API_KEY")
if not api_key:
raise ValueError("请设置环境变量 DASHSCOPE_API_KEY")
def submit_task():
url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
"X-DashScope-Async": "enable"
}
# --- 预置风格 ---
body = {
"model": "wanx-style-repaint-v1",
"input": {
"image_url": "https://vigen-video.oss-cn-shanghai.aliyuncs.com/demo_image/image_demo_input.png",
"style_index": 3 # <-- 预置风格编号,参见预置风格列表
}
}
# --- 自定义风格(取消注释以使用) ---
# body = {
# "model": "wanx-style-repaint-v1",
# "input": {
# "image_url": "https://vigen-video.oss-cn-shanghai.aliyuncs.com/demo_image/input_example.png",
# "style_ref_url": "https://vigen-video.oss-cn-shanghai.aliyuncs.com/demo_image/style_example.png",
# "style_index": -1 # <-- 自定义风格标识
# }
# }
response = requests.post(url, headers=headers, json=body)
if response.status_code == HTTPStatus.OK:
task_id = response.json().get('output', {}).get('task_id')
print(f"任务提交成功,任务ID为: {task_id}")
return task_id
else:
print(f"任务提交失败,状态码: {response.status_code}")
return None
def query_task_result(task_id):
if not task_id:
return
url = f"https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}"
headers = {"Authorization": f"Bearer {api_key}"}
while True:
response = requests.get(url, headers=headers)
if response.status_code != HTTPStatus.OK:
print(f"查询失败,状态码: {response.status_code}")
break
data = response.json()
status = data.get('output', {}).get('task_status')
if status == 'SUCCEEDED':
results = data.get('output', {}).get('results', [])
for i, result in enumerate(results):
print(f"生成图片_{i + 1} URL: {result.get('url')}")
break
elif status == 'FAILED':
print(f"任务失败: {data}")
break
else:
print(f"任务处理中,状态: {status}...")
time.sleep(5)
if __name__ == '__main__':
task_id = submit_task()
if task_id:
query_task_result(task_id)
预置风格列表
style_index | 风格名称 |
|---|
| 0 | 复古漫画 |
| 1 | 3D童话 |
| 2 | 二次元 |
| 3 | 小清新 |
| 4 | 未来科技 |
| 5 | 国画古风 |
| 6 | 将军百战 |
输入图像要求
人物图像
- 分辨率:最小 256x256,最大 5760x3240,宽高比不超过 2:1
- 质量:人脸清晰、光线充足,避免夸张姿势和表情
- 格式:JPEG、PNG、JPG、BMP、WEBP
- 大小:不超过 10MB
- 传入方式:HTTP/HTTPS URL(不含中文字符)或 Base64 编码
风格参考图(自定义风格)
- 分辨率:最小 256x256,最大 5760x3240,建议宽高比不超过 2:1
- 格式:JPEG、PNG、JPG、BMP、WEBP
- 大小:不超过 10MB
- 传入方式:HTTP/HTTPS URL(不含中文字符)或 Base64 编码
格式为 data:{MIME_type};base64,{base64_data},支持的 MIME 类型:| 格式 | MIME 类型 |
|---|
| JPEG/JPG | image/jpeg |
| PNG | image/png |
| BMP | image/bmp |
| WEBP | image/webp |
Python 编码示例:import base64
import mimetypes
def encode_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
if not mime_type or not mime_type.startswith("image/"):
raise ValueError("不支持或无法识别的图像格式")
with open(file_path, "rb") as f:
encoded = base64.b64encode(f.read()).decode('utf-8')
return f"data:{mime_type};base64,{encoded}"
print(encode_file("./image_demo_input.png"))
注意事项
- 计费:0.12 元/张,提供 500 张免费额度。调用失败不计费
- 并发限制:QPS 为 2,同时进行的任务数为 1。详见并发与配额
常见问题
- 使用高质量的人像照片:人脸清晰、光线充足、避免遮挡
- 自定义风格时,选择风格特征明显的参考图
不可以。两种模式互斥:使用预置风格时设置 style_index 为 0-6;使用自定义风格时需提供 style_ref_url 并设置 style_index=-1。若同时传入且未将 style_index 设为 -1,系统可能默认采用预置风格,导致自定义风格不生效。
不一致。输出图像的短边固定为 1536px,长边按原始宽高比等比缩放。