文档中心

按产品查看接口地址、请求参数、返回说明与示例代码。浏览文档无需登录;购买套餐与在线调试登录后仍留在本页。

涂抹去水印/去物体

● 服务正常 独立计费 # inpaint 含免费额度

上传图片并框选/涂抹水印区域,AI 修复填充。图片不落盘,成功后按次扣点。

调用权限
登录后开通
计费方式
成功扣 1 点
免费额度
注册赠送
参考价格
25 元起
以下均为 POST JSON(成功看 code===0,结果在 result_base64)。不要用短视频那种 GET 拼 url。

网页 · fetch

const endpoint = 'https://syapi.chuangye.site/api/inpaint/v1';

async function inpaintWeb(file, rectangles) {
  const buf = await file.arrayBuffer();
  const bytes = new Uint8Array(buf);
  let binary = '';
  for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
  const image_base64 = btoa(binary);

  const res = await fetch(endpoint, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      uid: 'YOUR_UID',
      key: 'YOUR_KEY',
      request_id: 'ip_' + Date.now(),
      mode: 'new',
      image_base64,
      rectangles // [{x1,y1,x2,y2}] 原图像素坐标
    })
  });
  const data = await res.json();
  if (Number(data.code) !== 0) throw new Error(data.msg_cn || data.msg || '失败');

  // 展示结果
  const imgUrl = 'data:image/jpeg;base64,' + data.result_base64;
  document.querySelector('#result').src = imgUrl;
  return data; // 含 image_id,可再次修复
}
// Node.js 18+(内置 fetch / fs)
const fs = require('fs');

const endpoint = 'https://syapi.chuangye.site/api/inpaint/v1';

async function inpaintFile(imagePath, rectangles) {
  const image_base64 = fs.readFileSync(imagePath).toString('base64');
  const res = await fetch(endpoint, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      uid: 'YOUR_UID',
      key: 'YOUR_KEY',
      request_id: 'ip_' + Date.now(),
      mode: 'new',
      image_base64,
      rectangles // [{x1,y1,x2,y2}] 原图像素坐标
    })
  });
  const data = await res.json();
  if (Number(data.code) !== 0) {
    throw new Error(data.msg_cn || data.msg || '失败');
  }
  fs.writeFileSync('out.jpg', Buffer.from(data.result_base64, 'base64'));
  return data; // 含 image_id,可再次修复
}

inpaintFile('./image.jpg', [{ x1: 80, y1: 40, x2: 320, y2: 120 }])
  .then((d) => console.log('ok, image_id=', d.image_id))
  .catch(console.error);

微信小程序 · wx.request

const endpoint = 'https://syapi.chuangye.site/api/inpaint/v1';

// 1) 先把本地图片转成 base64(选图后)
function fileToBase64(filePath) {
  return new Promise((resolve, reject) => {
    const fs = wx.getFileSystemManager();
    fs.readFile({
      filePath,
      encoding: 'base64',
      success: (r) => resolve(r.data),
      fail: reject
    });
  });
}

async function inpaintMp(tempFilePath, rectangles) {
  const image_base64 = await fileToBase64(tempFilePath);

  return new Promise((resolve, reject) => {
    wx.request({
      url: endpoint,
      method: 'POST',
      timeout: 120000,
      header: { 'content-type': 'application/json' },
      data: {
        uid: 'YOUR_UID',
        key: 'YOUR_KEY',
        request_id: 'ip_' + Date.now(),
        mode: 'new',
        image_base64,
        rectangles // 例: [{x1:80,y1:40,x2:320,y2:120}]
      },
      success(res) {
        const data = res.data || {};
        if (Number(data.code) !== 0) {
          reject(new Error(data.msg_cn || data.msg || '处理失败'));
          return;
        }
        // 2) base64 写临时文件再预览/保存
        const outPath = `${wx.env.USER_DATA_PATH}/inpaint_${Date.now()}.jpg`;
        wx.getFileSystemManager().writeFile({
          filePath: outPath,
          data: data.result_base64,
          encoding: 'base64',
          success: () => resolve({ ...data, localPath: outPath }),
          fail: reject
        });
      },
      fail: reject
    });
  });
}

