Ideal House
跳转到主要内容

Magic Editor API 文档#

基础 URL: https://api.ideal.house
版本: v1
更新于: 2026-03-06


📖 概述#

Magic Editor API 允许您使用 AI 智能编辑和转换图像。通过提供源图像和可选文本提示,AI 将根据所选模型模式对图像进行智能修改。该工作流是异步的,涉及两个步骤:

  1. 创建任务 — 提交您的图像和参数,然后获得一个 taskId
  2. 轮询结果 — 使用 taskId 查询任务状态并获取编辑后的图像。

🔐 认证#

所有 API 请求必须使用 API 密钥进行认证。

在请求头中携带您的 API 密钥:

头部
APIKEYyour_api_key_here

⚠️ 请妥善保管您的 API 密钥。 切勿将其暴露在客户端代码或公共仓库中。


💰 积分扣除#

[!WARNING] 🪙 积分根据所选的 modelType 在任务成功创建时扣除。若任务最终失败,已扣除的积分将自动退款至您的账户。
积分不足将返回错误代码 9051。📄 请参阅积分扣除说明

模型(modelType扣除积分
Flash1 积分
Base3 积分
Pro10 积分

📌 API 端点#


1. 创建 Magic Editor 任务#

创建一个新的 AI 魔法编辑 任务,并返回一个用于轮询的唯一 taskId

端点

纯文本
POST /api/v1/magicEditor/generate

请求头部

头部是否必填说明
APIKEY✅ 是您的 API 认证密钥
Content-Type✅ 是application/json

请求体

字段类型是否必填说明
imageUrlstring✅ 是待编辑源图像的 URL
promptstring⚠️ 条件必填描述期望编辑效果的文本提示。modelTypeBase 时必须提供FlashPro 模式下可选
modelTypestring❌ 可选模型类型。枚举值:FlashBasePro。默认为 Flash

🖼️ 图像要求: 使用 JPG/JPEG、PNG 或 WebP 格式。每张图像大小不得超过 20 MB,尺寸范围为 128 × 128 px6,000 × 6,000 px(含边界)。超出最大像素尺寸的图像将在处理前按比例缩小以适应 6,000 × 6,000 px 以内。图像 URL 必须可由 API 服务器直接访问。


模型类型

说明是否需要提示
Flash默认。 快速编辑,自动 AI 智能生成❌ 可选
Base文本引导编辑——使用您的提示精确控制输出✅ 必需
Pro更高质量的编辑,结果更详细❌ 可选

⚠️ 重要:modelTypeBase 时,必须提供 prompt 字段。modelType=Base 但未提供 prompt 的请求将返回参数错误。


📥 请求示例#

cURL
bash
# 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)
java
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)
python
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)
javascript
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();

📤 响应#

成功响应

json
{
  "code": 0,
  "message": "success",
  "data": 1234567890123456789
}
字段类型说明
codeinteger0 表示成功
messagestring响应消息
datalong用于轮询结果任务的唯一 ID

2. 获取任务结果#

获取先前创建的 Magic Editor 任务的当前状态和输出。

端点

纯文本
GET /api/v1/magicEditor/result

请求头部

头部是否必填说明
APIKEY✅ 是您的 API 认证密钥

查询参数

参数类型是否必填说明
taskIdlong✅ 是从创建任务端点返回的任务 ID

📥 请求示例#

cURL
bash
curl -X GET "https://api.ideal.house/api/v1/magicEditor/result?taskId=1234567890123456789" \
  -H "APIKEY: your_api_key_here"
Java (OkHttp)
java
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)
python
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)
javascript
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);

📤 响应#

成功响应(任务完成)

json
{
  "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
    }
  }
}

响应(任务处理中 / 队列中)

json
{
  "code": 0,
  "message": "success",
  "data": {
    "id": 1234567890123456789,
    "status": "Processing",
    "waitNumber": 1,
    "percentage": 40,
    "input": {
      "imageUrl": "https://example.com/room.jpg",
      "modelType": "Flash"
    },
    "output": null
  }
}

响应(任务失败)

json
{
  "code": 0,
  "message": "success",
  "data": {
    "id": 1234567890123456789,
    "status": "Failed",
    "waitNumber": 0,
    "percentage": 0,
    "input": {
      "imageUrl": "https://example.com/room.jpg",
      "modelType": "Flash"
    },
    "output": null
  }
}

响应字段

字段类型说明
idlong任务唯一标识符
statusstring当前任务状态(参见任务状态
waitNumberinteger队列中排在前面任务的数量(0 表示正在处理)
percentageinteger任务完成百分比(0–100
inputobject任务的原始输入参数
input.imageUrlstring源图像 URL
input.promptstring文本提示(若提供)
input.modelTypestring使用的模型类型
outputobject生成结果(仅当 statusSuccess 时可获取)
output.resultUrlstring编辑后输出图像的 URL
output.widthinteger输出宽度(像素)
output.heightinteger输出高度(像素)

📊 任务状态#

状态说明
Unprocessed任务已创建但尚未开始
Processing任务正在处理中
Success任务成功完成——输出可用
Failed任务因错误失败
Termination任务被中断或终止

3-5 秒轮询一次。参见API 任务限制


❌ 错误响应#

所有错误响应共享相同的 JSON 结构:

json
{
  "code": 5002,
  "message": "Invalid API Key",
  "data": null
}

错误代码说明#

代码名称说明建议操作
1001FAILED请求失败(通用错误)检查 message 字段以获取具体错误详情
1003INTERNAL_ERROR内部服务器错误稍后重试;若持续出现请联系技术支持
1011PARAM_ERROR请求参数错误 — e.g., prompt 缺失当 modelType=Base使用 Base 模式时请确保提供 prompt
5002API_KEY_INVALIDAPI 密钥无效或缺失确保 APIKEY 头部存在且值正确
9010SCAN_TEXT_ERROR文本提示未能通过内容审核修改提示以移除敏感或禁止内容
9038PROHIBITED_CONTENT生成结果图像包含禁止内容调整提示/风格/输入并重试
9051COINS_NOT_ENOUGH金币/积分不足充值账户积分后重试

📄 常见 API 错误代码完整列表,请参见错误代码参考