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

# Qwen 圖像生成

> OpenAI-compatible image generation. Also accepts Qwen-compatible payloads (`wanx-v1` style models) using an `input.messages` wrapper instead of `prompt`.

本頁使用與 [建立圖像](/zh-Hant/api-reference/images/create-image) 相同的 `images/generations` 操作，上方 playground 已預先填入通用的 OpenAI 風格圖像結構（`prompt`、`model`、`size` 等）。以下說明 `wanx-v1` 類模型的 Qwen 專用請求格式。

<Note>
  Qwen 圖像模型接受另一種請求格式：將 prompt 包在 `input.messages` 中，而不是使用頂層 `prompt` 欄位。若要使用這種格式，請在 playground 的請求本文中同時提供 `model` 與 `input`。
</Note>

### Qwen 專用請求欄位

| 欄位                         | 類型     | 必填 | 說明                            |
| -------------------------- | ------ | -- | ----------------------------- |
| `model`                    | string | 是  | 模型識別碼，例如 `wanx-v1`。           |
| `input`                    | object | 是  | 請求中傳送的輸入包裝物件，用來取代頂層 `prompt`。 |
| `input.messages`           | array  | 是  | 巢狀於 `input` 之下的 messages 陣列。  |
| `input.messages[].role`    | string | 是  | 訊息角色，例如 `user`。               |
| `input.messages[].content` | string | 是  | 描述目標圖像的 prompt 文字。            |

<Tip>
  與 playground 中顯示的標準 `prompt`、`size`、`quality` 欄位不同，Qwen 的 `wanx-v1` 模型會從 `input.messages[].content` 讀取 prompt。像 `n` 與 `response_format` 這類其他頂層欄位，並不適用於此格式。
</Tip>

### 範例：生成圖像

```json theme={null}
{
  "model": "wanx-v1",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": "A serene mountain lake at dawn, photorealistic."
      }
    ]
  }
}
```

### 回應欄位

回應遵循標準圖像生成結構：

<ResponseField name="created" type="integer">
  建立時間戳。
</ResponseField>

<ResponseField name="data" type="array">
  生成圖像條目。

  <Expandable title="data item properties">
    <ResponseField name="url" type="string">
      圖像 URL。
    </ResponseField>

    <ResponseField name="b64_json" type="string">
      Base64 圖像負載。
    </ResponseField>

    <ResponseField name="revised_prompt" type="string">
      模型回傳的修訂 prompt。
    </ResponseField>
  </Expandable>
</ResponseField>

### 回應範例

```json 200 theme={null}
{
  "created": 1719859200,
  "data": [
    {
      "url": "https://cdn.dgrid.ai/generated/abc123.png",
      "b64_json": "",
      "revised_prompt": "A serene mountain lake at dawn with mist rising off the water, photorealistic."
    }
  ]
}
```


## OpenAPI

````yaml api-reference/openapi.json POST /v1/images/generations
openapi: 3.1.0
info:
  title: DGrid AI Gateway API
  description: >-
    A single, unified API to access 200+ leading AI models. OpenAI-, Claude-,
    and Gemini-compatible endpoints for chat, completions, embeddings, images,
    audio, and moderations.
  version: 1.0.0
  contact:
    name: DGrid AI
    url: https://dgrid.ai
servers:
  - url: https://api.dgrid.ai
    description: DGrid AI Gateway
security:
  - bearerAuth: []
paths:
  /v1/images/generations:
    post:
      tags:
        - Images
      summary: Create image
      description: >-
        OpenAI-compatible image generation. Also accepts Qwen-compatible
        payloads (`wanx-v1` style models) using an `input.messages` wrapper
        instead of `prompt`.
      operationId: createImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  title: OpenAI format
                  required:
                    - prompt
                  properties:
                    prompt:
                      type: string
                      description: Image prompt.
                    model:
                      type: string
                      default: dall-e-2
                      description: Model such as `dall-e-2` or `dall-e-3`.
                    'n':
                      type: integer
                      default: 1
                      description: Number of images to generate.
                    quality:
                      type: string
                      enum:
                        - standard
                        - hd
                      default: standard
                    response_format:
                      type: string
                      enum:
                        - url
                        - b64_json
                      default: url
                    size:
                      type: string
                      default: 1024x1024
                      description: Output size.
                    style:
                      type: string
                      enum:
                        - vivid
                        - natural
                      default: vivid
                    user:
                      type: string
                      description: End-user identifier.
                - type: object
                  title: Qwen format
                  required:
                    - model
                    - input
                  properties:
                    model:
                      type: string
                      description: Model identifier, such as `wanx-v1`.
                    input:
                      type: object
                      description: Input wrapper object.
                      properties:
                        messages:
                          type: array
                          description: Messages array nested under `input`.
                          items:
                            type: object
            example:
              prompt: A cute baby sea otter wearing a beret
              model: dall-e-3
              size: 1024x1024
      responses:
        '200':
          description: Generated images.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  schemas:
    ImageResponse:
      type: object
      properties:
        created:
          type: integer
          description: Creation timestamp.
        data:
          type: array
          description: Generated image entries.
          items:
            type: object
            properties:
              url:
                type: string
                description: Image URL when using URL output.
              b64_json:
                type: string
                description: Base64 image payload when requested.
              revised_prompt:
                type: string
                description: Refined prompt returned by the model.
        usage:
          type: object
          properties:
            total_tokens:
              type: integer
            input_tokens:
              type: integer
            output_tokens:
              type: integer
            input_tokens_details:
              type: object
              properties:
                text_tokens:
                  type: integer
                image_tokens:
                  type: integer
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type: string
            code:
              type: string
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your DGrid API key. All endpoints use `Authorization: Bearer
        <DGRID_API_KEY>`.

````