> ## 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 Image Edits

> 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.

This page uses the same `images/edits` operation as [Edit image](https://docs.dgrid.ai/api-reference/images/edit-image.md), with the playground above pre-filled for the generic OpenAI-style edit schema (`image`, `mask`, `prompt`, etc.). The notes below describe the Qwen-specific request shape for `wanx-v1` style models.

> [!NOTE]
>
> Qwen image editing models accept an alternate JSON request shape that wraps your editing instructions and source image references inside `input.messages`, rather than uploading `image`/`mask` files via multipart form data. Provide `model` and `input` together in the playground's request body to use this shape.

### Qwen-specific request fields

| Field | Type | Required | Description |
| - | - | - | - |
| `model` | string | Yes | Model identifier, such as `wanx-v1`. |
| `input` | object | Yes | Input wrapper object sent in the request body, used instead of multipart `image`/`mask` fields. |
| `input.messages` | array | Yes | Messages array nested under `input`. |
| `input.messages[].role` | string | Yes | Message role, e.g. `user`. |
| `input.messages[].content` | string | Yes | Editing instructions and any referenced source image(s). |

> [!TIP]
>
> Source images can be referenced inline within `input.messages[].content` (for example as URLs or embedded references) rather than as separate multipart file uploads.

### Example: editing an image

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

### Response fields

The response follows the standard image edit shape:

**created** `integer`

Creation timestamp.

**data** `array`

Generated image entries.

**data item properties**

**url** `string`

Image URL.

**b64\_json** `string`

Base64 image payload.

**revised\_prompt** `string`

Revised prompt returned by the model.

### Example response

```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>`.

````

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