Logo for AiToolGo

Text-to-Image API Guide: Create AI Images with Wan and Qwen-Image Models

In-depth discussion
Technical
 0
 0
 5
该文档介绍阿里云百炼平台的文生图 API,支持通义万相(Wan)、千问(Qwen-Image)和 z-image 系列模型。内容涵盖在线体验入口、模型效果展示、模型选型建议(qwen-image-3.0-pro/2.1-pro/2.1-turbo)、快速开始的 Python 示例代码,以及提示词撰写、智能改写(prompt_extend)、分辨率设置、组图生成、思考模式、自定义颜色主题、水印等关键参数说明。另包含生产环境注意事项(图片URL 24小时有效期、内容安全审核、版权合规)、错误码与常见问题。整体偏官方 API 参考与操作指南性质。
  • main points
  • unique insights
  • practical applications
  • key topics
  • key insights
  • learning outcomes
  • • main points

    • 1
      参数体系完整:覆盖提示词、智能改写、分辨率、组图、思考模式、颜色主题等关键能力,并给出各模型支持范围的明确对比
    • 2
      提供可直接运行的 Python 示例代码与推荐分辨率表,便于快速上手
    • 3
      包含生产环境实践指引,如图片 URL 失效处理、轮询策略、限流应对与内容安全审核说明
  • • unique insights

    • 1
      明确区分 prompt_extend_mode 的 direct(DPE)与 agent(APE)两种增强方式及其适用场景(agent 仅支持文生图)
    • 2
      指出文本渲染的局限(长文本易出现错字漏字),并给出缩短画面文字或后期编辑的务实建议
  • • practical applications

    • 对需要在自有应用中集成文生图能力的开发者具有较高参考价值,可据此快速完成模型选型、参数配置与生产化部署(包括图片转存与容错设计)。
  • • key topics

    • 1
      文生图模型选型与效果对比(Qwen-Image 与万相系列)
    • 2
      提示词撰写与智能改写参数(prompt_extend)
    • 3
      分辨率、组图生成、思考模式与颜色主题等生成控制参数
    • 4
      生产环境容错、图片持久化与内容安全合规
  • • key insights

    • 1
      一站式覆盖从在线体验、API 集成到生产部署的完整链路
    • 2
      明确列出不同模型对各参数的支持差异,降低踩坑成本
    • 3
      给出 4K/2K/1K 多宽高比推荐分辨率,便于直接套用
  • • learning outcomes

    • 1
      掌握通过 DashScope SDK 调用文生图 API 的基本流程与关键参数
    • 2
      能够根据需求在 qwen-image 与万相系列模型之间进行合理选型
    • 3
      理解提示词撰写技巧、智能改写的启用策略及生产环境的容错与合规要点
examples
tutorials
code samples
visuals
fundamentals
advanced content
practical tips
best practices

“ Introduction to Text-to-Image Generation with Model Studio

The text-to-image API lets developers create entirely new images from written descriptions. Alibaba Cloud Model Studio (Bailian) offers the Wan (万相), Qwen-Image (千问) and z-image model families, making it straightforward to add AI image generation to websites, design tools, marketing workflows and creative apps. This guide explains how to get started, choose a suitable model, control output quality, and prepare the integration for production use.

“ Try It Out: Online Experience Center

Before writing any code, you can test generation in the web-based Experience Center, available in the Beijing and Singapore regions. Enter a text description, choose a model, set the output resolution, toggle smart rewriting, and submit. The Tongyi Wanxiang standalone site also offers direct image generation. When you are ready to embed the capability in your own product, switch to the API calls described below.

“ Choosing the Right Model

Model Studio currently recommends three Qwen-Image options. qwen-image-3.0-pro delivers flagship quality, supports intelligent prompt rewriting, and excels at accurate Chinese and English text rendering with realistic materials. qwen-image-2.1-pro balances speed, quality and cost, and supports up to ten reference images for image-to-image tasks. It can automatically output either standard images or images with transparency depending on the prompt. qwen-image-2.1-turbo offers the best cost-performance ratio in the series and shares the same reference-image and transparency capabilities. Select the model that matches your quality target, latency tolerance and budget.

“ Quick Start: Prerequisites and Sample Code

Before calling the API, obtain an API key and set it as an environment variable. If you use the DashScope SDK, install it first. The example below uses synchronous calling with the qwen-image-3.0-pro model through MultiModalConversation. The response contains an image URL that can be retrieved from the output. Qwen-Image also supports asynchronous calling, and Wan models have their own API references. Check the response status code and handle errors using the returned code and message fields.

