This topic describes the input and output parameters of the Wan Text-to-image V2 model.
Model overview
Performance showcase
You can experience the text-to-image effects on the Wan official website.
The features on the Wan official website may differ from the capabilities supported by the API. For specific capabilities, refer to those listed in this API reference. This topic will be updated promptly when new features are added.
Model introduction
Version | Name | Description |
Wan Text-to-image 2.1 | wan2.1-t2i-turbo | Faster generation speed, general-purpose model. |
wan2.1-t2i-plus | Richer details in generated images, slightly slower speed, general-purpose model. |
Name | Unit price | Rate limits (shared between Alibaba Cloud account and RAM users) | Free quota | |
Requests per second (RPS) for task submission | Number of concurrent tasks | |||
wan2.1-t2i-turbo | $0.025/image | 2 | 2 | Free quota: 200 images each Validity period: 180 days after activation of Alibaba Cloud Model Studio |
wan2.1-t2i-plus | $0.05/image | 2 | 2 |
For more information, see Billing and rate limiting.
Prerequisites
The Text-to-image V2 API supports calls through HTTP and DashScope SDK.
Before you make a call, you must first obtain an API key and set the API key as an environment variable.
If you need to use SDK, you must install the SDK for Python or Java.
HTTP calls
Image model processing takes a long time. To avoid request timeouts, HTTP calls only support asynchronous retrieval of results. You need to make two requests:
Create task: Send a request to create a task, which will return a task ID.
Query results using the ID: Use the task ID to query the task status and the results. If successful, an image URL will be returned, which is valid for 24 hours.
After you create a task, it will be added to a queue. Later, call the query interface to get the task status and results based on the task ID.
Text-to-image generation takes approximately 1-3 minutes. The specific time depends on the number of queued tasks and service execution conditions. Please be patient when retrieving results.
Step 1: Create task
POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis
Request parameters | Text-to-imagePositive promptGenerate an image based on the prompt.
Positive + negative promptGenerate an image based on the prompt, avoiding "people" elements in the generated image.
|
Headers | |
Content-Type The type of the request content. This parameter must be set to | |
Authorization The identity authentication for the request, which is the Model Studio API key. Example: Bearer d1xxx2a. | |
X-DashScope-Async The asynchronous processing parameter. HTTP requests only support asynchronous mode, so this parameter must be set to | |
Request body | |
model The model name. Example: wan2.1-t2i-turbo. | |
input Basic input information, such as prompts. | |
parameters The image processing parameters. |
Response parameters | Successful response
Error response
|
output The task output information. | |
request_id The request ID. It can be used for tracing and troubleshooting. | |
code The error code for a failed request. This parameter is not returned when the request is successful. | |
message The error message for a failed request. This parameter is not returned when the request is successful. |
Step 2: Query results by task ID
GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
Request parameters | Query task resultsReplace
|
Headers | |
Authorization The identity authentication for the request, which is the Model Studio API key. Example: Bearer d1xxx2a. | |
Path parameters | |
task_id The task ID. |
Response parameters | Task succeededTask data (such as task status and image URLs) is only retained for 24 hours and will be automatically deleted. Save the generated images promptly.
Task failedIf the task fails for some reason, the task status will be set to FAILED, and the code and message fields will show the reason.
Task partially failedThe model can generate multiple images in a single task. As long as one of the images is generated successfully, the task status will be marked as
|
output The task output information. | |
usage The output statistics. Only counts successful results. | |
request_id The request ID. It can be used for tracing and troubleshooting. |
DashScope SDK
Make sure you have installed the latest version of the DashScope SDK to avoid errors: Install SDK.
DashScope SDK currently supports Python and Java.
The parameter names in the SDK are basically the same as the HTTP interface. The parameter structure depends on the SDK encapsulation of different languages. For parameter descriptions, refer to HTTP calls.
Because image model processing takes a long time, the underlying service uses an asynchronous approach. The SDK provides encapsulation at the upper layer and supports both synchronous and asynchronous calling methods.
Text-to-image generation takes approximately 1-3 minutes. The specific time depends on the number of queued tasks and service execution conditions. Please be patient when retrieving results.
Python SDK
Synchronous
Sample request
Text-to-image
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
prompt = "A flower shop with exquisite windows, beautiful wooden doors, displaying flowers"
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model="wan2.1-t2i-turbo",
prompt=prompt,
n=1,
size='1024*1024')
print('response: %s' % rsp)
if rsp.status_code == HTTPStatus.OK:
# Save images in the current directory
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))
Sample response
The URL is valid for 24 hours. Download the image in time.
{
"status_code": 200,
"request_id": "9d634fda-5fe9-9968-a908-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "d35658e4-483f-453b-b8dc-xxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1.png",
"orig_prompt": "A flower shop with exquisite windows, beautiful wooden doors, displaying flowers",
"actual_prompt": "An exquisite flower shop with elegant carved windows and beautiful wooden doors with brass handles. Inside, various colorful flowers are displayed, such as roses, tulips, and lilies. The background is a cozy indoor scene with soft lighting, creating a peaceful and comfortable atmosphere. High-definition realistic photography, close-up centered composition."
}],
"submit_time": "2025-01-08 19:36:01.521",
"scheduled_time": "2025-01-08 19:36:01.542",
"end_time": "2025-01-08 19:36:13.270",
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Asynchronous
Sample request
Text-to-image
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
prompt = "A flower shop with exquisite windows, beautiful wooden doors, displaying flowers"
def async_call():
print('----create task----')
task_info = create_async_task()
print('----wait task done then save image----')
wait_async_task(task_info)
# Create an asynchronous task
def create_async_task():
rsp = ImageSynthesis.async_call(api_key=os.getenv("DASHSCOPE_API_KEY"),
model="wan2.1-t2i-turbo",
prompt=prompt,
n=1,
size='1024*1024')
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
return rsp
# Wait for the asynchronous task to complete
def wait_async_task(task):
rsp = ImageSynthesis.wait(task)
print(rsp)
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('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
# Get asynchronous task information
def fetch_task_status(task):
status = ImageSynthesis.fetch(task)
print(status)
if status.status_code == HTTPStatus.OK:
print(status.output.task_status)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(status.status_code, status.code, status.message))
# Cancel the task. Only tasks in the PENDING state can be canceled
def cancel_task(task):
rsp = ImageSynthesis.cancel(task)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.task_status)
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(rsp.status_code, rsp.code, rsp.message))
if __name__ == '__main__':
async_call()
Sample response
1. Create a task
{
"status_code": 200,
"request_id": "31b04171-011c-96bd-ac00-f0383b669cc7",
"code": "",
"message": "",
"output": {
"task_id": "4f90cf14-a34e-4eae-xxxxxxxx",
"task_status": "PENDING",
"results": []
},
"usage": null
}
2. Query task results
The URL is valid for 24 hours. Download the image in time.
{
"status_code": 200,
"request_id": "9d634fda-5fe9-9968-a908-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "d35658e4-483f-453b-b8dc-xxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1.png",
"orig_prompt": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display.",
"actual_prompt": "An exquisite flower shop with windows decorated with elegant carvings and a beautiful wooden door with a brass handle. Inside, a variety of brightly colored flowers, such as roses, tulips, and lilies, are on display. The background is a warm indoor scene with soft lighting, creating a peaceful and comfortable atmosphere. High-definition, photorealistic photography, close-up, centered composition."
}],
"submit_time": "2025-01-08 19:36:01.521",
"scheduled_time": "2025-01-08 19:36:01.542",
"end_time": "2025-01-08 19:36:13.270",
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Java SDK
Synchronous
Sample request
Text-to-image
// Copyright (c) Alibaba, Inc. and its affiliates.
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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
static {
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void basicCall() throws ApiException, NoApiKeyException {
String prompt = "A flower shop with exquisite windows, beautiful wooden doors, displaying flowers";
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("wan2.1-t2i-turbo")
.prompt(prompt)
.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 listTask() throws ApiException, NoApiKeyException {
ImageSynthesis is = new ImageSynthesis();
AsyncTaskListParam param = AsyncTaskListParam.builder().build();
ImageSynthesisListResult result = is.list(param);
System.out.println(result);
}
public void fetchTask() throws ApiException, NoApiKeyException {
String taskId = "your task id";
ImageSynthesis is = new ImageSynthesis();
// If set DASHSCOPE_API_KEY environment variable, apiKey can null.
ImageSynthesisResult result = is.fetch(taskId, null);
System.out.println(result.getOutput());
System.out.println(result.getUsage());
}
public static void main(String[] args){
try{
basicCall();
//listTask();
}catch(ApiException|NoApiKeyException e){
System.out.println(e.getMessage());
}
}
}
Sample response
The URL is valid for 24 hours. Download the image in time.
{
"request_id": "22f9c744-206c-9a78-899a-xxxxxx",
"output": {
"task_id": "4a0f8fc6-03fb-4c44-a13a-xxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"orig_prompt": "A flower shop with exquisite windows, beautiful wooden doors, displaying flowers",
"actual_prompt": "A flower shop with exquisite carved windows, beautiful dark wooden doors slightly ajar. Inside, various fresh flowers are displayed, including roses, lilies, and sunflowers, vibrant and fragrant. The background is a cozy indoor scene with soft lighting filtering through the windows onto the flowers. High-definition realistic photography, medium shot composition.",
"url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1.png"
}],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Asynchronous
Sample request
Text-to-image
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
public class Main {
static {
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
public void asyncCall() {
System.out.println("---create task----");
String taskId = this.createAsyncTask();
System.out.println("---wait task done then return image url----");
this.waitAsyncTask(taskId);
}
/**
* Create an asynchronous task
* @return taskId
*/
public String createAsyncTask() {
String prompt = "A flower shop with exquisite windows, beautiful wooden doors, displaying flowers";
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("wan2.1-t2i-turbo")
.prompt(prompt)
.n(1)
.size("1024*1024")
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
result = imageSynthesis.asyncCall(param);
} catch (Exception e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
System.out.println("taskId=" + taskId);
return taskId;
}
/**
* Wait for the asynchronous task to complete
* @param taskId Task ID
* */
public void waitAsyncTask(String taskId) {
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
//If DASHSCOPE_API_KEY is already set in environment variables, the apiKey parameter in the wait() method can be set to null
result = imageSynthesis.wait(taskId, null);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
System.out.println(JsonUtils.toJson(result.getOutput()));
}
public static void main(String[] args){
Main main = new Main();
main.asyncCall();
}
}
Sample response
1. Create a task
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-542f97709ba8",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}
2. Query task results
{
"request_id": "22f9c744-206c-9a78-899a-xxxxxx",
"output": {
"task_id": "4a0f8fc6-03fb-4c44-a13a-xxxxxx",
"task_status": "SUCCEEDED",
"results": [{
"orig_prompt": "A flower shop with exquisite windows, beautiful wooden doors, displaying flowers",
"actual_prompt": "A flower shop with exquisite carved windows, beautiful dark wooden doors slightly ajar. Inside, various fresh flowers are displayed, including roses, lilies, and sunflowers, vibrant and fragrant. The background is a cozy indoor scene with soft lighting filtering through the windows onto the flowers. High-definition realistic photography, medium shot composition.",
"url": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1.png"
}],
"task_metrics": {
"TOTAL": 1,
"SUCCEEDED": 1,
"FAILED": 0
}
},
"usage": {
"image_count": 1
}
}
Error codes
If the model call fails and returns an error message, see Error messages for solutions.
Specific status codes for this API:
HTTP status code | API Error Code (code) | Description |
400 | IPInfringementSuspect | The input data may involve intellectual property infringement. Check your input to ensure it does not contain such content. |
FAQ
Billing and rate limiting
Free quota
Overview: Free quota refers to the number of output images successfully generated by the model. Input images and failed model processing do not consume the free quota.
How to get: You automatically get it after activating Model Studio, valid for 180 days.
Account usage: Alibaba Cloud account and its RAM users share the free quota.
For more information, see Free quota for new users.
Limited-time free
When a model is marked as limited-time free trial, the model is in public preview. After the free quota is exhausted, the model cannot be used.
Billing description
When a model has a specific unit price, such as $0.2/second, the model has been commercialized. You need to pay for it after its free quota is exhausted or expired.
Billing item: Only successfully generated output images are charged. Other cases are not charged.
Payment method: All payments are made by the Alibaba Cloud account. RAM users cannot pay independently. To check your bills, go to Billing Overview.
Recharge channel: You can recharge on the Alibaba Cloud Management Console Billing and Cost page.
Model usage statistics: You can check model usage and call count by visiting Alibaba Cloud Model Studio's Model Monitoring page.
For more information, see Billing items.
Rate limit
Overview: Alibaba Cloud account and its RAM users share the limits.
Configure domain whitelist to access image OSS links
Generated images are stored in OSS, and each image is assigned an OSS link, such as https://dashscope-result-xx.oss-cn-xxxx.aliyuncs.com/xxx.png
. OSS links allow public access. You can use this link to view or download the image. The link is valid for only 24 hours.
If your business has high security requirements and cannot access OSS links, you need to configure a separate whitelist for external network access Add the following domains to your whitelist to access image links.
# OSS domain list
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