> ## 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 圖像編輯

> Edit an uploaded image with an optional mask using the OpenAI-compatible image editing endpoint. Also accepts Qwen-compatible JSON payloads with an `input.messages` wrapper.

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

<Note>
  Qwen 圖像編輯模型接受另一種 JSON 請求格式：將編輯指令與來源圖像參照包在 `input.messages` 中，而不是透過 multipart form data 上傳 `image`／`mask` 檔案。若要使用這種格式，請在 playground 的請求本文中同時提供 `model` 與 `input`。
</Note>

### Qwen 專用請求欄位

| 欄位                         | 類型     | 必填 | 說明                                                  |
| -------------------------- | ------ | -- | --------------------------------------------------- |
| `model`                    | string | 是  | 模型識別碼，例如 `wanx-v1`。                                 |
| `input`                    | object | 是  | 在請求本文中傳送的輸入包裝物件，用來取代 multipart 的 `image`／`mask` 欄位。 |
| `input.messages`           | array  | 是  | 巢狀於 `input` 之下的 messages 陣列。                        |
| `input.messages[].role`    | string | 是  | 訊息角色，例如 `user`。                                     |
| `input.messages[].content` | string | 是  | 編輯指令，以及任何被參照的來源圖像。                                  |

<Tip>
  來源圖像可以直接在 `input.messages[].content` 中以內嵌方式參照（例如 URL 或嵌入式參照），而不必另外上傳 multipart 檔案。
</Tip>

### 範例：編輯圖像

```json theme={null}
{
  "model": "wanx-v1",
  "input": {
    "messages": [
      {
        "role": "user",
        "content": "Remove the background and replace it with a solid white backdrop."
      }
    ]
  }
}
```

### 回應欄位

回應遵循標準圖像編輯結構：

<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/edited-abc123.png",
      "b64_json": "",
      "revised_prompt": "The subject with background removed and replaced with a solid white backdrop."
    }
  ]
}
```


## OpenAPI

````yaml api-reference/openapi.json POST /v1/images/edits
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/edits:
    post:
      tags:
        - Images
      summary: Edit image
      description: >-
        Edit an uploaded image with an optional mask using the OpenAI-compatible
        image editing endpoint. Also accepts Qwen-compatible JSON payloads with
        an `input.messages` wrapper.
      operationId: editImage
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - image
                - prompt
              properties:
                image:
                  type: string
                  format: binary
                  description: Source image in PNG format, under 4 MB.
                mask:
                  type: string
                  format: binary
                  description: Optional mask image.
                prompt:
                  type: string
                  description: Editing instruction.
                model:
                  type: string
                  description: Target image model.
                'n':
                  type: integer
                  description: Number of outputs.
                size:
                  type: string
                  description: Output size.
                response_format:
                  type: string
                  description: Response format.
                user:
                  type: string
                  description: End-user identifier.
          application/json:
            schema:
              type: object
              title: Qwen format
              required:
                - model
                - input
              properties:
                model:
                  type: string
                  description: Model identifier.
                input:
                  type: object
                  description: Input wrapper object.
                  properties:
                    messages:
                      type: array
                      description: Messages array nested under `input`.
                      items:
                        type: object
      responses:
        '200':
          description: Edited images in the image generation response format.
          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>`.

````