全部产品
Search
文档中心

大模型服务平台百炼:文本生成图像

更新时间:Jun 30, 2026

通过文生图API,您可以基于文本描述创造出全新的图像。阿里云百炼提供万相(Wan)、千问(Qwen-Image)和z-image系列模型。

在线体验新加坡北京

模型效果

千问(Qwen-image)

复杂文字

p1005416-转换自-png

超长段落

p1005400-转换自-png

复杂布局

3

海报制作

image

插画设计

1

写实摄影

2

点击查看提示词

复杂文字:Bookstore window display. A sign displays “New Arrivals This Week”. Below, a shelf tag with the text “Best-Selling Novels Here”. To the side, a colorful poster advertises “Author Meet And Greet on Saturday” with a central portrait of the author. There are four books on the bookshelf, namely “The light between worlds” “When stars are scattered” “The slient patient” “The night circus”

超长段落:A young girl dressed in a school uniform stands in a classroom, writing on the blackboard. Centered on the board, neatly inscribed in white chalk, is the text: “Introducing Qwen-Image, a foundational image generation model that excels in complex text rendering and precise image editing.” Soft natural light streams through the windows, casting gentle shadows. The scene is rendered in a realistic photographic style, with finely detailed textures, shallow depth of field, and warm tonal hues. The girl’s focused expression and the chalk dust suspended in the air add a sense of movement and vitality. Background elements—including student desks and educational posters—are slightly blurred to emphasize the central action. Ultra-high 32K resolution, DSLR-quality imagery, soft bokeh effect, and documentary-style composition.

复杂布局:Create a classroom PPT slide for a speech. It features artistic, decorative shapes framing neatly arranged textual info as an elegant infographic. Center title: ‘Habits for Emotional Wellbeing’, surrounded by a symmetrical floral pattern. Left upper: ‘Practice Mindfulness’ + minimalist lotus icon + text ‘Be present, observe without judging, accept without resisting’. Downward: ‘Cultivate Gratitude’ + open hand illustration + text ‘Appreciate simple joys and acknowledge positivity daily’. Bottom - left: ‘Stay Connected’ + minimalistic chat bubble icon + text ‘Build and maintain meaningful relationships to sustain emotional energy’. Bottom right: ‘Prioritize Sleep’ + crescent moon illustration + text ‘Quality sleep benefits both body and mind’. Upward right: ‘Regular Physical Activity’ + jogging runner icon + text ‘Exercise boosts mood and relieves anxiety’. Top right: ‘Continuous Learning’ + book icon + text ‘Engage in new skill and knowledge for growth’. The layout balances clarity & artistry, guiding viewers naturally. --ar 16:9 --style clean - presentatio.

海报制作: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.

插画设计:A vibrant and lively illustration of a sunny, bustling commercial street scene, slice of life. In the foreground, a young boy in a white shirt and shorts is intently choosing items from a market stall. The stall is filled with snacks, drinks, and daily goods.The stall owner, a middle-aged man in an apron, is organizing the products. A wooden sign with “Qwen-Image” in a handwritten style hangs above the stall. The background features modern, colorful buildings with prominent signs for “Alibaba”“Model Studio”“Text-to-Image”. The sky is azure blue with fluffy white clouds and soaring seagulls.Art Style: Realism illustration, delicate and soft, vibrant colors, rich layers, subtle hand-drawn texture, detailed, strong light and shadow, full composition, strong sense of depth, cheerful and relaxing atmosphere.

