Skip to content
API Reference
API Reference

Qwen 2.1 Edit-Image

Edit up to ten source images, or repaint one masked region, with resolution and transparent background control.

01

Overview

Use the edit image endpoint with a supported model. Use the returned Task ID to retrieve its state, or provide callback_url for the deliveries documented below.

Quick start

  1. Create an API key and set it as RUNAPI_API_KEY.
  2. Choose a supported model and send a POST request whose body matches that model's schema.
  3. Store the returned task ID, then poll until a terminal state or handle the callbacks documented below.

Endpoint

POST /api/v1/qwen_2_1/edit_image
Base URL
https://runapi.ai
API version
v1
Authentication
Authorization: Bearer YOUR_API_TOKEN
02

Supported models

Open a model page for current pricing, rate limits, and commercial-usage details.

03

Request schema

JSON body

Fields and allowed values depend on the selected model. When supplied, callback_url receives the Task deliveries documented below.

qwen-2.1-edit-image11 fields
aspect_ratiostring
Optional

Output aspect ratio. auto follows the first source image. Ignored when mask_url is set.

Allowed values: auto, 1:1, 4:3, 3:4, 3:2, 2:3, 16:9, 9:16, 21:9, 9:21 Default: auto
backgroundstring
Optional

Background type. A transparent background requires output_format png or webp and cannot be combined with mask_url; describe only the subject in the prompt.

Allowed values: opaque, transparent Default: opaque
callback_urlstring
Optional

Webhook URL for asynchronous task updates.

enable_prompt_expansionboolean
Optional

Whether RunAPI expands the prompt before generation. Ignored when mask_url is set.

Default: true
mask_urlstring
Optional

Public mask image URL for local editing: white marks the area to change, black is kept. Requires exactly one source image and cannot be combined with a transparent background; aspect_ratio and enable_prompt_expansion are ignored.

modelstring
Required

RunAPI model identifier.

output_formatstring
Optional

Output image format. jpeg cannot be combined with a transparent background.

Allowed values: png, webp, jpeg Default: png
output_resolutionstring
Optional

Output image resolution.

Allowed values: 1k, 2k Default: 1k
promptstring
Required

Image editing prompt. With mask_url, describes what to generate inside the white area of the mask.

Range: 1 - 5000
seedinteger
Optional

Integer seed for reproducible results; omit for a random seed.

source_image_urlsarray
Required

Public source image URLs; one to ten images, in the order the prompt refers to them.

Item range: 1 - 10

Conditional rules

These requirements apply when all listed conditions match.

  1. When background = transparent, output_format = jpeg
    Required
    Not accepted
    output_format
  2. When background = transparent, mask_url present
    Required
    Not accepted
    mask_url
04

Create acceptance

HTTP 202

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "processing"
      ],
      "type": "string"
    },
    "task_replayed": {
      "type": "boolean"
    }
  },
  "required": [
    "id",
    "status"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "id": "tsk_reference_demo",
  "status": "processing"
}
05

Polling processing

HTTP 200

GET /api/v1/qwen_2_1/edit_image/:id

