Qwen 2.1 Edit-Image
Edit up to ten source images, or repaint one masked region, with resolution and transparent background control.
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
- Create an API key and set it as RUNAPI_API_KEY.
- Choose a supported model and send a POST request whose body matches that model's schema.
- Store the returned task ID, then poll until a terminal state or handle the callbacks documented below.
Endpoint
- Base URL
https://runapi.ai- API version
v1- Authentication
Authorization: Bearer YOUR_API_TOKEN
Supported models
Open a model page for current pricing, rate limits, and commercial-usage details.
Request schema
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_ratiostringOutput 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
backgroundstringBackground 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_urlstringWebhook URL for asynchronous task updates.
enable_prompt_expansionbooleanWhether RunAPI expands the prompt before generation. Ignored when mask_url is set.
Default:true
mask_urlstringPublic 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.
modelstringRunAPI model identifier.
output_formatstringOutput image format. jpeg cannot be combined with a transparent background.
Allowed values:png, webp, jpeg
Default: png
output_resolutionstringOutput image resolution.
Allowed values:1k, 2k
Default: 1k
promptstringImage editing prompt. With mask_url, describes what to generate inside the white area of the mask.
Range:1 - 5000
seedintegerInteger seed for reproducible results; omit for a random seed.
source_image_urlsarrayPublic 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.
-
When
background = transparent,output_format = jpeg- Required
- Not accepted
output_format
-
When
background = transparent,mask_url present- Required
- Not accepted
mask_url
Create acceptance
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
},
"task_replayed": {
"type": "boolean"
}
},
"required": [
"id",
"status"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"id": "tsk_reference_demo",
"status": "processing"
}
Polling processing
GET /api/v1/qwen_2_1/edit_image/:id
Response schema
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
}
},
"required": [
"id",
"status"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"id": "tsk_reference_demo",
"status": "processing"
}
Polling completed
GET /api/v1/qwen_2_1/edit_image/:id
Response schema
{
"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
{
"id": "tsk_reference_demo",
"images": [
{
"url": "https://cdn.runapi.ai/public/samples/image.jpg"
}
],
"status": "completed",
"usage": {
"cost": 0.05
}
}
Polling failed
GET /api/v1/qwen_2_1/edit_image/:id
Response schema
{
"properties": {
"error": {
"type": "string"
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "Task processing failed.",
"id": "tsk_reference_demo",
"status": "failed"
}
Customer callback: completed
POST callback_url
Response schema
{
"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
{
"id": "tsk_reference_demo",
"images": [
{
"url": "https://cdn.runapi.ai/public/samples/image.jpg"
}
],
"status": "completed",
"usage": {
"cost": 0.05
}
}
Customer callback: failed
POST callback_url
Response schema
{
"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
{
"error": {
"code": "generation_failed",
"message": "Task processing failed."
},
"id": "tsk_reference_demo",
"status": "failed"
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "Authentication required"
}
Errors
GET /api/v1/qwen_2_1/edit_image/:id
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "Authentication required"
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"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
{
"error": "model must be one of: qwen-2.1-edit-image"
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "Insufficient balance"
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "API key credit limit exceeded"
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "The request uses features that are not supported for the selected model"
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "Rate limit reached. Please retry later."
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "Service under maintenance, please try again later"
}
Errors
POST /api/v1/qwen_2_1/edit_image
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "The request timed out"
}
Errors
GET /api/v1/qwen_2_1/edit_image/:id
Response schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Response example
{
"error": "Task with id 'tsk_reference_demo' not found"
}
Generated Code Samples
Use cURL directly, or install an SDK for your language. Each sample submits the validated request shown in this reference.
Install
pip install runapi-qwen-2-1
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"
)