写实摄影:一位约20岁出头的亚洲年轻女性,留着齐刘海、乌黑光滑的长直发,自然垂落于双肩两侧。她侧坐于一张复古碎花布艺沙发上,沙发图案为米白底色配粉色与绿色花卉,质地略显陈旧,带有生活感。她身穿一件宽松的浅绿色马海毛针织毛衣,质感蓬松柔软,下身搭配浅灰蓝色亚麻长裙,整体造型清新自然、慵懒随性。右手轻轻握住一颗红色番茄,抬至下巴附近,姿态随意,眼神直视镜头,神情平静、略带冷淡,带有一种漫不经心的疏离感。沙发右侧放有一个浅色陶盘,盘内盛放着三至四颗饱满鲜红的番茄,带有绿色蒂头,色彩鲜艳,与画面整体的冷绿色调形成强烈对比。背景为做旧的青绿色墙面,斑驳而有质感。窗外射入的自然光形成明显的光束,斜斜打在人物与背景上,光影层次丰富。窗台及背景角落摆有数盆绿植,左侧隐约可见一个深棕色老式木柜。整张照片色调偏冷绿,叠有明显的胶片颗粒感与轻微漏光效果,构图饱满,氛围静谧、文艺,带有强烈的复古胶片人文摄影风格。

万相

人像写真

p1023523-转换自-png

写实摄影

p1023409-转换自-png

绘画流派

p1023526-转换自-png

文字生成

p1023535-转换自-png

海报设计

p1023546-转换自-png

组图生成

p1023532-转换自-png

点击查看提示词

人像写真:hyper-realistic Scandinavian woman portrait, flowing platinum blonde hair and piercing blue eyes with prominent freckles, sharp intellectual gaze, Nordic cold-toned directional lighting creating icy atmosphere, minimalist modern styling with clean lines, shallow depth-of-field blurred cold-gradient background, authentic Nordic facial features and porcelain skin texture.

写实摄影:fish-eye perspective forest scene with dramatic perspective distortion, ultra-detailed red fox staring into lens with piercing amber eyes, hyper-realistic fur texture showing individual guard hairs and undercoat layers, radially warped trees forming circular background patterns, watercolor painting style with translucent washes and organic pigment bleeding, soft pastel palette of moss green and earth ochre tones, painterly lighting with atmospheric glow through canopy gaps

绘画流派:Vintage oil painting style pastoral song, a farmer herding sheep across a meadow full of wildflowers, a windmill in the distance turning under blue sky and white clouds, smoke curling from the chimney of a wooden house, bright and soft colors, full of tranquility and comfort.​

文字生成:植物图鉴的一页,手绘水彩风格,描绘了一株“蒲公英”,并标注了它的各个部位名称。

海报设计:Cinematic poster scene: Extreme macro close-up of eye in wooden crack. Minimalist monochrome, watercolor-CGI fusion, low saturation. Slow push-in with tremor for surreal intensity. Vast negative space, hidden title. Optimized for immersive video generation.

组图生成:一位老人的一生回忆,四张不同画框的肖像画,分别描绘他的童年(黑白照片)、青年(军装照)、中年(西装工作照)和晚年(与老伴的合影)。

模型选型

  • wan2.7-image-pro:功能最全面,支持组图生成和高达4096x4096的分辨率,并增强了五官控制、色彩控制和超长文字渲染能力。

  • qwen-image-2.0-pro:擅长文本渲染,能精准生成贴合物理材质的中英文,适合生成图表、海报和PPT等。

  • z-image-turbo:追求速度与性价比。生成速度快、成本低,擅长高逼真度的人像与产品图。

快速开始

前提条件

在调用前,请获取API Key,再配置API Key到环境变量。如果通过DashScope SDK进行调用,还需要安装SDK

示例代码

调用方式说明

万相-异步调用

Python

请求示例
import os
import dashscope
from dashscope.aigc.image_generation import ImageGeneration
from dashscope.api_entities.dashscope_response import Message

# 以下为新加坡地域base_url,各地域的base_url不同
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")


def main():
    message = Message(
        role="user",
        content=[
            {"text": "一位年轻女性,自然随性的自拍风格,超高清写实人物生活照。她身着黄色碎花长袖上衣,长发自然垂落且略带波浪卷。画面背景为户外自然景色,近处有绿植,远处可见水域和山峦。自然柔和的阳光洒在人物脸上和身上,形成自然的光影效果,拍摄机位为人物手持设备的中景自拍视角,人物身体自然站立,展现出轻松自在的状态。角度自然,随手一拍的快照风格,不经意间的抓拍。"}
        ]
    )
    
    # 提交异步任务
    print("提交异步任务...")
    response = ImageGeneration.async_call(
        model="wan2.7-image-pro",
        api_key=api_key,
        messages=[message],
        enable_sequential=False,
        n=1,
        size="2K"
    )
    
    if response.status_code == 200:
        print(f"任务提交成功,任务ID: {response.output.task_id}")
        
        # 等待任务完成
        status = ImageGeneration.wait(task=response, api_key=api_key)
        
        if status.output.task_status == "SUCCEEDED":
            print("任务完成!")
            print(f"结果:")
            print(status)
        else:
            print(f"任务失败,状态: {status.output.task_status}")
    else:
        print(f"任务创建失败: {response.code} - {response.message}")


