Qwen 2.1 Edit-Image
编辑最多十张源图像,或重绘一个蒙版区域,并控制分辨率和透明背景。
概览
使用支持的模型提交Edit Image请求。使用返回的 Task ID 查询状态,或提供 callback_url 接收下方列出的投递。
快速开始
- 创建 API Key,并将其设置为 RUNAPI_API_KEY。
- 选择一个支持的模型,并发送与该模型 Schema 匹配的 POST 请求。
- 保存返回的任务 ID,随后轮询到终态,或处理下方列出的回调。
端点
- 基础 URL
https://runapi.ai- API 版本
v1- 身份验证
Authorization: Bearer YOUR_API_TOKEN
支持的模型
打开模型页可查看当前价格、限流和商业使用详情。
请求 Schema
字段和允许的取值取决于所选模型。提供 callback_url 后,它会收到下方列出的 Task 投递。
qwen-2.1-edit-image11 个字段
aspect_ratiostringOutput aspect ratio. auto follows the first source image. Ignored when mask_url is set.
可选值:auto, 1:1, 4:3, 3:4, 3:2, 2:3, 16:9, 9:16, 21:9, 9:21
默认值: 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.
可选值:opaque, transparent
默认值: opaque
callback_urlstringWebhook URL for asynchronous task updates.
enable_prompt_expansionbooleanWhether RunAPI expands the prompt before generation. Ignored when mask_url is set.
默认值: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.
可选值:png, webp, jpeg
默认值: png
output_resolutionstringOutput image resolution.
可选值:1k, 2k
默认值: 1k
promptstringImage editing prompt. With mask_url, describes what to generate inside the white area of the mask.
范围: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.
项数范围:1 - 10
条件规则
当列出的全部条件同时匹配时,应用这些要求。
-
当
background = transparent,output_format = jpeg- 必填
- 不可提供
output_format
-
当
background = transparent,mask_url present- 必填
- 不可提供
mask_url
创建已接受
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
},
"task_replayed": {
"type": "boolean"
}
},
"required": [
"id",
"status"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"id": "tsk_reference_demo",
"status": "processing"
}
轮询处理中
GET /api/v1/qwen_2_1/edit_image/:id
响应 Schema
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
}
},
"required": [
"id",
"status"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"id": "tsk_reference_demo",
"status": "processing"
}
轮询已完成
GET /api/v1/qwen_2_1/edit_image/:id
响应 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
}
响应示例
{
"id": "tsk_reference_demo",
"images": [
{
"url": "https://cdn.runapi.ai/public/samples/image.jpg"
}
],
"status": "completed",
"usage": {
"cost": 0.05
}
}
轮询失败
GET /api/v1/qwen_2_1/edit_image/:id
响应 Schema
{
"properties": {
"error": {
"type": "string"
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "Task processing failed.",
"id": "tsk_reference_demo",
"status": "failed"
}
客户回调:已完成
POST callback_url
响应 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
}
响应示例
{
"id": "tsk_reference_demo",
"images": [
{
"url": "https://cdn.runapi.ai/public/samples/image.jpg"
}
],
"status": "completed",
"usage": {
"cost": 0.05
}
}
客户回调:失败
POST callback_url
响应 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
}
响应示例
{
"error": {
"code": "generation_failed",
"message": "Task processing failed."
},
"id": "tsk_reference_demo",
"status": "failed"
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "Authentication required"
}
错误
GET /api/v1/qwen_2_1/edit_image/:id
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "Authentication required"
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 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
}
]
}
响应示例
{
"error": "model must be one of: qwen-2.1-edit-image"
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "Insufficient balance"
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "API key credit limit exceeded"
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "The request uses features that are not supported for the selected model"
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "Rate limit reached. Please retry later."
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "Service under maintenance, please try again later"
}
错误
POST /api/v1/qwen_2_1/edit_image
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "The request timed out"
}
错误
GET /api/v1/qwen_2_1/edit_image/:id
响应 Schema
{
"properties": {
"error": {
"description": "Human-readable error message.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
响应示例
{
"error": "Task with id 'tsk_reference_demo' not found"
}
生成的代码示例
直接使用 cURL,或安装所用语言的 SDK。每个示例都会提交本参考中经过验证的请求。
安装
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"
)