Qwen-Text-to-Image API Reference
The Qwen text-to-image model (Qwen-Image) is a general-purpose image generation model that supports a variety of artistic styles and excels at complex text rendering. The model supports multi-line layouts, paragraph-level text generation, and fine-grained detail depiction, enabling complex mixed text-and-image layout design.
Quick access:User Guide | Online experience (Beijing | Singapore) | Technical blog |
Showcases
Input prompt | Output image |
|---|---|
A wintry urban street scene in Beijing: two adjacent Chinese-style shops with grey-green tiled roofs and vermilion outer walls stand side by side, warm-glowing lanterns printed with paper-cut horses hanging under the eaves, casting a soft halo in the overcast diffused light and reflecting a delicate sheen on the damp cobblestone pavement. On the left is a calligraphy shop: on an aged indigo signboard, the words “text rendering” are carved in vigorous running script. On the glass at the shop entrance hangs a piece of calligraphy, written top to bottom in Tian Yingzhang hard-pen script: “professional slides, Chinese-English posters, premium infographics”, signed with a cinnabar seal reading “1k token”. On the interior wall of the shop, three vertical calligraphy works can be dimly made out, the first reading “Alibaba”, the second “Qwen”, and the third “Image Generation”. A white-haired old man stands with his back to the camera, admiring them. On the right is a flower shop, whose signboard spells out “photorealistic texture” in fresh flowers; multi-tiered racks inside display red roses, pink ranunculus, and green plants, a round floral badge on the door reads “2k resolution”, and a colorful neon sign at the entrance reads “fine detail, people, nature, architecture”. Between the two shops stands a snowman holding up an old-fashioned small blackboard with the chalk words “Qwen-Image-2.0 officially released”. On the left of the street, a young couple nestles together; the girl, with a slim face, wears an off-white cashmere coat and flesh-colored bare-leg tights. She holds a heart-shaped transparent balloon printed in white with “generation and editing in one”; inside it sits a fluffy capybara plush toy. The boy wears a well-tailored dark-grey wool coat over a light-colored high-neck sweater. On the right of the street, a rider with “smaller model, faster speed” written on his back speeds past. The whole street interweaves light and shadow, motion and stillness in perfect balance. |
|
Model Overview
| Model | Model Description | Output Image Specifications |
|---|---|---|
qwen-image-2.0-pro
| The Pro series of Qwen image generation and editing models. Stronger text rendering, photorealistic texture, and semantic compliance capabilities.
| Image resolution: The width and height can be set freely, and the total pixels of the output image must be between 512512 and 20482048. The default resolution is 2048*2048. Image format: png Number of images: 1-6 |
qwen-image-2.0-pro-2026-06-22 | ||
qwen-image-2.0-pro-2026-04-22 | ||
qwen-image-2.0-pro-2026-03-03 | ||
qwen-image-2.0
| Accelerated version of the Qwen image generation and editing model, balancing quality and response speed.
| |
qwen-image-2.0-2026-03-03 |
For models supported in each region, see the Bailian console.
Prerequisites
Before calling, first obtain and configure an API Key, and then configure the API Key in environment variables. To make calls through an SDK, please install the DashScope SDK.
ImportantThe China (Beijing) and Singapore regions have their own API Key and request address, which cannot be mixed. Cross-region calls will result in authentication failures or service errors.
ImportantAlibaba Cloud Bailian has launched workspace-exclusive domains for the China (Beijing) and Singapore regions, which deliver superior performance and higher stability for inference requests. Migrating to the new domains is recommended:
- China (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
Among them, {WorkspaceId} is your workspace ID, which you can view on the Workspace Details page in the Alibaba Cloud Bailian console. The existing domains remain available.
Synchronous API
HTTP calls
Qwen image models support synchronous APIs, which return results in a single request. The calling process is simple, making them recommended for most scenarios.
Beijing region: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
Singapore region: 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.
Request parametersRequest HeadersContent-Type Request content type. This parameter must be set to Authorization Request authentication. The API uses the Alibaba Cloud Bailian API Key for authentication. Example value: Bearer sk-xxxx. Request Bodymodel Model name. Example value: input Basic input information. parameters Image processing parameters. | Text-to-image |
Response parametersoutput Task output information. usage Output information statistics. Only successful results are counted. request_id The unique request identifier, which can be used for request detail tracing and troubleshooting. code The error code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error codes. message The detailed error information returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error codes. | Task executed successfullyThe image URL is retained for only 24 hours and is automatically cleared after it expires. Please save the generated image promptly. Task execution exceptionIf the task fails for some reason, relevant information will be returned, and the code and message fields clearly indicate the error cause. See Error codes to resolve the issue. |
DashScope SDK Calls
The DashScope SDK currently supports Python and Java.
The SDK parameter names are basically identical to those of the HTTP interface, with the parameter structures encapsulated according to language characteristics. For parameter descriptions of synchronous calls, see HTTP Calls.
Python
NotePlease make sure the latest version of the DashScope Python SDK is installed first; otherwise errors may occur: Install the SDK.
Request example
import json
import os
import dashscope
# 以下为华北2(北京)地域的配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的URL不同。
# 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
workspace="{WorkspaceId}",
region="cn-beijing",
)
messages = [
{
"role": "user",
"content": [
{"text": "冬日北京的都市街景,青灰瓦顶、朱红色外墙的两间相邻中式商铺比肩而立,檐下悬挂印有剪纸马的暖光灯笼,在阴天漫射光中投下柔和光晕,映照湿润鹅卵石路面泛起细腻反光。左侧为书法店:靛蓝色老旧的牌匾上以遒劲行书刻着“文字渲染”。店门口的玻璃上挂着一幅字,自上而下,用田英章硬笔写着“专业幻灯片 中英文海报 高级信息图”,落款印章为“1k token”朱砂印。店内的墙上,可以模糊的辨认有三幅竖排的书法作品,第一幅写着“阿里巴巴”,第二幅写着“通义千问”,第三幅写着“图像生成”。一位白发苍苍的老人背对着镜头观赏。右侧为花店,牌匾上以鲜花做成文字“真实质感”;店内多层花架陈列红玫瑰、粉洋牡丹和绿植,门上贴了一个圆形花边标识,标识上写着“2k resolution”,门口摆放了一个彩色霓虹灯,上面写着“细腻刻画 人物 自然 建筑”。两家店中间堆放了一个雪人,举了一老式小黑板,上面用粉笔字写着“Qwen-Image-2.0 正式发布”。街道左侧,年轻情侣依偎在一起,女孩是瘦脸,身穿米白色羊绒大衣,肉色光腿神器。女孩举着心形透明气球,气球印有白色的字:“生图编辑二合一”。里面有一个毛茸茸的卡皮巴拉玩偶。男孩身着剪裁合体的深灰色呢子外套,内搭浅色高领毛衣。街道右侧,一个后背上写着“更小模型,更快速度”的骑手疾驰而过。整条街光影交织、动静相宜。"}
]
}
]
# 1.x 的 prompt_extend/watermark/negative_prompt/size 等参数,2.0 中统一通过 parameters 传入
response = client.multimodal.chat.create(
model="qwen-image-2.0-pro",
messages=messages,
parameters={
"watermark": False,
"prompt_extend": True,
"negative_prompt": "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。",
"size": "2048*2048",
},
)
# 2.0 SDK:生成结果从 message.content_parts 读取,图像 part 形如 {"image": URL, "type": "image"}
message = response.choices[0].message
for part in (message.content_parts or []):
if "image" in part:
print(json.dumps(part, ensure_ascii=False))
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
NoteYou must install the latest DashScope Java SDK. Otherwise, runtime errors may occur: Install SDK.
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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class QwenImage {
static {
// 以下为华北2(北京)地域的URL,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的URL不同。
Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
}
// 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
// 若没有配置环境变量,请用百炼API Key将下行替换为: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", "冬日北京的都市街景,青灰瓦顶、朱红色外墙的两间相邻中式商铺比肩而立,檐下悬挂印有剪纸马的暖光灯笼,在阴天漫射光中投下柔和光晕,映照湿润鹅卵石路面泛起细腻反光。左侧为书法店:靛蓝色老旧的牌匾上以遒劲行书刻着“文字渲染”。店门口的玻璃上挂着一幅字,自上而下,用田英章硬笔写着“专业幻灯片 中英文海报 高级信息图”,落款印章为“1k token”朱砂印。店内的墙上,可以模糊的辨认有三幅竖排的书法作品,第一幅写着“阿里巴巴”,第二幅写着“通义千问”,第三幅写着“图像生成”。一位白发苍苍的老人背对着镜头观赏。右侧为花店,牌匾上以鲜花做成文字“真实质感”;店内多层花架陈列红玫瑰、粉洋牡丹和绿植,门上贴了一个圆形花边标识,标识上写着“2k resolution”,门口摆放了一个彩色霓虹灯,上面写着“细腻刻画 人物 自然 建筑”。两家店中间堆放了一个雪人,举了一老式小黑板,上面用粉笔字写着“Qwen-Image-2.0 正式发布”。街道左侧,年轻情侣依偎在一起,女孩是瘦脸,身穿米白色羊绒大衣,肉色光腿神器。女孩举着心形透明气球,气球印有白色的字:“生图编辑二合一”。里面有一个毛茸茸的卡皮巴拉玩偶。男孩身着剪裁合体的深灰色呢子外套,内搭浅色高领毛衣。街道右侧,一个后背上写着“更小模型,更快速度”的骑手疾驰而过。整条街光影交织、动静相宜。")
)).build();
Map<String, Object> parameters = new HashMap<>();
parameters.put("watermark", false);
parameters.put("prompt_extend", true);
parameters.put("negative_prompt", "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。");
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"
}
]
}
}
]
}
}
Use with the OpenAI Agents SDK
Image generation models such as Qwen-Image are called through the DashScope native API and do not support OpenAI-compatible (compatible-mode) mode, so they cannot be used directly as the reasoning model of an Agent in the OpenAI Agents SDK.
In agent frameworks such as the OpenAI Agents SDK, you can wrap image generation as a tool (function tool) and let a text chat model that supports OpenAI-compatible mode (such as qwen-plus) act as the Agent's reasoning core to orchestrate it. For example:
Before running, install the dependencies: pip install openai-agents dashscope.
import os
import asyncio
import dashscope
from openai import AsyncOpenAI
from agents import Agent, Runner, function_tool, OpenAIChatCompletionsModel
# 从环境变量读取百炼 API Key(若未配置,可直接替换为 api_key="sk-xxx")
API_KEY = os.getenv("DASHSCOPE_API_KEY")
# 以下为华北2(北京)地域的URL,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的URL不同。
# 图像生成走 DashScope 原生接口;文本对话模型(Agent 推理核心)通过 OpenAI 兼容模式接入
client = dashscope.Client(
api_key=API_KEY,
workspace="{WorkspaceId}",
region="cn-beijing",
)
openai_client = AsyncOpenAI(api_key=API_KEY, base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1")
# 将图像生成封装为工具(function tool),供 Agent 调用
@function_tool
def generate_image(prompt: str) -> str:
"""根据文本描述生成一张图片并返回图片 URL。prompt:图片内容的文字描述。"""
rsp = client.multimodal.chat.create(
model="qwen-image-2.0-pro",
messages=[{"role": "user", "content": [{"text": prompt}]}],
)
# 2.0 SDK:生成结果从 message.content_parts 读取,图像 part 形如 {"image": URL, "type": "image"}
message = rsp.choices[0].message
for part in (message.content_parts or []):
if "image" in part:
return part["image"]
return "生成失败:未返回图像"
agent = Agent(
name="图像生成助手",
instructions="你是图像生成助手。当用户想要图片时,调用 generate_image 工具,并把返回的图片 URL 告诉用户。",
model=OpenAIChatCompletionsModel(model="qwen-plus", openai_client=openai_client),
tools=[generate_image],
)
async def main():
result = await Runner.run(agent, "帮我画一只在草地上奔跑的柯基犬")
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())
Billing and rate limiting
- For free quotas and pricing, see Model pricing.
- For rate limits, see Qwen-Image.
- Billing details: Each successfully generated image is billed. Failed calls or processing errors do not incur charges or consume your new user free quota.
Error codes
If the model call fails and returns an error message, see Error codes for resolution.
FAQ
Q: Should I enable or disable the prompt_extend parameter?
A: Enable this option (default) if you want more diverse image content and for the model to add details. Disable it if you need tighter control over image details, and optimize your prompts using the Text-to-Image Prompt Guide.
Q: What are the differences between qwen-image-2.0 series models?
A:
-
Combined image generation and editing models: Support both text-to-image and image editing.
qwen-image-2.0-proandqwen-image-2.0-pro-2026-04-22: Same capabilities. The Pro series delivers more professional text rendering, finer realistic textures, detailed realistic scenes, and stronger semantic adherence. Supports synchronous calls only.qwen-image-2.0andqwen-image-2.0-2026-03-03: Same capabilities. The accelerated version balances model performance and quality. Supports synchronous calls only.
Q: How do I get the domain name whitelist for image storage?
A: Images generated by models are stored in Alibaba Cloud OSS. The API returns a temporary public URL (valid for 24 hours; download and save it promptly). The image URL domain format is dashscope-{marker}.oss-accelerate.aliyuncs.com or dashscope-{marker}.oss-cn-{region}.aliyuncs.com. If you need to configure a firewall whitelist for the download address, note the following: because the underlying storage changes dynamically, the bucket names below are for reference only and may change at any time: dashscope-a717, dashscope-66f3, dashscope-7c2c, dashscope-2522, dashscope-c72b, dashscope-0484, dashscope-7e0f, dashscope-5859, dashscope-5496, dashscope-35f9, dashscope-31d9, dashscope-7f1f, dashscope-cc75, dashscope-64e9. To prevent outdated information from affecting access, this document does not provide a fixed OSS domain whitelist. If you have security control requirements, contact your account manager to obtain the latest OSS domain list. The API currently returns URLs only and does not support base64 output.