if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        print(f"错误: {e}")
响应示例

1、创建任务的响应示例

{
    "status_code": 200,
    "request_id": "4fb3050f-de57-4a24-84ff-e37ee5xxxxxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": null,
        "audio": null,
        "task_id": "77093787-a217-4c29-9cd4-ca7b5ac86xxx",
        "task_status": "PENDING"
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "characters": 0
    }
}

2、查询任务结果的响应示例

url 有效期24小时,请及时下载图像。
{
    "status_code": 200,
    "request_id": "56e318fd-ed60-99e8-8ca1-cdef25ca4xxx",
    "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,
        "task_id": "77093787-a217-4c29-9cd4-ca7b5ac86xxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-03-31 23:04:46.166",
        "scheduled_time": "2026-03-31 23:04:46.208",
        "end_time": "2026-03-31 23:05:11.664",
        "finished": true
    },
    "usage": {
        "input_tokens": 720,
        "output_tokens": 11,
        "characters": 0,
        "size": "2048*2048",
        "total_tokens": 731,
        "image_count": 1
    }
}

Java

请求示例
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 {
        // 以下为新加坡地域url,各地域的base_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/zh/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static ImageGenerationResult waitTask(String taskId)
            throws ApiException, NoApiKeyException {
        ImageGeneration imageGeneration = new ImageGeneration();
        return imageGeneration.wait(taskId, apiKey);
    }

    public static void asyncCall() throws ApiException, NoApiKeyException, UploadFileException {
        ImageGenerationMessage message = ImageGenerationMessage.builder()
                .role("user")
                .content(Collections.singletonList(
                        Collections.singletonMap("text", "一位年轻女性,自然随性的自拍风格,超高清写实人物生活照。她身着黄色碎花长袖上衣,长发自然垂落且略带波浪卷。画面背景为户外自然景色,近处有绿植,远处可见水域和山峦。自然柔和的阳光洒在人物脸上和身上,形成自然的光影效果,拍摄机位为人物手持设备的中景自拍视角,人物身体自然站立,展现出轻松自在的状态。角度自然,随手一拍的快照风格,不经意间的抓拍。")
                )).build();

        ImageGenerationParam param = ImageGenerationParam.builder()
                .apiKey(apiKey)
                .model("wan2.7-image-pro")
                .messages(Collections.singletonList(message))
                .enableSequential(false)
                .n(1)
                .size("2K")
                .build();

        ImageGeneration imageGeneration = new ImageGeneration();
        ImageGenerationResult taskResult = null;
        try {
            System.out.println("----async call, creating task----");
            taskResult = imageGeneration.asyncCall(param);
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e.getMessage());
        }
        System.out.println("Task created: " + JsonUtils.toJson(taskResult));

        // 等待任务完成
        String taskId = taskResult.getOutput().getTaskId();
        ImageGenerationResult result = waitTask(taskId);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            asyncCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
    }
}
响应示例

1、创建任务的响应示例

{
    "requestId": "7d026dc1-e8c9-9caa-84ac-e82e2da97xxx",
    "output": {
        "task_id": "2de18c56-c151-4b80-8105-1d164733exxx",
        "task_status": "PENDING"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

2、查询任务结果的响应示例

{
    "requestId": "daea7295-4ce0-928a-9a11-4d2bea058xxx",
    "usage": {
        "input_tokens": 720,
        "output_tokens": 11,
        "total_tokens": 731,
        "image_count": 1,
        "size": "2048*2048"
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxxxxx.png?Expires=xxxxxx",
                            "type": "image"
                        }
                    ]
                }
            }
        ],
        "task_id": "2de18c56-c151-4b80-8105-1d164733exxx",
        "task_status": "SUCCEEDED",
        "finished": true,
        "submit_time": "2026-03-31 19:49:53.124",
        "scheduled_time": "2026-03-31 19:49:53.175",
        "end_time": "2026-03-31 19:50:53.160"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

