The Wan image generation model supports image editing and image-text mixed output, meeting diverse generation and integration needs.
Model Overview
Model | Model Description | Output Image Specifications |
|---|---|---|
wan2.6-image | Wan2.6 image Supports image editing and image-text mixed output For pure text-based image generation (text-to-image), we recommend using the wan2.6-t2i model (Wan-Text-to-Image V2). | Image Format: PNG. For image resolution and dimensions, see the size parameter. |
NoteBefore making calls, check the model list and prices supported in each region.
Prerequisites
You must have obtained and configured an API Key and configured the API Key in environment variables. Replace DASHSCOPE_API_HOST in the sample code with your obtained API Host.
ImportantThe Singapore, United States (Virginia), and North China 2 (Beijing) regions each have their own API Key and request address, which cannot be mixed. Cross-region calls will result in authentication failure or service errors. For details, see Select a region, service deployment scope, and endpoint.
ImportantAlibaba Cloud Model Studio has launched workspace-dedicated domains for the North China 2 (Beijing) and Singapore regions, which deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
- North China 2 (Beijing) region: migrate from
https://dashscope.aliyuncs.comtohttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com - Singapore region: migrate from
https://dashscope-intl.aliyuncs.comtohttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which you can view on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domains remain available.
HTTP Synchronous Call
A single request returns the result, making the workflow simple. Recommended for most scenarios.
Singapore
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
When calling, replace {WorkspaceId} with your actual Workspace ID.
United States (Virginia)
POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
North China 2 (Beijing)
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
When calling, replace {WorkspaceId} with your actual Workspace ID.
dashscope CLI
Call via the dashscope command line.
export DASHSCOPE_API_KEY="your-api-key"
# 将 {WorkspaceId} 替换为业务空间ID,ap-southeast-1 替换为对应地域(美东: us-east-1, 德国: eu-central-1)
export DASHSCOPE_HTTP_BASE_URL="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"
dashscope image-generation create -m wan2.6-t2i -t "一只可爱的猫"
ImportantThe SDK Expert interactive assistant can accomplish the same development and troubleshooting tasks using natural language. See
DashScope SDK Expert.For the complete list of regions, see Base URL Overview.
The global deployment scope (Frankfurt region) only supports asynchronous calls.
Request ParametersRequest HeadersContent-Type The request content type. This parameter must be set to Authorization Request authentication. The interface uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx. X-DashScope-Sse Used to enable streaming output.
Request Bodymodel The model name. Set it to wan2.6-image. input The basic information of the input. parameters Image processing parameters. | Image editingInterleaved text and images (streaming only)When the synchronous interface enables interleaved text and image output (that is,
|
Response parametersoutput Task output information. usage Output information statistics. Only successful results are counted. request_id Unique request identifier. It can be used for request detail tracing and troubleshooting. code Error code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error code. message Detailed information about the request failure. This parameter is not returned when the request succeeds. For details, see Error code. | Task executed successfullyTask data (such as task status and image URLs) is retained for only 24 hours and is automatically cleared after expiration. Be sure to save the generated images in a timely manner. Task executed successfully (streaming output)Task data (such as task status and image URLs) is retained for only 24 hours and is automatically cleared after expiration. Be sure to save the generated images in a timely manner. Task execution exceptionIf the task fails for some reason, the relevant information will be returned, and the cause of the error is clearly indicated by the code and message fields. See Error codes to resolve the issue. |
HTTP asynchronous call
The workflow consists of two core steps, “Create task -> Poll for results”, as detailed below:
Step 1: Create a task to obtain the task ID
Singapore
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation
When calling, replace {WorkspaceId} with your actual Workspace ID.
United States (Virginia)
POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation
North China 2 (Beijing)
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation
When calling, replace {WorkspaceId} with your actual Workspace ID.
Germany (Frankfurt)
POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation
When calling, replace {WorkspaceId} with your actual Workspace ID.
Note
- After the task is created successfully, use the
task_idreturned by the API to query the result. The task_id is valid for 24 hours. Do not create the task repeatedly; poll to obtain the result instead. - For beginner guidance, see Postman.
Request parametersRequest headersContent-Type The request content type. This parameter must be set to Authorization Request authentication. The interface uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx. X-DashScope-Async The asynchronous processing configuration parameter, which must be set to ImportantIf this request header is missing, the following error occurs: “current user api does not support synchronous calls”. Request bodymodel The model name. Example value: wan2.6-image input The basic information of the input. parameters Image processing parameters. | |
Response parametersoutput Task output information. request_id Unique request identifier. It can be used for request detail tracing and troubleshooting. code Error code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error code. message Detailed information about the request failure. This parameter is not returned when the request succeeds. For details, see Error code. | Successful responseSave the task_id, which is used to query the task status and results. Error responseFailed to create the task. See Error codes to resolve the issue. |
Step 2: Query the result based on the task ID
Singapore
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
When calling, replace {WorkspaceId} with your actual Workspace ID.
United States (Virginia)
GET https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
North China 2 (Beijing)
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
When calling, replace {WorkspaceId} with your actual Workspace ID.
Germany (Frankfurt)
GET https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
When calling, replace {WorkspaceId} with your actual Workspace ID.
Note
- Polling recommendations: Image generation is time-consuming. We recommend using a polling mechanism and setting a reasonable query interval (for example, 10 seconds) to obtain the results.
- Task status transitions: PENDING (Queuing) → RUNNING (Processing) → SUCCEEDED (Success) / FAILED (Failed).
- Result links: After the task succeeds, an image URL is returned and remains valid for 24 hours. We recommend that you download the image immediately after obtaining the URL and transfer it to permanent storage (such as Alibaba Cloud OSS).
Request parametersRequest headersAuthorization Request authentication. The interface uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx. URL path parameterstask_id Task ID. | Query task resultsReplace |
Response parametersoutput Task output information. usage Output information statistics. Only successful results are counted. request_id Unique request identifier. It can be used for request detail tracing and troubleshooting. code Error code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error code. message Detailed information about the request failure. This parameter is not returned when the request succeeds. For details, see Error code. | Task executed successfullyTask data (such as task status and image URLs) is retained for only 24 hours and is automatically cleared after expiration. Be sure to save the generated images in a timely manner. Task execution exceptionIf the task fails for some reason, the relevant information will be returned, and the cause of the error is clearly indicated by the code and message fields. See Error codes to resolve the issue. |
Call the DashScope Python SDK
The SDK parameter naming is basically the same as that of the HTTP API, and the parameter structure is encapsulated based on language characteristics.
Since tasks take a long time to complete, the SDK encapsulates the HTTP asynchronous call process at the underlying layer and supports both synchronous and asynchronous call methods.
The actual time required depends on the number of queuing tasks and service execution conditions. Please wait patiently when obtaining the results.
ImportantMake sure that the DashScope Python SDK version is no earlier than 2.1.0 before running the following code. For updates, see Install the SDK.
The base_url and API Key of each region are not universal. The following example uses the Singapore region as an example to make the call:
Singapore
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1
When calling, replace {WorkspaceId} with your actual Workspace ID.
United States (Virginia)
https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1
North China 2 (Beijing)
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1
When calling, replace {WorkspaceId} with your actual Workspace ID.
Germany (Frankfurt)
https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1
When calling, replace {WorkspaceId} with your actual Workspace ID.
The global deployment (Frankfurt region) only supports asynchronous calls.
Image editing
Synchronous call
Request example
import os
import dashscope
# 以下为新加坡地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
print("----sync call, please wait a moment----")
job = client.images.generate(
model='wan2.6-image',
prompt="参考图1的风格和图2的背景,生成番茄炒蛋",
# 参考图列表,支持本地文件 如 "file://umbrella1.png"
image_urls=[
"https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png",
"https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"
],
negative_prompt="",
prompt_extend=True,
watermark=False,
n=1,
parameters={"enable_interleave": False},
size="1K"
)
print(job)
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{
"status_code": 200,
"request_id": "b6a4c68d-3a91-4018-ae96-3cf373xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"audio": null,
"finished": true
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"characters": 0,
"image_count": 1,
"size": "1376*768",
"total_tokens": 0
}
}
Asynchronous call
Request example
import os
import dashscope
from dashscope import DashScopeError
# 以下为新加坡地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
# 创建异步任务
def create_async_task():
print("Creating async task...")
job = client.images.jobs.create(
model="wan2.6-image",
prompt='参考图1的风格和图2的背景,生成番茄炒蛋',
# 参考图列表,支持本地文件 如 "file://umbrella1.png"
image_urls=[
'https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png',
'https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp'
],
negative_prompt="",
prompt_extend=True,
watermark=False,
n=1,
parameters={"enable_interleave": False},
size="1K"
)
print("Task created successfully:", job)
return job # 返回任务
# 等待任务完成
def wait_for_completion(task_response):
print("Waiting for task completion...")
done = client.images.jobs.wait(task_response)
if done.succeeded:
print("Task succeeded!")
print("Response:", done)
else:
raise Exception(f"Task failed with status: {done.status}")
# 获取异步任务信息
def fetch_task_status(task_id):
print("Fetching task status...")
snapshot = client.images.jobs.fetch(task_id)
print("Task status:", snapshot.status)
print("Response details:", snapshot)
# 取消异步任务
def cancel_task(task_id):
print("Canceling task...")
response = client.images.jobs.cancel(task_id)
print("Task canceled successfully:", response.status)
# 主执行流程
if __name__ == "__main__":
try:
task = create_async_task()
wait_for_completion(task)
except DashScopeError as e:
print(f"HTTP返回码:{e.status_code}")
print(f"错误码:{e.code}")
print(f"错误信息:{e.message}")
print("请参考文档:https://www.alibabacloud.com/help/model-studio/error-code")
Response example
- Response example of creating a task
{
"status_code": 200,
"request_id": "4fb3050f-de57-4a24-84ff-e37ee5xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": null,
"audio": null,
"task_id": "127ec645-118f-4884-955d-0eba8dxxxxxx",
"task_status": "PENDING"
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"characters": 0
}
}
- Response example of querying task results
The url is valid for 24 hours. Download the image in a timely manner.
{
"status_code": 200,
"request_id": "b2a7fab4-5e00-4b0a-86fe-8b9964xxxxxx",
"code": null,
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
"type": "image"
}
]
}
}
],
"audio": null,
"task_id": "127ec645-118f-4884-955d-0eba8xxxxxx",
"task_status": "SUCCEEDED",
"submit_time": "2026-01-09 17:52:04.136",
"scheduled_time": "2026-01-09 17:52:04.164",
"end_time": "2026-01-09 17:52:25.408",
"finished": true
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"characters": 0,
"size": "1376*768",
"total_tokens": 0,
"image_count": 1
}
}
Image and text mixed output
Synchronous call (streaming only)
Request example
import os
import dashscope
# 以下为新加坡地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
def sync_call_with_stream():
print("\n========== 同步调用 - 流式图文输出 ==========")
stream = client.multimodal.chat.create(
model="wan2.6-image",
messages=[
{
"role": "user",
"content": [
{"text": "给我一个3张图辣椒炒肉教程"}
],
}
],
stream=True, # 仅支持流式调用
# 注意:必须显式传 parameters.stream=True(stream=True 不会自动落到 wire 层),
# 否则服务端会报错 "stream=False is not supported"
parameters={
"stream": True,
"negative_prompt": "",
"enable_interleave": True, # 开启图文混排输出
"max_images": 3,
"size": "1280*1280",
},
)
print("流式输出结果:")
for chunk in stream:
if not chunk.choices:
continue
delta = chunk.choices[0].delta
# 文本增量输出
if delta.content:
print(delta.content, end="")
# 图像增量输出:content_parts 携带含图片URL的 image part
for part in delta.content_parts or []:
if part.get("type") == "image":
print(f"\n[图片] {part['image']}")
if __name__ == "__main__":
sync_call_with_stream()
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "辣椒"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 0, "characters": 0, "total_tokens": 28, "image_count": 0, "size": "0*0"}}
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "炒"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 1, "characters": 0, "total_tokens": 29, "image_count": 0, "size": "0*0"}}
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "肉"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 2, "characters": 0, "total_tokens": 30, "image_count": 0, "size": "0*0"}}
......
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "null", "message": {"role": "assistant", "content": [{"type": "text", "text": "。"}]}}], "audio": null, "finished": false}, "usage": {"input_tokens": 28, "output_tokens": 398, "characters": 0, "total_tokens": 426, "image_count": 2, "size": "1280*1280"}}
{"status_code": 200, "request_id": "5b98e8f3-aeff-4c20-a26c-499a7525axxx", "code": "", "message": "", "output": {"text": null, "finish_reason": null, "choices": [{"finish_reason": "stop", "message": {"role": "assistant", "content": [{"type": "image", "image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}], "audio": null, "finished": true}, "usage": {"input_tokens": 28, "output_tokens": 523, "characters": 0, "total_tokens": 551, "image_count": 3, "size": "1280*1280"}}
Asynchronous call
Request example
Note: For asynchronous calls, you do not need to set the stream parameter.
import os
import dashscope
from dashscope import DashScopeError
# 以下为新加坡地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="ap-southeast-1",
)
def main():
"""异步调用 - 图文输出"""
print("========== wan2.6-image 异步调用 - 图文输出 ==========")
# 创建异步任务
print("---async call, creating task----")
job = client.images.jobs.create(
model="wan2.6-image",
prompt="给我一个3张图的辣椒炒肉教程",
# 异步调用不需要设置stream参数
negative_prompt="",
parameters={"enable_interleave": True, "max_images": 3},
size="1280*1280"
)
print(f"任务创建成功:")
print(job)
# 等待任务完成
print("\n---waiting for task completion----")
done = client.images.jobs.wait(job)
if done.succeeded:
print("任务完成!")
print(f"结果:")
print(f"图片URL: {done.image_urls}")
else:
print(f"任务失败,状态: {done.status}")
if __name__ == "__main__":
try:
main()
except DashScopeError as e:
print(f"HTTP返回码:{e.status_code}")
print(f"错误码:{e.code}")
print(f"错误信息:{e.message}")
print("请参考文档:https://www.alibabacloud.com/help/model-studio/error-code")
Response example
- Response example of creating a task
{
"status_code": 200,
"request_id": "4fb3050f-de57-4a24-84ff-e37ee5xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": null,
"audio": null,
"task_id": "5c67585e-a3be-4943-b04d-c3fbb2xxxxxx",
"task_status": "PENDING"
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"characters": 0
}
}
- Response example of querying task results
The url is valid for 24 hours. Download the image in a timely manner.
{
"status_code": 200,
"request_id": "997a759b-fbb9-4b35-9a4d-6dab1xxxxxx",
"code": null,
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"text": "辣椒炒肉是湘菜中的经典,也是许多人心中的家常美味。它以鲜辣爽口、肉质鲜嫩而闻名,制作过程简单,却能带来极致的味蕾享受。今天,我们就来一起学习这道菜的制作方法。\n\n首先,准备好所有食材是成功的第一步。新鲜的猪肉、红绿辣椒、蒜瓣和姜片是必不可少的。将猪肉切成薄片,辣椒切段,蒜和姜切片备用。",
"type": "text"
},
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
},
{
"text": "接下来是炒制的关键环节。热锅凉油,放入蒜片和姜片爆香,接着倒入切好的肉片,快速翻炒至肉片变色。肉片炒香后,加入切好的辣椒段,继续翻炒,让辣椒的香气充分释放出来,与肉片的鲜美完美融合。",
"type": "text"
},
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
},
{
"text": "最后,加入适量的生抽、老抽、蚝油和少许糖调味,快速翻炒均匀,让每一片肉和辣椒都裹上酱汁。待汤汁收浓,即可关火出锅。这道色香味俱全的辣椒炒肉就大功告成了!",
"type": "text"
},
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
]
}
}
],
"audio": null,
"task_id": "5c67585e-a3be-4943-b04d-c3fbb2xxxxxx",
"task_status": "SUCCEEDED",
"submit_time": "2026-01-16 17:47:39.469",
"scheduled_time": "2026-01-16 17:47:39.804",
"end_time": "2026-01-16 17:49:46.736",
"finished": true
},
"usage": {
"input_tokens": 29,
"output_tokens": 477,
"characters": 0,
"size": "1280*1280",
"total_tokens": 506,
"image_count": 3
}
}
Call through the DashScope Java SDK
The SDK parameter naming is basically the same as that of the HTTP API, and the parameter structure is encapsulated based on language characteristics.
Since tasks take a long time to complete, the SDK encapsulates the HTTP asynchronous call process at the underlying layer and supports both synchronous and asynchronous call methods.
The actual time required depends on the number of queuing tasks and service execution conditions. Please wait patiently when obtaining the results.
ImportantBefore running the following code, make sure the DashScope Java SDK version is no earlier than 2.22.6.
The base_url and API Key of each region are not universal. The following example uses the Singapore region as an example to make the call:
Singapore
https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1
When calling, replace {WorkspaceId} with your actual Workspace ID.
United States (Virginia)
https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1
North China 2 (Beijing)
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1
When calling, replace {WorkspaceId} with your actual Workspace ID.
Germany (Frankfurt)
https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1
When calling, replace {WorkspaceId} with your actual Workspace ID.
The global deployment (Frankfurt region) only supports asynchronous calls.
Image Editing
Synchronous call
Request example
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.Arrays;
import java.util.Collections;
/**
* wan2.6-image 图像编辑 - 同步调用示例
*/
public class Main {
static {
// 以下为新加坡地域URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void basicCall() throws ApiException, NoApiKeyException, UploadFileException {
// 构建多图输入消息
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Arrays.asList(
// 支持多图输入,可以提供多张参考图片
Collections.singletonMap("text", "参考图1的风格和图2的背景,生成番茄炒蛋"),
Collections.singletonMap("image", "https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png"),
Collections.singletonMap("image", "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp")
)).build();
// 图像编辑使用普通同步调用,不需要设置stream和enable_interleave
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.6-image")
.messages(Collections.singletonList(message))
.n(1)
.size("1K")
.negativePrompt("")
.promptExtend(true)
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---sync call for image editing, please wait a moment----");
result = imageGeneration.call(param);
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
basicCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
}
}
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{
"requestId": "b148327e-830f-414c-a8df-724dec28exxx",
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"total_tokens": 0,
"image_count": 1,
"size": "1376*768"
},
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
]
}
}
],
"finished": true
},
"status_code": 200,
"code": "",
"message": ""
}
Asynchronous call
Request example
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.Arrays;
import java.util.Collections;
/**
* wan2.6-image 图像编辑 - 异步调用示例
*/
public class Main {
static {
// 以下为新加坡地域URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void asyncCall() throws ApiException, NoApiKeyException, UploadFileException {
// 构建多图输入消息
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Arrays.asList(
// 支持多图输入,可以提供多张参考图片
Collections.singletonMap("text", "参考图1的风格和图2的背景,生成番茄炒蛋"),
Collections.singletonMap("image", "https://cdn.wanx.aliyuncs.com/tmp/pressure/umbrella1.png"),
Collections.singletonMap("image", "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp")
)).build();
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.6-image")
.n(1)
.size("1K")
.negativePrompt("")
.promptExtend(true)
.messages(Arrays.asList(message))
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---async call for image editing, creating task----");
result = imageGeneration.asyncCall(param);
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
System.out.println("任务创建结果:");
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
// 等待任务完成
waitTask(taskId);
}
public static void waitTask(String taskId) throws ApiException, NoApiKeyException {
ImageGeneration imageGeneration = new ImageGeneration();
System.out.println("\n---waiting for task completion----");
ImageGenerationResult result = imageGeneration.wait(taskId, apiKey);
System.out.println("任务完成结果:");
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
asyncCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
}
}
Response example
- Response example of creating a task
{
"status_code": 200,
"request_id": "9cd85950-2e26-4b2c-b562-1694cf928xxx",
"code": "",
"message": "",
"output": {
"task_id": "4c861fbe-af89-4a2f-8fc5-4bb15c313xxx",
"task_status": "PENDING"
},
"usage": null
}
- Response example of querying task results
The url is valid for 24 hours. Download the image in a timely manner.
{
"status_code": 200,
"request_id": "cbdf1424-306e-4a52-82f3-8bf5d8a99xxx",
"code": "",
"message": "",
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
]
}
}
],
"task_id": "4c861fbe-af89-4a2f-8fc5-4bb15c3139ba",
"task_status": "SUCCEEDED",
"submit_time": "2026-01-16 16:36:06.556",
"scheduled_time": "2026-01-16 16:36:06.591",
"end_time": "2026-01-16 16:36:25.190",
"finished": true
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"size": "1376*768",
"total_tokens": 0,
"image_count": 1
}
}
Image and text mixed output
Synchronous call (streaming only)
Request example
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import io.reactivex.Flowable;
import java.util.Collections;
/**
* wan2.6-image 图文输出 - 流式调用示例
*/
public class Main {
static {
// 以下为新加坡地域URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void streamCall() throws ApiException, NoApiKeyException, UploadFileException {
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Collections.singletonList(
Collections.singletonMap("text", "给我一个3张图辣椒炒肉教程")
)).build();
// 图文输出必须使用流式调用
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.6-image")
.messages(Collections.singletonList(message))
.stream(true) // 必须开启流式输出
.enableInterleave(true)
.size("1280*1280")
.negativePrompt("")
.maxImages(3)
.build();
ImageGeneration imageGeneration = new ImageGeneration();
try {
System.out.println("---stream call for image interleave----");
Flowable<ImageGenerationResult> resultFlowable = imageGeneration.streamCall(param);
resultFlowable.blockingForEach(result -> {
System.out.println(JsonUtils.toJson(result));
});
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
}
public static void main(String[] args) {
try {
streamCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
Response example
The url is valid for 24 hours. Download the image in a timely manner.
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":0,"total_tokens":28,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"辣椒"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":1,"total_tokens":29,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"炒"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":2,"total_tokens":30,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"肉"}]}}],"finished":false},"status_code":200,"code":"","message":""}
......
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":73,"total_tokens":101,"image_count":0,"size":"0*0"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"。"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":198,"total_tokens":226,"image_count":1,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"image","image":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":199,"total_tokens":227,"image_count":1,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"接下来"}]}}],"finished":false},"status_code":200,"code":"","message":""}
......
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":245,"total_tokens":273,"image_count":1,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"。"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":368,"total_tokens":396,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"image","image":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":369,"total_tokens":397,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"最后"}]}}],"finished":false},"status_code":200,"code":"","message":""}
......
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":416,"total_tokens":444,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"锅"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":417,"total_tokens":445,"image_count":2,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"type":"text","text":"。"}]}}],"finished":false},"status_code":200,"code":"","message":""}
{"requestId":"12c7432c-8028-4289-a97c-4e22df98bxxx","usage":{"input_tokens":28,"output_tokens":541,"total_tokens":569,"image_count":3,"size":"1280*1280"},"output":{"choices":[{"finish_reason":"stop","message":{"role":"assistant","content":[{"type":"image","image":"https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"}]}}],"finished":true},"status_code":200,"code":"","message":""}
Asynchronous call
Request example
Note: For asynchronous calls, you do not need to set the stream parameter.
import com.alibaba.dashscope.aigc.imagegeneration.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.Collections;
/**
* wan2.6-image 图文输出 - 异步调用示例
*/
public class Main {
static {
// 以下为新加坡地域URL,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
}
// 若没有配置环境变量,请用百炼API Key将下行替换为:apiKey="sk-xxx"
// 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void asyncCall() throws ApiException, NoApiKeyException, UploadFileException {
ImageGenerationMessage message = ImageGenerationMessage.builder()
.role("user")
.content(Collections.singletonList(
Collections.singletonMap("text", "给我一个3张图的辣椒炒肉教程")
)).build();
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.6-image")
.size("1280*1280")
.enableInterleave(true)
.maxImages(3)
.negativePrompt("")
.messages(Collections.singletonList(message))
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---async call for image interleave, creating task----");
result = imageGeneration.asyncCall(param);
} catch (ApiException | NoApiKeyException | UploadFileException e) {
throw new RuntimeException(e.getMessage());
}
System.out.println("任务创建结果:");
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
// 等待任务完成
waitTask(taskId);
}
public static void waitTask(String taskId) throws ApiException, NoApiKeyException {
ImageGeneration imageGeneration = new ImageGeneration();
System.out.println("\n---waiting for task completion----");
ImageGenerationResult result = imageGeneration.wait(taskId, apiKey);
System.out.println("任务完成结果:");
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
asyncCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
}
}
Response example
- Response example of creating a task
{
"requestId": "7d6c5760-334b-48c4-9b1e-08ee9c7fexxx",
"output": {
"task_id": "1bb9d9fa-bf1a-43dc-b5fe-366c1dc70xxx",
"task_status": "PENDING"
},
"status_code": 200,
"code": "",
"message": ""
}
- Response example of querying task results
The url is valid for 24 hours. Download the image in a timely manner.
{
"requestId": "6ed62b00-2225-4fc3-8ee3-2aed0b484xxx",
"usage": {
"input_tokens": 29,
"output_tokens": 471,
"total_tokens": 500,
"image_count": 3,
"size": "1280*1280"
},
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"text": "辣椒炒肉是湘菜中的经典,也是许多人心中的家常美味。它以鲜辣爽口、肉质鲜嫩而闻名,制作过程简单,却能带来极致的味蕾享受。今天,我们就来一起学习这道菜的制作方法。\n\n首先,准备好所有食材是成功的第一步。新鲜的猪肉、红绿辣椒、蒜瓣和姜片是必不可少的。将猪肉切成薄片,辣椒切段,蒜和姜切片备用。",
"type": "text"
},
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
},
{
"text": "接下来是腌制猪肉。将切好的猪肉片放入碗中,加入少许生抽、料酒、淀粉和食用油,用手抓匀,腌制10-15分钟。这样处理过的肉片会更加滑嫩入味。",
"type": "text"
},
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
},
{
"text": "最后,热锅凉油,放入腌制好的肉片快速滑炒至变色,盛出备用。锅中留底油,放入蒜片和姜片爆香,再加入辣椒段翻炒出香味。随后倒入肉片,加入生抽、老抽、少许糖和蚝油,快速翻炒均匀,撒上葱花即可出锅。",
"type": "text"
},
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx",
"type": "image"
}
]
}
}
],
"task_id": "1bb9d9fa-bf1a-43dc-b5fe-366c1dc70836",
"task_status": "SUCCEEDED",
"finished": true,
"submit_time": "2026-01-16 18:26:32.082",
"scheduled_time": "2026-01-16 18:26:32.133",
"end_time": "2026-01-16 18:28:41.748"
},
"status_code": 200,
"code": "",
"message": ""
}
Limits
- Data validity: The task
task_idand the imageurlare retained for only 24 hours and can no longer be queried or downloaded after expiration. - Content moderation: Both the input
promptand the output images go through content safety review; requests containing non-compliant content will return the "IPInfringementSuspect" or "DataInspectionFailed" error. For more information, see Error codes.
Billing and rate limiting
- For the model free quota and billing unit price, see Model Price.
- For model rate limits, see Wan.
- Billing details: You are billed based on the number of images successfully generated. Failed model calls or processing errors incur no charges and do not consume the free quota for new users.
Error codes
If a model call fails and returns an error message, see Error codes to resolve the issue.
FAQ
Q: Why does the code example fail to run?A: Upgrade your SDK to the latest version. For update instructions, see Install the SDK.