> ## 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 文生图

> 调用 Ali `qwen-image-2.0-pro` 执行文生图。

公开调用方案保留顶层 `model`、`input`、`response_format`，并将 `n`、`size`、`negative_prompt`、`prompt_extend`、`watermark`、`seed` 设计为顶层字段。提示词位于 `input.messages[0].content[0].text`。请求体不接受顶层 `parameters`。



## OpenAPI

````yaml api-reference/zh-Hans/zmodelImage/ali/qwen-text-to-image.json POST /v1/images/generations
openapi: 3.0.1
info:
  title: Qwen 文生图
  version: 1.0.0
  description: >-
    阿里 Qwen 文生图能力文档。公开统一入口为 `/v1/images/generations`，当前文档描述 `qwen-image-2.0-pro`
    对外公开的网关契约：保留 `input.messages[].content[].text` 承载提示词，其余控制字段使用顶层 OpenAI
    风格字段，由网关映射到上游 `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: Qwen 文生图能力
paths:
  /v1/images/generations:
    post:
      tags:
        - Qwen Image
      summary: Qwen 文生图
      description: >-
        调用 Ali `qwen-image-2.0-pro` 执行文生图。


        公开调用方案保留顶层 `model`、`input`、`response_format`，并将
        `n`、`size`、`negative_prompt`、`prompt_extend`、`watermark`、`seed`
        设计为顶层字段。提示词位于 `input.messages[0].content[0].text`。请求体不接受顶层 `parameters`。
      operationId: aliQwenTextToImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TextToImageRequest'
            examples:
              basic_generation:
                summary: 基础文生图
                value:
                  model: qwen-image-2.0-pro
                  response_format: url
                  input:
                    messages:
                      - role: user
                        content:
                          - text: 一只可爱的橘猫坐在窗台上，阳光洒在身上，写实风格
                  size: 2048*2048
                  'n': 1
                  watermark: false
              advanced_generation:
                summary: 高级参数文生图
                value:
                  model: qwen-image-2.0-pro
                  response_format: url
                  input:
                    messages:
                      - role: user
                        content:
                          - text: 科幻风格的城市夜景，霓虹灯光，未来感建筑
                  size: 2048*1024
                  'n': 2
                  negative_prompt: 低分辨率，低画质，模糊
                  prompt_extend: true
                  watermark: false
                  seed: 0
      responses:
        '200':
          description: 调用成功，返回图像生成结果。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
        '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`。
        response_format:
          type: string
          enum:
            - url
            - b64_json
          description: 响应格式。`url` 返回图片下载链接；`b64_json` 返回 Base64 编码的图片数据。默认值为 `url`。
          default: url
        input:
          $ref: '#/components/schemas/QwenTextToImageInput'
        'n':
          type: integer
          minimum: 1
          maximum: 6
          description: 输出图像数量，默认值为 1。对于 `qwen-image-2.0` 系列模型，可选择输出 1-6 张图片。
        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）。
          x-options:
            - label: 512*512
              value: 512*512
            - label: 1K
              value: 1000*1000
            - label: 2K
              value: 2000*2000
          default: 512*512
        negative_prompt:
          type: string
          description: >-
            反向提示词，用于描述不希望在图像中出现的内容，对画面进行限制。支持中英文，长度不超过 500
            个字符，超出部分将自动截断。示例值：低分辨率，低画质，肢体畸形，手指畸形，画面过饱和，蜡像感，人脸无细节，过度光滑，画面具有AI感。构图混乱。文字模糊，扭曲。
        prompt_extend:
          type: boolean
          description: |-
            是否开启 Prompt（提示词）智能改写功能。开启后模型将对正向提示词进行优化与润色。此功能不会修改反向提示词。

            true：默认值，开启智能改写。如果希望图像内容更多样化，由模型补充细节，建议开启此选项。

            false：关闭智能改写。如果图像细节更可控，建议关闭此选项
        watermark:
          type: boolean
          description: 是否在图像右下角添加 "Qwen-Image" 水印。默认值为 `false`。
          default: false
        seed:
          type: integer
          format: int64
          description: >-
            随机数种子，取值范围 [0, 2147483647]。使用相同的 `seed`
            参数值可使生成内容保持相对稳定。若不提供，算法将自动使用随机数种子。注意：模型生成过程具有概率性，即使使用相同的
            `seed`，也不能保证每次生成结果完全一致。
          default: 0
          minimum: 0
    ImageResponse:
      type: object
      properties:
        created:
          type: integer
          format: int64
          description: 响应生成时间戳。
        data:
          type: array
          description: 生成后的图片结果列表。
          items:
            $ref: '#/components/schemas/ImageData'
        metadata:
          type: object
          description: 透传的上游原始响应元数据。
    ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ErrorObject'
    QwenTextToImageInput:
      type: object
      required:
        - messages
      properties:
        messages:
          type: array
          minItems: 1
          maxItems: 1
          description: 请求内容数组。当前仅支持单轮对话，数组内有且只有一个元素。
          items:
            $ref: '#/components/schemas/QwenTextToImageMessage'
    ImageData:
      type: object
      properties:
        url:
          type: string
          description: 当结果以 URL 返回时使用。
        b64_json:
          type: string
          description: 当结果以 Base64 返回时使用。
        revised_prompt:
          type: string
          description: 上游返回的改写提示词。
    ErrorObject:
      type: object
      properties:
        message:
          type: string
        type:
          type: string
        param:
          type: string
        code:
          type: string
    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'
    QwenTextToImageContentItem:
      type: object
      required:
        - text
      properties:
        text:
          type: string
          description: >-
            正向提示词，用于描述您期望生成的图像内容、风格和构图。支持中英文，`qwen-image-2.0` 系列模型长度上限为 1300
            Token，其他模型为 800 Token，超出部分将自动截断。
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: '在请求头中传入 `Authorization: Bearer <token>`。'

````