“ Controlling Output: Prompts and Prompt Rewriting

The positive prompt (text in messages or prompt in input) is the core control parameter. Describe the subject, scene, style, lighting and composition you want. The optional negative_prompt describes unwanted elements such as blur or extra fingers. Note that wan2.7-image-pro, wan2.7-image and qwen-image-2.1 series do not accept negative_prompt, so express exclusions directly in the positive prompt. Text rendering inside images works for short titles and phrases, but long passages or full poems may contain typos or missing characters. For critical text, keep it short or edit the result afterward. Prompt rewriting, enabled with prompt_extend, expands short or vague prompts and typically adds three to five seconds of latency. Keep it on for concise inputs and turn it off when your prompt is already detailed or when latency is critical. Qwen-Image 3.0 and 2.1 series also accept prompt_extend_mode, where direct is suitable for most scenarios and agent offers finer rewriting for text-to-image only.

“ Resolution, Aspect Ratios, and Image Sets

Set the output size with the size parameter in the format width*height. Qwen-Image 3.0 and 2.1 series accept sizes from 512x512 to 2048x2048 with aspect ratios between 1:8 and 8:1, and the model picks a recommended size if none is specified. Qwen-Image 2.0 defaults to 2048x2048. wan2.7-image-pro supports 1K, 2K and 4K presets or custom sizes from 768x768 to 4096x4096, with 2K as the default. The 4K and custom 4096x4096 options are available only for text-to-image requests without image inputs or sequential generation. wan2.7-image supports 1K and 2K presets or custom sizes up to 2048x2048. Recommended pixel sizes include 2048x2048 for square 2K, 2688x1536 for 16:9 at 2K, and 4096x2304 for 16:9 at 4K. For storytelling or consistent series, enable sequential generation with enable_sequential set to true. The n parameter controls how many images are produced, from 1 to 12 in set mode. Billing is based on the number of successfully generated images, so n directly affects cost.

“ Advanced Features: Thinking Mode and Color Palettes

For wan2.7-image-pro and wan2.7-image, thinking_mode (enabled by default) strengthens reasoning to improve output quality at the cost of additional generation time. This setting can replace prompt_extend for these models, which do not support that parameter. Custom color palettes are available through color_palette, where you provide between three and ten colors in hex format, each with a ratio, and the ratios must total 100 percent. The recommended palette size is eight colors. Note that thinking_mode and color_palette cannot be used together with sequential image set generation.

“ Common Parameters for Consistent Results

Several general parameters help you control repeatability and presentation. seed accepts an integer between 0 and 2147483647, and reusing the same seed produces relatively stable results. If no seed is provided, the service chooses one randomly. watermark, which defaults to false, adds an AI-generated label to the bottom-right corner of the image when enabled. The n parameter sets the number of images, as described earlier. Check each model's API reference to confirm which parameters are supported.

“ Building Production-Ready Applications

Production systems need robust handling. When the API returns a Throttling error code or HTTP 429, apply rate-limit handling as described in the rate-limit documentation. For asynchronous tasks, poll results with a sensible strategy, such as checking every three seconds for the first thirty seconds and then increasing the interval, and set a final timeout, for example two minutes, after which the task is marked failed. Image URLs expire after 24 hours, so download each image immediately and store it in persistent storage such as Alibaba Cloud Object Storage Service (OSS). All prompts and negative prompts pass content safety review, and non-compliant inputs return a DataInspectionFailed error. Ensure your prompts comply with applicable laws, and carefully evaluate copyright and portrait-rights risks before generating brand logos, celebrity likenesses or protected characters.

“ FAQ and Error Handling

Image URLs remain valid for 24 hours, so save them permanently right after generation. If a request fails with DataInspectionFailed, revise the prompt to remove potentially non-compliant content and retry. For prompt_extend, keep it enabled for brief prompts or when creative variation is welcome, and set it explicitly to false for detailed prompts or strict latency requirements. Models that do not support prompt_extend can use thinking_mode instead. To clear the conversation in the Experience Center, click the clear control at the top right of the console. For any other model error, consult the error code reference and the official API documentation.

 Original link: https://help.aliyun.com/zh/model-studio/text-to-image

Comment(0)

user's avatar

      Related Tools