> ## Documentation Index
> Fetch the complete documentation index at: https://docs.powertokens.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 千问-文生图

> 调用阿里云千问 `qwen-image-2.0-pro` 模型执行文生图任务。

请求体包含 `model`、`input`、`parameters` 三个主要字段。`input.messages[0].content[0].text` 放置正向提示词。`parameters` 字段控制分辨率 `size`、数量 `n`、反向提示词 `negative_prompt`、提示词智能改写 `prompt_extend`、水印 `watermark`、随机种子 `seed` 等。



## OpenAPI

````yaml api-reference/zh-Hans/zmodelImage/ali/api/qwen-text-to-image.json POST /ali/api/v1/services/aigc/multimodal-generation/generation
openapi: 3.0.1
info:
  title: 千问-文生图
  version: 1.0.0
  description: >-
    阿里云千问文生图能力文档。平台统一接口端点为
    `/ali/api/v1/services/aigc/multimodal-generation/generation`。本文档描述了
    `qwen-image-2.0-pro` 模型的文生图调用契约：`input.messages[].content[].text`
    携带正向提示词，`parameters` 控制图像分辨率、数量、反向提示词等参数。
  license:
    name: Project License
    url: https://github.com/QuantumNous/new-api/blob/main/LICENSE
servers:
  - url: https://api.powertokens.ai
    description: baze平台 API 服务端点
security: []
tags:
  - name: Qwen Image
    description: 千问文生图能力
