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

# 生成图片

> 根据提示词生成图片。请求是同步的，生成完成后在响应中返回图片链接，请及时下载保存。只支持文生图，不支持图片编辑。



## OpenAPI

````yaml /openapi/zh/qwen-image-2-1-pro.json post /v1/images/generations
openapi: 3.1.0
info:
  title: Qwen-Image 2.1 Pro
  version: v1
  description: Qwen-Image 2.1 Pro：Qwen-Image 2.1 的完整版，画质、细节和文字渲染优于 Turbo。
servers:
  - url: https://api.dreamto.ai
security:
  - bearerAuth: []
tags:
  - name: Qwen-Image 2.1 Pro
paths:
  /v1/images/generations:
    post:
      tags:
        - Qwen-Image 2.1 Pro
      summary: 生成图片
      description: 根据提示词生成图片。请求是同步的，生成完成后在响应中返回图片链接，请及时下载保存。只支持文生图，不支持图片编辑。
      operationId: qwenImageGenerate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QwenImageGenerationRequest'
            examples:
              文生图:
                summary: 文生图
                value:
                  model: qwen-image-2.1-pro
                  prompt: 一张电影感的城市夜景海报，顶部写着“夜行”
                  size: 1024x1024
              一次生成多张:
                summary: 一次生成多张
                value:
                  model: qwen-image-2.1-pro
                  prompt: 水彩风格的山间小屋，清晨薄雾
                  size: 1536x1024
                  'n': 2
      responses:
        '200':
          description: 生成成功。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QwenImageResponse'
              examples:
                example:
                  value:
                    created: 1795963958
                    data:
                      - url: >-
                          https://api.dreamto.ai/v1/media/dtm_0123456789abcdef0123456789abcdef
                    usage:
                      image_count: 1
                      width: 1024
                      height: 1024
        '400':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: invalid_request
                      http_status: 400
                      message: Invalid request.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: invalid_request_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 参数错误：缺少必填参数、取值不合法或传入了不支持的参数。不扣费。
        '401':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: unauthorized
                      http_status: 401
                      message: Unauthorized.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: authentication_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: API Key 缺失或无效。
        '402':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: insufficient_balance
                      http_status: 402
                      message: Insufficient balance.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: insufficient_balance_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 余额不足。
        '429':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: rate_limit_exceeded
                      http_status: 429
                      message: Rate limit exceeded. Please try again later.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: rate_limit_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 请求过于频繁，请稍后重试。
        '502':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: service_unavailable
                      http_status: 502
                      message: Service temporarily unavailable. Please try again later.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: api_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 上游生成失败（含内容审核拒绝），不扣费，可重试。
components:
  schemas:
    QwenImageGenerationRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          type: string
          enum:
            - qwen-image-2.1-pro
          description: 模型名称。
        prompt:
          type: string
          description: 描述要生成的图片，中英文均可。要写进图里的文字用引号标出。
        size:
          type: string
          description: >-
            输出尺寸，格式 `宽x高`。总像素 512×512 到 2048×2048，宽高比 1:8 到
            8:1；不传时模型按提示词推荐尺寸。常用：`1024x1024`、`1536x1024`、`1024x1536`、`1472x1104`、`1104x1472`、`1664x928`、`928x1664`、`2048x2048`。
          example: 1024x1024
        'n':
          type: integer
          minimum: 1
          maximum: 6
          default: 1
          description: 一次生成的张数，1 ~ 6，默认 1。按张计费。
      additionalProperties: false
    QwenImageResponse:
      type: object
      required:
        - data
      properties:
        created:
          type: integer
          description: 创建时间（Unix 秒）。
        data:
          type: array
          description: 生成的图片。
          items:
            type: object
            required:
              - url
            properties:
              url:
                type: string
                description: 图片链接。
        usage:
          type: object
          description: 用量。
          properties:
            image_count:
              type: integer
              description: 生成的张数（按张计费）。
            width:
              type: integer
              description: 图片宽度（像素）。
            height:
              type: integer
              description: 图片高度（像素）。
    ImageAPIErrorResponse:
      additionalProperties: false
      description: 错误响应。
      properties:
        error:
          $ref: '#/components/schemas/ImageAPIError'
          description: 错误信息。
      required:
        - error
      type: object
    ImageAPIError:
      additionalProperties: false
      description: 错误信息。
      properties:
        code:
          description: 错误码。
          type: string
        http_status:
          description: HTTP 状态码。
          format: int64
          type: integer
        message:
          description: 可读的错误说明。
          type: string
        request_id:
          description: 请求 ID，排查问题时请提供。
          type: string
        type:
          description: |-
            错误类型。

            **可选值：**
            - `invalid_request_error`：请求参数错误。
            - `authentication_error`：认证失败。
            - `insufficient_balance_error`：余额不足。
            - `permission_error`：无权限。
            - `rate_limit_error`：请求过于频繁。
            - `api_error`：服务端或上游错误。
          enum:
            - invalid_request_error
            - authentication_error
            - insufficient_balance_error
            - permission_error
            - rate_limit_error
            - api_error
          type: string
      required:
        - code
        - http_status
        - message
        - request_id
        - type
      type: object
  securitySchemes:
    bearerAuth:
      description: 'DreamTo 控制台创建的 API Key，格式 `Authorization: Bearer <API Key>`。'
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.