Use the text-to-image API to generate new images from text descriptions. Alibaba Cloud Model Studio offers two model families:
Qwen-Image: excels at rendering complex Chinese and English text.
Wan series: generates realistic images and photography-grade visual effects.
Try it online: Singapore | Beijing
Model performance
Qwen-Image
Complex text
| Long paragraph
| Complex layout
|
Poster creation
| Illustration design
| Photorealistic photography
|
Wan
Portrait photography
| Photorealistic
| Artistic styles
|
Text rendering
| Poster design
| Multi-image generation
|
Supported models
Model selection
Complex text rendering (e.g., posters, couplets): Use
qwen-image-2.0-proorwan2.6-t2i.Realistic scenes and photography styles (general use): Choose Wan models such as
wan2.6-t2iorwan2.5-t2i-preview.Custom output image resolution: Use
qwen-image-2.0series or Wan models. The qwen-image-2.0 series supports custom width and height. Total pixels must be between 512*512 and 2048*2048. Wan models such aswan2.6-t2isupport total pixels between 1280*1280 and 1440*1440.The qwen-image-max and qwen-image-plus series support only five fixed sizes: 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 calling the API, get your API key. Then set your API key as an environment variable. If you use the DashScope SDK, also install the SDK.
Sample code
Calling methods:
All Qwen text-to-image models support synchronous calls. The qwen-image-plus and qwen-image models also support asynchronous calls. For details, see Qwen - text-to-image.
All Wan text-to-image models support asynchronous calls. The wan2.6-t2i model also supports synchronous calls. For details, see Wan - text-to-image V2.
Synchronous
Python
Request example
import json
import os
import dashscope
from dashscope import MultiModalConversation
# Use this URL for Singapore region. For Beijing region, replace with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
messages = [
{
"role": "user",
"content": [
{"text": "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."}
]
}
]
# API keys differ between Beijing and Singapore regions. Get your API key: https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# If you haven't set the environment variable, replace the line below with: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")
response = MultiModalConversation.call(
api_key=api_key,
model="qwen-image-2.0-pro",
messages=messages,
result_format='message',
stream=False,
watermark=False,
prompt_extend=True,
negative_prompt="Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-figure appearance, lack of facial detail, excessive smoothness, AI-looking artifacts, chaotic composition, blurry or warped text.",
size='2048*2048'
)
if response.status_code == 200:
print(json.dumps(response, ensure_ascii=False))
else:
print(f"HTTP status code: {response.status_code}")
print(f"Error code: {response.code}")
print(f"Error message: {response.message}")
print("See documentation: https://www.alibabacloud.com/help/zh/model-studio/error-code")
Response example
Image URLs expire after 24 hours. Download the images promptly.
{
"status_code": 200,
"request_id": "d2d1a8c0-325f-9b9d-8b90-xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/xxx.png?Expires=xxx"
}
]
}
}
]
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"width": 2048,
"image_count": 1,
"height": 2048
}
}Java
Request example
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class QwenImage {
static {
// Use this URL for Singapore region. For Beijing region, replace with: https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// API keys differ between Beijing and Singapore regions. Get your API key: https://www.alibabacloud.com/help/zh/model-studio/get-api-key
// If you haven't set the environment variable, replace the line below with: static String apiKey="sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void call() throws ApiException, NoApiKeyException, UploadFileException, IOException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
.content(Arrays.asList(
Collections.singletonMap("text", "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.")
)).build();
Map<String, Object> parameters = new HashMap<>();
parameters.put("watermark", false);
parameters.put("prompt_extend", true);
parameters.put("negative_prompt", "Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-figure appearance, lack of facial detail, excessive smoothness, AI-looking artifacts, chaotic composition, blurry or warped text.");
parameters.put("size", "2048*2048");
MultiModalConversationParam param = MultiModalConversationParam.builder()
.apiKey(apiKey)
.model("qwen-image-2.0-pro")
.messages(Collections.singletonList(userMessage))
.parameters(parameters)
.build();
MultiModalConversationResult result = conv.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
call();
} catch (ApiException | NoApiKeyException | UploadFileException | IOException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
Response example
Image URLs expire after 24 hours. Download the images promptly.
{
"requestId": "5b6f2d04-b019-40db-a5cc-xxxxxx",
"usage": {
"image_count": 1,
"width": 2048,
"height": 2048
},
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/xxx.png?Expires=xxx"
}
]
}
}
]
}
}curl
Request example
curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "A winter street scene in Beijing featuring two adjacent traditional Chinese shops with gray-tiled roofs and vermilion-red exterior walls standing side by side. Warm-glow lanterns adorned with paper-cut horse motifs hang beneath the eaves, casting soft halos under overcast diffused light that gently reflects off the damp cobblestone pavement. On the left is a calligraphy shop: an aged indigo signboard bears the bold running-script characters “Text Rendering.” A vertical scroll on the storefront glass reads from top to bottom in Tian Yingzhang’s hard-pen style: “Professional Slides, Bilingual Posters, Advanced Infographics,” stamped with a cinnabar seal reading “1k token.” Inside, three vertically mounted calligraphy works are faintly visible on the wall—the first says “Alibaba,” the second “Qwen,” and the third “Image Generation.” An elderly white-haired man stands with his back to the camera, admiring the art. On the right is a flower shop whose sign spells out “Realistic Texture” using fresh blooms. Multi-tiered shelves inside display red roses, pink peonies, and greenery. A circular floral-patterned badge on the door reads “2k resolution,” and a colorful neon sign at the entrance displays the text “Detailed Depiction: People, Nature, Architecture.” Between the two shops sits a snowman holding an old-fashioned chalkboard with the words “Qwen-Image-2.0 Officially Released” scrawled in chalk. On the left side of the street, a young couple leans close together—the woman has a slender face, wears a beige cashmere coat and nude-toned sheer tights, and holds a transparent heart-shaped balloon printed with white text: “Image Generation and Editing in One.” Inside the balloon is a fluffy capybara plush toy. The man wears a well-tailored dark gray wool overcoat layered over a light turtleneck sweater. On the right side of the street, a delivery rider speeds past with “Smaller Model, Faster Speed” written across his back. The entire street blends dynamic motion with serene stillness through interwoven light and shadow."
}
]
}
]
},
"parameters": {
"negative_prompt": "Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-figure appearance, lack of facial detail, excessive smoothness, AI-looking artifacts, chaotic composition, blurry or warped text.",
"prompt_extend": true,
"watermark": false,
"size": "2048*2048"
}
}'curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"model": "qwen-image-2.0-pro",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "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": "Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-figure appearance, lack of facial detail, excessive smoothness, AI-looking artifacts, chaotic composition, blurry or warped text.",
"prompt_extend": true,
"watermark": false,
"size": "2048*2048"
}
}'Response example
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": [
{
"image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"
}
],
"role": "assistant"
}
}
]
},
"usage": {
"height": 2048,
"image_count": 1,
"width": 2048
},
"request_id": "d0250a3d-b07f-49e1-bdc8-6793f4929xxx"
}Asynchronous
The SDK wraps asynchronous logic at the lower level. Its top-level interface behaves like a synchronous call (single request, wait for final result). The curl examples use two separate asynchronous APIs: one to submit a task, another to query results.
Python
Request example
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message
# The following is the base_url for the Singapore region. The base_url is different for each region.
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
# The API keys for different regions are different. To obtain an API key, see https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")
message = Message(
role="user",
content=[
{
'text': 'A flower shop with exquisite windows, a beautiful wooden door, and flowers on display'
}
]
)
print("----sync call, please wait a moment----")
rsp = ImageGeneration.call(
model="wan2.6-t2i",
api_key=api_key,
messages=[message],
negative_prompt="",
prompt_extend=True,
watermark=False,
n=1,
size="1280*1280"
)
print(rsp)
Response example
The URL is valid for 24 hours. You must download the image promptly.
{
"status_code": 200,
"request_id": "820dd0db-eb42-4e05-8d6a-1ddb4axxxxxx",
"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": "1280*1280",
"total_tokens": 0
}
}
Java
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.Collections;
public class Main {
static {
// The following is the URL for the Singapore region. The base_url is different for each region.
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey="sk-xxx"
// The API keys for different regions are different. To obtain an API key, see https://www.alibabacloud.com/help/zh/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(Collections.singletonList(
Collections.singletonMap("text", "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display")
)).build();
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(apiKey)
.model("wan2.6-t2i")
.n(1)
.size("1280*1280")
.negativePrompt("")
.promptExtend(true)
.watermark(false)
.messages(Collections.singletonList(message))
.build();
ImageGeneration imageGeneration = new ImageGeneration();
ImageGenerationResult result = null;
try {
System.out.println("---sync call, 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. You must download the image promptly.
{
"status_code": 200,
"request_id": "50b57166-eaaa-4f17-b1e0-35a5ca88672c",
"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"
}
]
}
}
],
"finished": true
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"image_count": 1,
"size": "1280*1280",
"total_tokens": 0
}
}
curl
Set the header parameter
X-DashScope-Asynctoenablefor asynchronous calls.The
task_idfor asynchronous tasks expires after 24 hours. After expiration, the task status becomesUNKNOWN.
Step 1: Submit a task
This request returns a task ID (task_id).
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'X-DashScope-Async: enable' \
--data '{
"model": "wan2.6-t2i",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "A flower shop with exquisite windows, a beautiful wooden door, and flowers on display"
}
]
}
]
},
"parameters": {
"prompt_extend": true,
"watermark": false,
"n": 1,
"negative_prompt": "",
"size": "1280*1280"
}
}'Step 2: Query the result using the task ID
Use the task_id from Step 1. Poll the task status until task_status becomes SUCCEEDED or FAILED.
Replace {task_id} with the task_id value returned by the previous API call. task_id is valid for queries within 24 hours.
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"Key capabilities
1. Instruction following (prompts)
Parameters: input.prompt (required) and input.negative_prompt (optional).
Prompt (positive prompt): Describes what you want in the image—subject, scene, style, lighting, and composition. This is the core control parameter for text-to-image.
Negative prompt: Describes what you do not want in the image, such as “blurry” or “extra fingers”. Used only to help refine output quality.
Writing tips: Structured prompts often yield better results. See Text-to-image prompt guide for best practices.
2. Enable prompt rewriting
Parameter: parameters.prompt_extend (boolean, default: true).
This feature automatically expands and refines short prompts to improve image quality. Enabling it adds 3–5 seconds of latency—the time needed for a large language model to rewrite the text.
Practical advice:
Enable it when your input prompt is brief or general. This significantly improves image quality.
Disable it when you need tight control over details, already provide a detailed description, or require low latency. Set
prompt_extendtofalse.
3. Set output image resolution
Parameter: parameters.size (string), format: "width*height".
qwen-image-2.0 series: Supports custom width and height. Total pixels must be between 512*512 and 2048*2048. Default resolution is 2048*2048. Recommended resolutions:
2688*1536: 16:91536*2688: 9:162048*2048(default): 1:12368*1728: 4:31728*2368: 3:4
qwen-image-max and qwen-image-plus series: Support only these five fixed resolutions:
1664*928(default): 16:91472*1104: 4:31328*1328: 1:11104*1472: 3:4928*1664: 9:16
Wan V2 model (version 2.0 and later): supports width and height within the [512, 1440] pixel range, with the total number of pixels not exceeding 1440*1440. Common resolutions:
1024*1024(default): 1:11440*810: 16:9810*1440: 9:161440*1080: 4:31080*1440: 3:4
Going live
Fault tolerance
Handle rate limiting: When the API returns error code
Throttlingor HTTP status code 429, the request is rate-limited. See Rate limiting for details.Poll asynchronous tasks: When polling for asynchronous task results, use a reasonable strategy—such as every 3 seconds for the first 30 seconds, then increasing intervals—to avoid triggering rate limiting. Set a final timeout (e.g., 2 minutes). Mark the task as failed if it times out.
Risk prevention
Persistent storage: Image URLs from the API expire after 24 hours. Production systems must download images immediately after receiving the URL and store them in persistent storage (e.g., Alibaba Cloud Object Storage Service).
Content moderation: All
promptandnegative_promptinputs are moderated. If content violates policies, the request is blocked and returns errorDataInspectionFailed.Copyright and compliance risks: Ensure your prompts comply with applicable laws and regulations. Generating content with brand trademarks, celebrity likenesses, or copyrighted IP may pose infringement risks. You are responsible for those risks.
API reference
Billing and rate limiting
For free quotas and pricing, see Model pricing.
For rate limits, see Image generation.
Billing note: Charge per successfully generated image. Failed calls incur no charge and do not consume free trial quota.
Error codes
If the model call fails and returns an error message, see Error messages for resolution.
FAQ
Q: How long do image URLs last? How do I save images permanently?
A: Image URLs expire after 24 hours. Download images immediately after receiving the URL and save them to persistent storage—such as a local server or Alibaba Cloud Object Storage Service.
Q: My API call returns DataInspectionFailed. How do I fix it?
A: This error means your input text triggered content moderation. Review and revise your prompt or negative_prompt to remove potentially non-compliant content, then retry.
Q: Should I enable or disable the prompt_extend parameter?
A: Keep it enabled (default) when your prompt is brief or you want the model to add creative detail. Disable it by setting it to false when your prompt is already detailed—or when you need strict latency control.
Q: How do I improve text rendering in images?
A: Use the qwen-image-2.0-pro model. It excels at text rendering.