paths:
  /ali/api/v1/services/aigc/multimodal-generation/generation:
    post:
      tags:
        - Qwen Image
      summary: 千问-文生图
      description: >-
        调用阿里云千问 `qwen-image-2.0-pro` 模型执行文生图任务。


        请求体包含 `model`、`input`、`parameters`
        三个主要字段。`input.messages[0].content[0].text` 放置正向提示词。`parameters` 字段控制分辨率
        `size`、数量 `n`、反向提示词 `negative_prompt`、提示词智能改写 `prompt_extend`、水印
        `watermark`、随机种子 `seed` 等。
      operationId: aliQwenTextToImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TextToImageRequest'
            examples:
              qwen_image_2_pro_generation:
                summary: Qwen-Image-2.0 Pro 文生图
                value:
                  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
      responses:
        '200':
          description: 成功返回图像生成结果。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
              examples:
                success:
                  summary: 成功响应
                  value:
                    request_id: d0250a3d-b07f-49e1-bdc8-6793f4929xxx
                    output:
                      choices:
                        - message:
                            role: assistant
                            content:
                              - image: >-
                                  https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx
                          finish_reason: stop
                    usage:
                      image_count: 1
                      height: 2048
                      width: 2048
        '400':
          description: 请求参数无效。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: 认证失败，例如缺少或无效的令牌。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '413':
          description: 请求体过大。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: 触发限流或账户额度不足。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: 处理请求时发生内部服务器错误。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '502':
          description: 上游渠道返回了异常响应。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: 上游渠道暂时不可用，或当前模型无可用渠道。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    TextToImageRequest:
      type: object
      required:
        - model
        - input
      properties:
        model:
          type: string
          enum:
            - qwen-image-2.0-pro
          description: 模型名称。示例值：`qwen-image-2.0-pro`。
        input:
          $ref: '#/components/schemas/QwenTextToImageInput'
        parameters:
          $ref: '#/components/schemas/QwenTextToImageParameters'
    ImageResponse:
      type: object
      properties:
        output:
          $ref: '#/components/schemas/ImageOutput'
          description: 任务输出信息。
        usage:
          $ref: '#/components/schemas/ImageUsage'
        request_id:
          type: string
          description: 请求唯一标识。可用于请求明细溯源和问题排查。
        code:
          type: string
          description: 错误码，仅在请求失败时返回。
        message:
          type: string
          description: 错误信息，仅在请求失败时返回。
    ErrorResponse:
      type: object
      properties:
        code:
          type: string
          description: 请求失败的错误码。请求成功时不会返回此参数。
        message:
          type: string
          description: 请求失败的详细信息。请求成功时不会返回此参数。
        request_id:
          type: string
          description: 请求唯一标识。可用于请求明细溯源和问题排查。
    QwenTextToImageInput:
      type: object
      required:
        - messages
      properties:
        messages:
          type: array
          minItems: 1
          maxItems: 1
          description: 请求内容数组。当前仅支持单轮对话，数组内有且只有一个元素。
          items:
            $ref: '#/components/schemas/QwenTextToImageMessage'
      description: 输入的基本信息。
    QwenTextToImageParameters:
      type: object
      properties:
        negative_prompt:
          type: string
          maxLength: 500
          description: >-
            反向提示词，用于描述不希望在图像中出现的内容，对画面进行限制。支持中英文，长度不超过 500
            个字符，超出部分将自动截断。示例值：低分辨率，低画质，肢体畸形，手指畸形，画面过饱和，蜡像感，人脸无细节，过度光滑，画面具有AI感。构图混乱。文字模糊，扭曲。
        size:
          type: string
          description: >-
            输出图像的分辨率，格式为 `宽*高`。`qwen-image-2.0` 系列模型输出图像总像素需在 `512*512` 至
            `2048*2048` 之间，默认分辨率为
            `2048*2048`。推荐分辨率：`2688*1536`（16:9）、`1536*2688`（9:16）、`2048*2048`（1:1，默认值）、`2368*1728`（4:3）、`1728*2368`（3:4）。
        'n':
          type: integer
          minimum: 1
          maximum: 6
          default: 1
          description: 输出图像的数量，默认值为 1。对于 `qwen-image-2.0` 系列模型，可选择输出 1-6 张图片。
        prompt_extend:
          type: boolean
          default: true
          description: >-
            是否开启
            Prompt（提示词）智能改写功能。开启后模型将对正向提示词进行优化与润色，此功能不会修改反向提示词。`true`：默认值，开启智能改写。如果希望图像内容更多样化，由模型补充细节，建议开启此选项。`false`：关闭智能改写。如果希望图像细节更可控，建议关闭此选项。当前仅异步接口返回实际提示词。
        watermark:
          type: boolean
          default: false
          description: 是否在图像右下角添加 "Qwen-Image" 水印。默认值为 `false`。
        seed:
          type: integer
          format: int64
          minimum: 0
          maximum: 2147483647
          description: >-
            随机数种子，取值范围 [0, 2147483647]。使用相同的 `seed`
            参数值可使生成内容保持相对稳定。若不提供，算法将自动使用随机数种子。注意：模型生成过程具有概率性，即使使用相同的
            `seed`，也不能保证每次生成结果完全一致。
      description: 图像处理参数。
    ImageOutput:
      type: object
      properties:
        choices:
          type: array
          description: 模型生成的输出内容。此数组仅包含一个元素。
          items:
            $ref: '#/components/schemas/ImageChoice'
    ImageUsage:
      type: object
      properties:
        image_count:
          type: integer
          description: 模型生成图像的数量，当前固定为 1。
        width:
          type: integer
          description: 模型生成图像的宽度（像素）。
        height:
          type: integer
          description: 模型生成图像的高度（像素）。
      description: 输出信息统计。只对成功的结果计数。
    QwenTextToImageMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
          description: 消息的角色。此参数必须设置为 `user`。
        content:
          type: array
          minItems: 1
          maxItems: 1
          description: 消息内容数组。仅支持传入一个 `text`，不传或传入多个将报错。
          items:
            $ref: '#/components/schemas/QwenTextToImageContentItem'
    ImageChoice:
      type: object
      properties:
        finish_reason:
          type: string
          description: 任务停止原因，自然停止时为 `stop`。
        message:
          $ref: '#/components/schemas/ImageChoiceMessage'
    QwenTextToImageContentItem:
      type: object
      required:
        - text
      properties:
        text:
          type: string
          description: >-
            正向提示词用于描述您期望生成的图像内容、风格和构图。支持中英文，`qwen-image-2.0` 系列模型长度上限为 1300
            Token，其他模型为 800 Token，超出部分将自动截断。
    ImageChoiceMessage:
      type: object
      properties:
        role:
          type: string
          description: 消息的角色，固定为 `assistant`。
        content:
          type: array
          description: 模型返回的消息内容数组。
          items:
            $ref: '#/components/schemas/ImageChoiceContentItem'
      description: 模型返回的消息。
    ImageChoiceContentItem:
      type: object
      properties:
        image:
          type: string
          description: 生成图像的 URL，图像格式为 PNG。链接有效期为 24 小时，请及时下载并保存图像。
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: '在请求头中传递 `Authorization: Bearer <token>`。'

````