curl

说明
  • 异步调用必须设置 Header 参数X-DashScope-Asyncenable

  • 异步任务的 task_id 查询有效期为 24 小时,过期后任务状态将变为 UNKNOWN

步骤1:发起创建任务请求

该请求会返回一个任务ID(task_id)。

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.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.7-image-pro",
        "input": {
            "messages": [
                {
                    "role": "user",
                    "content": [
                        {"text": "一间有着精致窗户的花店,漂亮的木质门,摆放着花朵"}
                    ]
                }
            ]
        },
        "parameters": {
            "size": "2K",
            "n": 1,
            "watermark": false,
            "thinking_mode": true
        }
    }'
    
步骤2:根据任务ID查询结果

使用上一步获取的 task_id,通过接口轮询任务状态,直到 task_status 变为 SUCCEEDED 或 FAILED。

{task_id}完整替换为上一步接口返回的task_id的值。task_id查询有效期为24小时。

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

千问-同步调用

Python

请求示例

import json
import os
import dashscope
from dashscope import MultiModalConversation

# 以下为新加坡地域URL,调用时请将WorkspaceId替换为真实的业务空间ID,各地域的URL不同。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.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 Key不同。获取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# 若没有配置环境变量,请用百炼API Key将下行替换为: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="低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。",
    size='2048*2048'
)

if response.status_code == 200:
    print(json.dumps(response, ensure_ascii=False))
else:
    print(f"HTTP返回码:{response.status_code}")
    print(f"错误码:{response.code}")
    print(f"错误信息:{response.message}")
    print("请参考文档:https://www.alibabacloud.com/help/zh/model-studio/error-code")

响应示例

图像链接的有效期为24小时,请及时下载图像。
{
    "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

请求示例

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 {
        // 以下为新加坡地域URL,调用时请将WorkspaceId替换为真实的业务空间ID,各地域的URL不同。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // 新加坡和北京地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/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", "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", "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有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);
    }

响应示例

图像链接的有效期为24小时,请及时下载图像。
{
    "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

请求示例
curl --location 'https://{WorkspaceId}.cn-beijing.maas.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": "冬日北京的都市街景,青灰瓦顶、朱红色外墙的两间相邻中式商铺比肩而立,檐下悬挂印有剪纸马的暖光灯笼,在阴天漫射光中投下柔和光晕,映照湿润鹅卵石路面泛起细腻反光。左侧为书法店:靛蓝色老旧的牌匾上以遒劲行书刻着“文字渲染”。店门口的玻璃上挂着一幅字,自上而下,用田英章硬笔写着“专业幻灯片 中英文海报 高级信息图”,落款印章为“1k token”朱砂印。店内的墙上,可以模糊的辨认有三幅竖排的书法作品,第一幅写着“阿里巴巴”,第二幅写着“通义千问”,第三幅写着“图像生成”。一位白发苍苍的老人背对着镜头观赏。右侧为花店,牌匾上以鲜花做成文字“真实质感”;店内多层花架陈列红玫瑰、粉洋牡丹和绿植,门上贴了一个圆形花边标识,标识上写着“2k resolution”,门口摆放了一个彩色霓虹灯,上面写着“细腻刻画 人物 自然 建筑”。两家店中间堆放了一个雪人,举了一老式小黑板,上面用粉笔字写着“Qwen-Image-2.0 正式发布”。街道左侧,年轻情侣依偎在一起,女孩是瘦脸,身穿米白色羊绒大衣,肉色光腿神器。女孩举着心形透明气球,气球印有白色的字:“生图编辑二合一”。里面有一个毛茸茸的卡皮巴拉玩偶。男孩身着剪裁合体的深灰色呢子外套,内搭浅色高领毛衣。街道右侧,一个后背上写着“更小模型,更快速度”的骑手疾驰而过。整条街光影交织、动静相宜。"
                    }
                ]
            }
        ]
    },
    "parameters": {
        "negative_prompt": "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。",
        "prompt_extend": true,
        "watermark": false,
        "size": "2048*2048"
    }
}'
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.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": "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲。",
      "prompt_extend": true,
      "watermark": false,
      "size": "2048*2048"
    }
}'
响应示例
{
    "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"
}

