The text-to-image API enables you to create new images from text descriptions. Alibaba Cloud Model Studio offers two main model series:
Qwen-Image: Excels at rendering complex Chinese and English text.
Wan series: Generates realistic images and photographic-grade visual effects.
Try it online: Singapore | Beijing
Model performance
Qwen-Image
Complex text
| Long paragraphs
| Complex layouts
|
Poster creation
| Illustration design
| Realistic photography
|
Wan
Portrait photography
| Realistic photography
| Painting styles
|
Text generation
| Poster design
| Image set generation
|
Supported models
Model selection
Complex text rendering (such as for posters and couplets): Use
qwen-image-maxorwan2.6-t2i.Realistic scenes and photographic styles (for general scenarios): Use a Wan model, such as
wan2.6-t2iorwan2.5-t2i-preview.Custom output image resolution: Use a Wan model, such as
wan2.2-t2i-flash. It supports any width and height combination within the range of 512 to 1440 pixels.Qwen-Image supports only five fixed resolutions: 1664*928 (16:9), 928*1664 (9:16), 1328*1328 (1:1), 1472*1104 (4:3), and 1104*1472 (3:4).
Getting started
Prerequisites
Before you start, create an API key and export it as an environment variable. If you use the DashScope SDK, install the SDK.
Sample code
Invocation methods: Qwen-Image supports synchronous calls. The qwen-image-plus and qwen-image models also support asynchronous calls. Wan supports only asynchronous calls.
Asynchronous call: The APIs for both models are compatible. You can simply change the
modelparameter to switch between them. For example, to use a Wan model, set model to "wan2.2-t2i-flash".Synchronous call: Only Qwen-Image supports this method. To learn how to make a synchronous call, see the Qwen-Image API reference.
The following examples use the asynchronous call method. The sample code uses qwen-image-plus as an example, but the same approach applies to Wan models.
The SDK encapsulates the asynchronous processing logic, so it appears as a synchronous call at the interface level. This means a single request waits for the final result. In contrast, the curl example uses two separate asynchronous API calls: one to submit a task and another to query the result.
Python
Request example
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
import dashscope
# The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
prompt = "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere."
# The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
# If you have not configured an environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")
print('----sync call, please wait a moment----')
rsp = ImageSynthesis.call(api_key=api_key,
model="qwen-image-plus", # Currently, only the qwen-image-plus and qwen-image models support asynchronous API calls.
prompt=prompt,
negative_prompt=" ",
n=1,
size='1664*928',
prompt_extend=True,
watermark=False)
print(f'response: {rsp}')
if rsp.status_code == HTTPStatus.OK:
# Save the image to 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(f'sync_call Failed, status_code: {rsp.status_code}, code: {rsp.code}, message: {rsp.message}')
Response example
The URL is valid for 24 hours. Download the image promptly.
{
"status_code": 200,
"request_id": "a47b1a65-7041-4565-9068-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "91093132-475e-43cf-b94e-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"url": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxxxxx",
"orig_prompt": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere.",
"actual_prompt": "Childhood-inspired hand-drawn poster design: Three playful puppies joyfully interact with a colorful ball on a vibrant patch of lush green grass. Delicate decorative elements including fluttering birds and twinkling stars are scattered throughout. At the top center, the bold, blue cartoon-style title “Come Play Ball!” stands out prominently. Directly beneath, the subtitle “Come [Show Off Your Skills]!” is rendered in cheerful green lettering. A whimsical speech bubble near one of the puppies contains the playful text: “Hehe, watch me amaze my little friends next!” At the bottom edge, smaller supplementary text reads: “We get to play ball with our friends again!” The color palette is centered on fresh greens and sky blues, accented with pops of bright pink and sunny yellow, enhancing the cheerful, childlike atmosphere. Style evokes nostalgic, hand-inked illustrations with soft textures, gentle linework, and a whimsical, storybook-like composition."
}
],
"submit_time": "2025-09-09 13:39:20.659",
"scheduled_time": "2025-09-09 13:39:20.717",
"end_time": "2025-09-09 13:39:45.233"
},
"usage": {
"image_count": 1
}
}Java
Request example
// 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.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
import java.util.Map;
public class Text2Image {
static {
// The following URL is for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// The API keys for the Singapore and China (Beijing) regions are different. To get an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
// If you have not configured an environment variable, replace the following line with your Model Studio API key: static String apiKey = "sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void basicCall() throws ApiException, NoApiKeyException {
String prompt = "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere.";
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("negative_prompt", " ");
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(apiKey)
// Currently, only the qwen-image-plus and qwen-image models support asynchronous API calls.
.model("qwen-image-plus")
.prompt(prompt)
.n(1)
.size("1664*928")
.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());
}
}
}
Response example
The URL is valid for 24 hours. Download the image promptly.
{
"request_id": "9f3044ba-528f-4606-8830-xxxxxx",
"output": {
"task_id": "fecf4c7f-3508-45f4-8454-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"orig_prompt": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere.",
"actual_prompt": "Childhood-inspired hand-drawn poster design: Three playful puppies joyfully interact with a colorful ball on a vibrant patch of lush green grass. Delicate decorative elements including fluttering birds and twinkling stars are scattered throughout. At the top center, the bold, blue cartoon-style title “Come Play Ball!” stands out prominently. Directly beneath, the subtitle “Come [Show Off Your Skills]!” is rendered in cheerful green lettering. A whimsical speech bubble near one of the puppies contains the playful text: “Hehe, watch me amaze my little friends next!” At the bottom edge, smaller supplementary text reads: “We get to play ball with our friends again!” The color palette is centered on fresh greens and sky blues, accented with pops of bright pink and sunny yellow, enhancing the cheerful, childlike atmosphere. Style evokes nostalgic, hand-inked illustrations with soft textures, gentle linework, and a whimsical, storybook-like composition.",
"url": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxxx"
}
]
},
"usage": {
"image_count": 1
}
}curl
For asynchronous calls, set the header parameter
X-DashScope-Asynctoenable.The
task_idfor an asynchronous task is valid for 24 hours. After it expires, the task status changes toUNKNOWN.
Step 1: Submit a task creation request
This request returns a task ID (task_id).
curl -X POST https://dashscope-intl.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": "qwen-image-plus",
"input": {
"prompt": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere."
},
"parameters": {
"negative_prompt":" ",
"size": "1664*928",
"n": 1,
"prompt_extend": true,
"watermark": false
}
}' Step 2: Query the result by task ID
Use the task_id from the previous step to poll the task status through the API until task_status is SUCCEEDED or FAILED.
Replace 86ecf553-d340-4e21-xxxxxxxxx with the actual task ID.
API keys are region-specific. Get an API key.
For models in the Beijing region, replace `base_url` with `https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx`
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"Key capabilities
1. Instruction following (prompts)
Parameters: input.prompt (required), input.negative_prompt (optional).
prompt (positive prompt): Describes the content, subjects, scenes, styles, lighting, and composition you want to see in the image. This is the core parameter for controlling text-to-image generation.
negative_prompt: Describes the content you do not want to see in the image, such as "blurry" or "extra fingers". This is used only to help optimize the generation quality.
Writing tips: A structured prompt usually produces better results. For writing tips, see Text-to-image prompt guide.
2. Enable prompt rewriting
Parameter: parameters.prompt_extend (bool, defaults to true).
This feature automatically expands and optimizes short prompts to improve image quality. Enabling this feature adds 3 to 5 seconds of latency because a large model is used to rewrite the prompt.
Best practices:
Enable it when your input prompt is simple or broad. This feature can significantly improve the image quality.
Disable it if you want to control fine details, have already provided a detailed description, or are sensitive to response latency. To disable it, explicitly set the
prompt_extendparameter tofalse.
3. Set the output image resolution
Parameter: parameters.size (string), in the format "width*height".
Qwen-Image: Supports only the following five fixed resolutions:
1664*928 (default): 16:9.
1472*1104: 4:3.
1328*1328: 1:1.
1104*1472: 3:4.
928*1664: 9:16.
Wan V2 models (v2.0 and later): Support resolutions with a width and height from 512 to 1440 pixels, provided the total pixel count does not exceed 1440*1440. Common resolutions:
1024*1024 (default): 1:1.
1440*810: 16:9.
810*1440: 9:16.
1440*1080: 4:3.
1080*1440: 3:4.
Going live
Fault tolerance strategies
Handle rate limiting: If the API returns a
Throttlingerror code or an HTTP 429 status code, rate limiting has been triggered, see Rate limits.Asynchronous task polling: When polling for asynchronous task results, use a reasonable polling strategy, such as polling every 3 seconds for the first 30 seconds and then increasing the interval. This helps avoid triggering rate limiting due to frequent requests. Set a final timeout for the task, such as 2 minutes, and consider the task failed if it times out.
Risk prevention
Result persistence: The image URL returned by the API is valid for 24 hours. Your production system must immediately download the image after you retrieve the URL and transfer it to your own persistent storage service, such as Alibaba Cloud Object Storage Service (OSS).
Content Moderation: All
promptandnegative_promptinputs undergo content moderation. If an input is non-compliant, the request is blocked and aDataInspectionFailederror is returned.Copyright and compliance risks of generated content: Ensure that your prompt content complies with relevant laws and regulations. Generating content that includes brand trademarks, celebrity portraits, or copyrighted IP images may pose infringement risks. You are responsible for assessing and bearing any resulting liabilities.
API reference
Billing and rate limiting
For information about the free quota and unit price for models, see Image generation.
Billing rules
Billable item: You are billed for the number of successfully generated images on a pay-as-you-go basis.
Billing formula: Fee = Unit price × Number of images.
Consumption order: Free quotas are consumed first. After your free quota is used up, the pay-as-you-go billing method is used by default.
You can enable the "Free quota only" option to prevent charges after your free quota is exhausted. For more information, see Free quota for new users.
No charge for failures: Failed model calls or processing errors do not incur fees or consume free quotas.
Free quotas
For more information about how to claim, query, and use free quotas, see Free quota for new users.
Query usage
Approximately one hour after a model call is complete, you can go to the Model Observation (Singapore) page to view metrics such as usage, number of calls, and success rate.
If you use a model in the China (Beijing) region, go to the Model Observation page for the China (Beijing) region.
Rate limiting
For rate limiting rules and FAQ, see Rate limits.
Error codes
If a call fails, see Error messages for troubleshooting.
FAQ
Q: How long is an image URL valid? How can I permanently save my images?
A: The image URL is valid for 24 hours. You must immediately download the image after you retrieve the URL and save it to your own persistent storage, such as a local server or Object Storage Service (OSS).
Q: The API call returns a DataInspectionFailed error. What should I do?
A: This error indicates that the input text triggered content moderation. Check and modify the text in the prompt or negative_prompt to remove any potentially non-compliant content, and then retry the request.
Q: Should I enable or disable the prompt_extend parameter?
A: Keep it enabled (the default) when your prompt is simple or you want the model to be more creative. Explicitly set it to false when your prompt is already very detailed and professional, or when you have strict requirements for API response latency.
Q: How can I improve the quality of text generated in images?
A: If your business relies heavily on generating clear and accurate text in images, use the qwen-image-plus model. It is specifically trained for such scenarios.











