Magic Editor API 文档#
基础 URL:
https://api.ideal.house
版本: v1
更新于: 2026-03-06
📖 概述#
Magic Editor API 允许您使用 AI 智能编辑和转换图像。通过提供源图像和可选文本提示,AI 将根据所选模型模式对图像进行智能修改。该工作流是异步的,涉及两个步骤:
- 创建任务 — 提交您的图像和参数,然后获得一个
taskId。 - 轮询结果 — 使用
taskId查询任务状态并获取编辑后的图像。
🔐 认证#
所有 API 请求必须使用 API 密钥进行认证。
在请求头中携带您的 API 密钥:
| 头部 | 值 |
|---|---|
APIKEY | your_api_key_here |
⚠️ 请妥善保管您的 API 密钥。 切勿将其暴露在客户端代码或公共仓库中。
💰 积分扣除#
[!WARNING] 🪙 积分根据所选的
modelType在任务成功创建时扣除。若任务最终失败,已扣除的积分将自动退款至您的账户。
积分不足将返回错误代码9051。📄 请参阅积分扣除说明。
模型(modelType) | 扣除积分 |
|---|---|
Flash | 1 积分 |
Base | 3 积分 |
Pro | 10 积分 |
📌 API 端点#
1. 创建 Magic Editor 任务#
创建一个新的 AI 魔法编辑 任务,并返回一个用于轮询的唯一 taskId。
端点
POST /api/v1/magicEditor/generate
请求头部
| 头部 | 是否必填 | 说明 |
|---|---|---|
APIKEY | ✅ 是 | 您的 API 认证密钥 |
Content-Type | ✅ 是 | application/json |
请求体
| 字段 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
imageUrl | string | ✅ 是 | 待编辑源图像的 URL |
prompt | string | ⚠️ 条件必填 | 描述期望编辑效果的文本提示。modelType 为 Base 时必须提供;Flash 和 Pro 模式下可选 |
modelType | string | ❌ 可选 | 模型类型。枚举值:Flash、Base、Pro。默认为 Flash |
🖼️ 图像要求: 使用 JPG/JPEG、PNG 或 WebP 格式。每张图像大小不得超过 20 MB,尺寸范围为 128 × 128 px 至 6,000 × 6,000 px(含边界)。超出最大像素尺寸的图像将在处理前按比例缩小以适应 6,000 × 6,000 px 以内。图像 URL 必须可由 API 服务器直接访问。
模型类型
| 值 | 说明 | 是否需要提示 |
|---|---|---|
Flash | 默认。 快速编辑,自动 AI 智能生成 | ❌ 可选 |
Base | 文本引导编辑——使用您的提示精确控制输出 | ✅ 必需 |
Pro | 更高质量的编辑,结果更详细 | ❌ 可选 |
⚠️ 重要: 当
modelType为Base时,必须提供prompt字段。modelType=Base但未提供prompt的请求将返回参数错误。
📥 请求示例#
cURL
# Flash mode (default) — prompt is optional
curl -X POST "https://api.ideal.house/api/v1/magicEditor/generate" \
-H "APIKEY: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"imageUrl": "https://example.com/room.jpg",
"modelType": "Flash"
}'
# Base mode — prompt is required
curl -X POST "https://api.ideal.house/api/v1/magicEditor/generate" \
-H "APIKEY: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"imageUrl": "https://example.com/room.jpg",
"prompt": "Change the wall color to warm beige and add wooden flooring",
"modelType": "Base"
}'
# Pro mode — prompt is optional
curl -X POST "https://api.ideal.house/api/v1/magicEditor/generate" \
-H "APIKEY: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"imageUrl": "https://example.com/room.jpg",
"prompt": "Modern Scandinavian style interior",
"modelType": "Pro"
}'
Java (OkHttp)
import okhttp3.*;
import java.io.IOException;
public class MagicEditorApiExample {
private static final String BASE_URL = "https://api.ideal.house";
private static final String API_KEY = "your_api_key_here";
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
// Flash mode (default) — no prompt needed
String requestBody = """
{
"imageUrl": "https://example.com/room.jpg",
"modelType": "Flash"
}
""";
// Base mode — prompt is required
// String requestBody = """
// {
// "imageUrl": "https://example.com/room.jpg",
// "prompt": "Change the wall color to warm beige and add wooden flooring",
// "modelType": "Base"
// }
// """;
// Pro mode — prompt is optional
// String requestBody = """
// {
// "imageUrl": "https://example.com/room.jpg",
// "prompt": "Modern Scandinavian style interior",
// "modelType": "Pro"
// }
// """;
Request request = new Request.Builder()
.url(BASE_URL + "/api/v1/magicEditor/generate")
.addHeader("APIKEY", API_KEY)
.addHeader("Content-Type", "application/json")
.post(RequestBody.create(requestBody, MediaType.parse("application/json")))
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println("Response: " + response.body().string());
}
}
}
Python (requests)
import requests
BASE_URL = "https://api.ideal.house"
API_KEY = "your_api_key_here"
headers = {
"APIKEY": API_KEY,
"Content-Type": "application/json"
}
# Flash mode (default) — no prompt needed
payload = {
"imageUrl": "https://example.com/room.jpg",
"modelType": "Flash"
}
# Base mode — prompt is required
# payload = {
# "imageUrl": "https://example.com/room.jpg",
# "prompt": "Change the wall color to warm beige and add wooden flooring",
# "modelType": "Base"
# }
# Pro mode — prompt is optional
# payload = {
# "imageUrl": "https://example.com/room.jpg",
# "prompt": "Modern Scandinavian style interior",
# "modelType": "Pro"
# }
response = requests.post(
f"{BASE_URL}/api/v1/magicEditor/generate",
headers=headers,
json=payload
)
data = response.json()
task_id = data.get("data")
print(f"Task ID: {task_id}")
Node.js (axios)
const axios = require('axios');
const BASE_URL = 'https://api.ideal.house';
const API_KEY = 'your_api_key_here';
async function createMagicEditorTask() {
try {
const response = await axios.post(
`${BASE_URL}/api/v1/magicEditor/generate`,
{
// Flash mode (default) — no prompt needed
imageUrl: 'https://example.com/room.jpg',
modelType: 'Flash'
// Base mode — prompt is required:
// imageUrl: 'https://example.com/room.jpg',
// prompt: 'Change the wall color to warm beige and add wooden flooring',
// modelType: 'Base'
// Pro mode — prompt is optional:
// imageUrl: 'https://example.com/room.jpg',
// prompt: 'Modern Scandinavian style interior',
// modelType: 'Pro'
},
{
headers: {
'APIKEY': API_KEY,
'Content-Type': 'application/json'
}
}
);
const taskId = response.data.data;
console.log('Task ID:', taskId);
return taskId;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
createMagicEditorTask();
📤 响应#
成功响应
{
"code": 0,
"message": "success",
"data": 1234567890123456789
}
| 字段 | 类型 | 说明 |
|---|---|---|
code | integer | 0 表示成功 |
message | string | 响应消息 |
data | long | 用于轮询结果任务的唯一 ID |
2. 获取任务结果#
获取先前创建的 Magic Editor 任务的当前状态和输出。
端点
GET /api/v1/magicEditor/result
请求头部
| 头部 | 是否必填 | 说明 |
|---|---|---|
APIKEY | ✅ 是 | 您的 API 认证密钥 |
查询参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
taskId | long | ✅ 是 | 从创建任务端点返回的任务 ID |
📥 请求示例#
cURL
curl -X GET "https://api.ideal.house/api/v1/magicEditor/result?taskId=1234567890123456789" \
-H "APIKEY: your_api_key_here"
Java (OkHttp)
import okhttp3.*;
import java.io.IOException;
public class MagicEditorResultExample {
private static final String BASE_URL = "https://api.ideal.house";
private static final String API_KEY = "your_api_key_here";
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
long taskId = 1234567890123456789L;
Request request = new Request.Builder()
.url(BASE_URL + "/api/v1/magicEditor/result?taskId=" + taskId)
.addHeader("APIKEY", API_KEY)
.get()
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println("Response: " + response.body().string());
}
}
}
Python (requests)
import requests
import time
BASE_URL = "https://api.ideal.house"
API_KEY = "your_api_key_here"
headers = {
"APIKEY": API_KEY
}
task_id = 1234567890123456789
# Poll until task is complete
while True:
response = requests.get(
f"{BASE_URL}/api/v1/magicEditor/result",
headers=headers,
params={"taskId": task_id}
)
data = response.json()
result = data.get("data", {})
status = result.get("status")
print(f"Status: {status}, Progress: {result.get('percentage')}%, Queue: {result.get('waitNumber')}")
if status in ("Success", "Failed", "Termination"):
break
time.sleep(3) # Poll every 3 seconds
if status == "Success":
print("Result URL:", result["output"]["resultUrl"])
else:
print("Task ended with status:", status)
Node.js (axios)
const axios = require('axios');
const BASE_URL = 'https://api.ideal.house';
const API_KEY = 'your_api_key_here';
async function pollResult(taskId) {
const headers = { 'APIKEY': API_KEY };
while (true) {
const response = await axios.get(
`${BASE_URL}/api/v1/magicEditor/result`,
{
headers,
params: { taskId }
}
);
const result = response.data.data;
const { status, percentage, waitNumber } = result;
console.log(`Status: ${status} | Progress: ${percentage}% | Queue: ${waitNumber}`);
if (['Success', 'Failed', 'Termination'].includes(status)) {
if (status === 'Success') {
console.log('Result URL:', result.output.resultUrl);
console.log('Size:', result.output.width, 'x', result.output.height);
} else {
console.log('Task ended with status:', status);
}
break;
}
// Wait 3 seconds before next poll
await new Promise(resolve => setTimeout(resolve, 3000));
}
}
pollResult(1234567890123456789n);
📤 响应#
成功响应(任务完成)
{
"code": 0,
"message": "success",
"data": {
"id": 1234567890123456789,
"status": "Success",
"waitNumber": 0,
"percentage": 100,
"input": {
"imageUrl": "https://example.com/room.jpg",
"prompt": "Change the wall color to warm beige and add wooden flooring",
"modelType": "Base"
},
"output": {
"resultUrl": "https://cdn.ideal.house/output/magic_editor_result.jpg",
"width": 1024,
"height": 1024
}
}
}
响应(任务处理中 / 队列中)
{
"code": 0,
"message": "success",
"data": {
"id": 1234567890123456789,
"status": "Processing",
"waitNumber": 1,
"percentage": 40,
"input": {
"imageUrl": "https://example.com/room.jpg",
"modelType": "Flash"
},
"output": null
}
}
响应(任务失败)
{
"code": 0,
"message": "success",
"data": {
"id": 1234567890123456789,
"status": "Failed",
"waitNumber": 0,
"percentage": 0,
"input": {
"imageUrl": "https://example.com/room.jpg",
"modelType": "Flash"
},
"output": null
}
}
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | long | 任务唯一标识符 |
status | string | 当前任务状态(参见任务状态) |
waitNumber | integer | 队列中排在前面任务的数量(0 表示正在处理) |
percentage | integer | 任务完成百分比(0–100) |
input | object | 任务的原始输入参数 |
input.imageUrl | string | 源图像 URL |
input.prompt | string | 文本提示(若提供) |
input.modelType | string | 使用的模型类型 |
output | object | 生成结果(仅当 status 为 Success 时可获取) |
output.resultUrl | string | 编辑后输出图像的 URL |
output.width | integer | 输出宽度(像素) |
output.height | integer | 输出高度(像素) |
📊 任务状态#
| 状态 | 说明 |
|---|---|
Unprocessed | 任务已创建但尚未开始 |
Processing | 任务正在处理中 |
Success | 任务成功完成——输出可用 |
Failed | 任务因错误失败 |
Termination | 任务被中断或终止 |
每 3-5 秒轮询一次。参见API 任务限制。
❌ 错误响应#
所有错误响应共享相同的 JSON 结构:
{
"code": 5002,
"message": "Invalid API Key",
"data": null
}
错误代码说明#
| 代码 | 名称 | 说明 | 建议操作 |
|---|---|---|---|
1001 | FAILED | 请求失败(通用错误) | 检查 message 字段以获取具体错误详情 |
1003 | INTERNAL_ERROR | 内部服务器错误 | 稍后重试;若持续出现请联系技术支持 |
1011 | PARAM_ERROR | 请求参数错误 — e.g., prompt 缺失当 modelType=Base | 使用 Base 模式时请确保提供 prompt |
5002 | API_KEY_INVALID | API 密钥无效或缺失 | 确保 APIKEY 头部存在且值正确 |
9010 | SCAN_TEXT_ERROR | 文本提示未能通过内容审核 | 修改提示以移除敏感或禁止内容 |
9038 | PROHIBITED_CONTENT | 生成结果图像包含禁止内容 | 调整提示/风格/输入并重试 |
9051 | COINS_NOT_ENOUGH | 金币/积分不足 | 充值账户积分后重试 |
📄 常见 API 错误代码完整列表,请参见错误代码参考。