关键能力

1. 指令遵循(提示词)

参数:messages.content.textinput.prompt(必选)、negative_prompt(可选)。

  • text \ prompt(正向提示词):描述希望在画面中看到的内容、主体、场景、风格、光照和构图。文生图的核心控制参数。

  • negative_prompt(反向提示词):描述不希望在画面中出现的内容,如“模糊”、“多余的手指”等。仅用于辅助优化生成质量。

撰写技巧:一个结构化的 Prompt 通常能带来更好的效果,撰写技巧请参见文生图Prompt指南

wan2.7-image-pro、wan2.7-image不支持negative_prompt参数,对于不希望出现的元素,请在正向提示词中描述(不要出现xxx)。

2. 开启prompt智能改写

参数: parameters.prompt_extend (bool, 默认为 true)。

此功能可自动扩展和优化较短的Prompt,提升出图效果。开启此功能额外耗时 3-5 秒。此耗时为使用大模型改写文本。

实践建议:

  • 建议开启:当输入 Prompt 较简洁或宽泛时,此功能可显著提升图像效果。

  • 建议关闭:若需控制画面细节、或已提供详细描述,或对响应延迟敏感。请将参数 prompt_extend 显式设为 false

wan2.7-image-pro、wan2.7-image不支持prompt_extend参数,可通过开启thinking_mode提升出图质量。

3. 设置输出图像分辨率

参数: parameters.size (string),格式为 "宽*高"

模型

size格式

总像素支持范围

默认

宽高比

wan2.7-image-pro

缩写

1K(1024*1024)、2K(2048*2048)、4K(4096*4096)

2K(2048*2048)

1:8 – 8:1

自定义 "宽*高"

768*768 – 4096*4096

wan2.7-image

缩写

1K(1024*1024)、2K(2048*2048)

2K(2048*2048)

1:8 – 8:1

自定义 "宽*高"

768*768 – 2048*2048

wan2.6-image(图文混排输出模式)

自定义 "宽*高"

768*768 – 1280*1280

匹配输入宽高比 (≤1280*1280)

1:4 – 4:1

wan2.6-t2i, wan2.5-t2i-preview

自定义 "宽*高"

1280*1280 – 1440*1440

1280*1280

1:4 – 4:1

wan2.2 及更早的 t2i 模型

自定义 "宽*高"

[512, 1440],且总像素 ≤1440*1440

1024*1024

-

qwen-image-2.0 系列

自定义 "宽*高"

512*512 – 2048*2048

2048*2048

-

qwen-image-max / qwen-image-plus 系列

仅限固定预设尺寸

见下方预设尺寸

1664*928 (16:9)

-

wan2.7-image-pro仅文生图场景(无图片输入、非组图生成)支持4K与自定义4096*4096分辨率,其余场景仅支持2K与2048*2048分辨率。

qwen-image-max、qwen-image-plus 系列:仅支持以下 5 种固定的分辨率:

  • 1664*928(默认值):16:9

  • 1472*1104:4:3

  • 1328*1328:1:1

  • 1104*1472:3:4

  • 928*1664:9:16

推荐分辨率:

宽高比

4K (wan2.7-image-pro)

2K (wan2.7-image, qwen-image-2.0)

1K (Wan t2i)

1:1

4096*4096

2048*2048

1280*1280

16:9

4096*2304

2688*1536

1696*960

9:16

2304*4096

1536*2688

960*1696

4:3

4096*3072

2368*1728

1472*1104

3:4

3072*4096

1728*2368

1104*1472

4. 组图生成