// 使用:
// wx.chooseMedia({ count:1, mediaType:['image'], success: async (r) => {
//   const path = r.tempFiles[0].tempFilePath;
//   const ret = await inpaintMp(path, [{x1:10,y1:10,x2:200,y2:80}]);
//   wx.previewImage({ urls: [ret.localPath] });
// }});

小程序后台需把业务域名 syapi.chuangye.site 配到 request 合法域名。单次 body 较大时注意包体积与超时(建议 ≥60s)。

curl -X POST "https://syapi.chuangye.site/api/inpaint/v1" \
  -H "Content-Type: application/json" \
  -d "{
    \"uid\": \"YOUR_UID\",
    \"key\": \"YOUR_KEY\",
    \"request_id\": \"ip_demo_001\",
    \"mode\": \"new\",
    \"image_base64\": \"/9j/4AAQ...(原图base64)\",
    \"rectangles\": [{\"x1\":80,\"y1\":40,\"x2\":320,\"y2\":120}]
  }"
<?php
$endpoint = 'https://syapi.chuangye.site/api/inpaint/v1';
$body = json_encode([
    'uid' => 'YOUR_UID',
    'key' => 'YOUR_KEY',
    'request_id' => 'ip_' . time(),
    'mode' => 'new',
    'image_base64' => base64_encode(file_get_contents('/path/to/image.jpg')),
    'rectangles' => [['x1' => 80, 'y1' => 40, 'x2' => 320, 'y2' => 120]],
], JSON_UNESCAPED_UNICODE);

$ch = curl_init($endpoint);
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 120,
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);

if ((int)($data['code'] ?? -1) !== 0) {
    throw new RuntimeException($data['msg_cn'] ?? $data['msg'] ?? '失败');
}
file_put_contents('out.jpg', base64_decode($data['result_base64']));
import base64, json, requests

endpoint = "https://syapi.chuangye.site/api/inpaint/v1"
with open("image.jpg", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

payload = {
    "uid": "YOUR_UID",
    "key": "YOUR_KEY",
    "request_id": "ip_demo_001",
    "mode": "new",
    "image_base64": image_b64,
    "rectangles": [{"x1": 80, "y1": 40, "x2": 320, "y2": 120}],
}
data = requests.post(endpoint, json=payload, timeout=120).json()
if int(data.get("code", -1)) != 0:
    raise RuntimeError(data.get("msg_cn") or data.get("msg") or "失败")
open("out.jpg", "wb").write(base64.b64decode(data["result_base64"]))

再次修复(复用 image_id)

{
  "uid": "YOUR_UID",
  "key": "YOUR_KEY",
  "image_id": "上次返回的 image_id",
  "rectangles": [{"x1": 12, "y1": 20, "x2": 180, "y2": 90}],
  "mode": "new"
}

常见问题

如何获取 UID / KEY? 注册并登录后,本页「在线调试」会自动填入;也可在控制台查看。

是不是 GET? 不是。请 POST JSON 到业务地址 https://syapi.chuangye.site/api/inpaint/v1,不要走短视频的 /home/api?url=。

要传什么? 必填 uid、key;原图三选一(image_base64 / image_url / image_id);蒙版至少一种(常用 rectangles)。详见「API 文档 / 示例代码」。

如何计费? 成功调用扣 1 点,失败不扣;可在本页「立即购买」开通包点或包月。

有免费额度吗? 新用户注册即可免费测试:每个独立计费产品赠送 20 次调用额度(失败不扣点),用完后需购买套餐。「共用默认池」产品与短视频共用同一份额度。

准备联调?

注册即含免费测试额度;登录后自动填入 UID / KEY,可直接在本页调试或购买套餐。