Response schema
JSON
{
  "properties": {
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "processing"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "id": "tsk_reference_demo",
  "status": "processing"
}
06

Polling completed

HTTP 200

GET /api/v1/qwen_2_1/edit_image/:id

Response schema
JSON
{
  "properties": {
    "id": {
      "type": "string"
    },
    "images": {
      "items": {
        "properties": {
          "url": {
            "type": "string",
            "x-runapi-generated-media": true
          }
        },
        "required": [
          "url"
        ],
        "type": "object",
        "unevaluatedProperties": false
      },
      "type": "array"
    },
    "status": {
      "enum": [
        "completed"
      ],
      "type": "string"
    },
    "usage": {
      "properties": {
        "cost": {
          "type": "number"
        }
      },
      "required": [
        "cost"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "id",
    "status",
    "images",
    "usage"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "id": "tsk_reference_demo",
  "images": [
    {
      "url": "https://cdn.runapi.ai/public/samples/image.jpg"
    }
  ],
  "status": "completed",
  "usage": {
    "cost": 0.05
  }
}
07

Polling failed

HTTP 200

GET /api/v1/qwen_2_1/edit_image/:id

Response schema
JSON
{
  "properties": {
    "error": {
      "type": "string"
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "failed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "Task processing failed.",
  "id": "tsk_reference_demo",
  "status": "failed"
}
08

Customer callback: completed

HTTP 200

POST callback_url

Response schema
JSON
{
  "properties": {
    "id": {
      "type": "string"
    },
    "images": {
      "items": {
        "properties": {
          "url": {
            "type": "string",
            "x-runapi-generated-media": true
          }
        },
        "required": [
          "url"
        ],
        "type": "object",
        "unevaluatedProperties": false
      },
      "type": "array"
    },
    "status": {
      "enum": [
        "completed"
      ],
      "type": "string"
    },
    "usage": {
      "properties": {
        "cost": {
          "type": "number"
        }
      },
      "required": [
        "cost"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  },
  "required": [
    "id",
    "status",
    "images",
    "usage"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "id": "tsk_reference_demo",
  "images": [
    {
      "url": "https://cdn.runapi.ai/public/samples/image.jpg"
    }
  ],
  "status": "completed",
  "usage": {
    "cost": 0.05
  }
}
09

Customer callback: failed

HTTP 200

POST callback_url

Response schema
JSON
{
  "properties": {
    "error": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "properties": {
            "code": {
              "type": "string"
            },
            "limit_cents": {
              "type": "integer"
            },
            "message": {
              "type": "string"
            },
            "reset_at": {
              "format": "date-time",
              "type": [
                "string",
                "null"
              ]
            },
            "used_cents": {
              "type": "integer"
            },
            "window": {
              "enum": [
                "1h",
                "1d",
                "7d",
                "daily",
                "weekly",
                "monthly",
                "lifetime"
              ],
              "type": "string"
            }
          },
          "required": [
            "code",
            "message"
          ],
          "type": "object",
          "unevaluatedProperties": false
        }
      ]
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "failed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": {
    "code": "generation_failed",
    "message": "Task processing failed."
  },
  "id": "tsk_reference_demo",
  "status": "failed"
}
10

Errors

HTTP 401

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "Authentication required"
}
11

Errors

HTTP 401

GET /api/v1/qwen_2_1/edit_image/:id

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "Authentication required"
}
12

Errors

HTTP 400

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "oneOf": [
    {
      "properties": {
        "error": {
          "description": "Human-readable error message.",
          "type": "string"
        }
      },
      "required": [
        "error"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    {
      "properties": {
        "error": {
          "description": "Human-readable validation summary.",
          "type": "string"
        },
        "errors": {
          "additionalProperties": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "description": "Validation messages keyed by public request field, with an array of human-readable strings for each field.",
          "type": "object"
        }
      },
      "required": [
        "error",
        "errors"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  ]
}

Response example

JSON
{
  "error": "model must be one of: qwen-2.1-edit-image"
}
13

Errors

HTTP 402

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "Insufficient balance"
}
14

Errors

HTTP 429

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "API key credit limit exceeded"
}
15

Errors

HTTP 409

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "The request uses features that are not supported for the selected model"
}
16

Errors

HTTP 429

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "Rate limit reached. Please retry later."
}
17

Errors

HTTP 503

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "Service under maintenance, please try again later"
}
18

Errors

HTTP 504

POST /api/v1/qwen_2_1/edit_image

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "The request timed out"
}
19

Errors

HTTP 404

GET /api/v1/qwen_2_1/edit_image/:id

Response schema
JSON
{
  "properties": {
    "error": {
      "description": "Human-readable error message.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Response example

JSON
{
  "error": "Task with id 'tsk_reference_demo' not found"
}
20

Generated Code Samples

Use cURL directly, or install an SDK for your language. Each sample submits the validated request shown in this reference.

Install

Shell
pip install runapi-qwen-2-1
PYTHON
import os
from runapi.qwen_2_1 import Qwen21Client

client = Qwen21Client(api_key=os.environ["RUNAPI_API_KEY"])
task = client.edit_image.create(
  model="qwen-2.1-edit-image",
  prompt="Change the vase to cobalt blue.",
  source_image_urls=["https://cdn.runapi.ai/public/samples/image.jpg"],
  output_resolution="2k"
)