参数:parameters.enable_sequential(bool,默认为 false)。仅wan2.7-image-prowan2.7-image支持。

设为true时启用组图模式,模型将根据提示词和参考图片的内容一次性生成多张有故事连贯性的图像。

  • 生成数量:通过n参数控制,开启组图模式时,取值范围1~12(默认12),实际数量由模型决定且不超过n。

  • 注意:开启组图模式时,thinking_modecolor_palette参数不可用。

5. 思考模式

参数:parameters.thinking_mode(bool,默认为 true)。仅wan2.7-image-prowan2.7-image支持。

开启时,模型将增强推理能力以提升出图质量,但会增加生成耗时。

仅在关闭组图模式(enable_sequential=false)时可用。

6. 自定义颜色主题

参数:parameters.color_palette(array)。仅wan2.7-image-prowan2.7-image支持。

通过传入包含颜色(hex)和占比(ratio)的对象数组,自定义生成图像的颜色方案。需包含3至10种颜色,推荐设置为8种。所有ratio值相加总和必须为100.00%。

仅在关闭组图模式(enable_sequential=false)时可用。

点击查看输入示例

"color_palette": [
    {
        "hex": "#C2D1E6",
        "ratio": "23.51%"
    },
    {
        "hex": "#CDD8E9",
        "ratio": "20.13%"
    },
    {
        "hex": "#B5C8DB",
        "ratio": "15.88%"
    },
    {
        "hex": "#C0B5B4",
        "ratio": "13.27%"
    },
    {
        "hex": "#DAE0EC",
        "ratio": "10.11%"
    },
    {
        "hex": "#636574",
        "ratio": "8.93%"
    },
    {
        "hex": "#CACAD2",
        "ratio": "5.55%"
    },
    {
        "hex": "#CBD4E4",
        "ratio": "2.62%"
    }
]

应用于生产环境

  • 容错策略

    • 处理限流:当 API 返回 Throttling 错误码或 HTTP 429 状态码时,表明已触发限流,限流处理请参见限流

    • 异步任务轮询:轮询查询异步任务结果时,建议采用合理的轮询策略(如前30秒每3秒一次,之后拉长间隔),避免因过于频繁的请求而触发限流。为任务设置一个最终超时时间(如 2 分钟),超时后标记为失败。

  • 风险防范

    • 结果持久化:API 返回的图片 URL 有 24 小时有效期。生产系统必须在获取 URL 后立即下载图片,并转存至您自己的持久化存储服务中(如阿里云对象存储 OSS)。

    • 内容安全审核:所有 promptnegative_prompt 都会经过内容安全审核。若输入内容不合规,请求将被拦截并返回 DataInspectionFailed 错误。

    • 生成内容的版权与合规风险:请确保您的提示词内容符合相关法律法规。生成包含品牌商标、名人肖像、受版权保护的 IP 形象等内容可能涉及侵权风险,请您自行评估并承担相应责任。

API文档

计费与限流

  • 模型免费额度和计费单价请参见模型价格

  • 模型限流请参见限流-图像生成

  • 计费说明:按成功生成的 图像张数 计费。模型调用失败或处理错误不产生任何费用,也不消耗新人免费额度

错误码

如果模型调用失败并返回报错信息,请参见错误码进行解决。

常见问题

Q: 图片 URL 多久会失效?我应该如何永久保存图片?

A: 图片 URL 的有效期为 24 小时。您必须在获取到 URL 后,立即通过程序下载图片,并将其保存到您自己的持久化存储中,例如本地服务器或阿里云对象存储 OSS。

Q: 调用API返回DataInspectionFailed错误,如何处理?

A: 该错误表示输入文本触发了内容安全审核。请检查并修改prompt或negative_prompt中的文本,移除可能违规的内容后重试。

Q: prompt_extend参数应该开启还是关闭?

A: 当输入的prompt比较简洁或希望模型发挥更多创意时,建议保持开启(默认)。当prompt已经非常详细、专业,或对API响应延迟有严格要求时,建议显式设置为false。

注意:wan2.7-image-pro、wan2.7-image不支持prompt_extend参数,可通过开启thinking_mode提升出图质量。