ByByBG API 文档 – AI 背景移除 API
🚀 开发者文档

ByByBG API 文档

通过简单的 API 请求,将 AI 背景移除功能集成到网站、移动应用、SaaS 平台、自动化系统和企业解决方案中。

概览

欢迎使用 ByByBG API

ByByBG API 允许您使用先进的 AI 模型自动移除图片背景。

我们的基础设施针对速度、可扩展性、安全性以及生产环境集成进行了优化。

快速 AI 处理

借助优化的 AI 服务器,在几秒钟内完成背景移除。

🔐

安全 API

通过 API 密钥和加密连接保护您的请求。

🌍

多平台支持

适用于网站、移动应用、后端系统、SaaS 产品和自动化工具。

📦

批量处理

从单张图片到数千张图片均可高效处理。

工作流程

简单的背景移除流程

01

上传图片

用户选择或拖放图片。

02

发送 API 请求

您的服务器使用私有 API 密钥安全发送图片。

03

获取透明 PNG

AI 处理图片并立即返回透明 PNG。

API ENDPOINT

官方 API Endpoint

向以下 Endpoint 发送 POST 请求即可执行 AI 背景移除。

POST https://api.bybybg.com/v1/remove-bg
READY TO USE DEMO

现成示例

复制以下文件,添加您的 API 密钥,并上传到服务器即可开始背景移除。

项目文件夹结构

project/
├── index.html
├── style.css
├── script.js
└── remove-bg.php

index.html

创建一个名为 index.html 的文件,并将以下代码粘贴进去。

<!DOCTYPE html>
<html>

<head>

<link rel="stylesheet" href="style.css">

</head>

<body>

<div class="upload-box">

    <input type="file"
           id="imageInput"
           accept="image/*">

    <button id="uploadBtn">
        Remove Background
    </button>

    <img id="preview">

</div>

<script src="script.js"></script>

</body>
</html>

style.css

body{
    background:#0f172a;
    color:white;
    font-family:Arial;
    padding:40px;
}

.upload-box{
    max-width:500px;
    margin:auto;
    padding:30px;
    background:#111827;
    border-radius:20px;
    text-align:center;
}

button{
    padding:14px 22px;
    border:none;
    border-radius:10px;
    cursor:pointer;
}

img{
    width:100%;
    margin-top:20px;
}

script.js

const input = document.getElementById("imageInput");
const button = document.getElementById("uploadBtn");
const preview = document.getElementById("preview");

button.onclick = async () => {

    if(!input.files.length) return;

    const formData = new FormData();

    formData.append("file", input.files[0]);

    const response = await fetch("remove-bg.php", {
        method:"POST",
        body:formData
    });

    const blob = await response.blob();

    preview.src = URL.createObjectURL(blob);
};

remove-bg.php

创建一个名为 remove-bg.php 的文件,并将 YOUR_API_KEY 替换为您的真实 API 密钥。

<?php

$apiKey = "YOUR_API_KEY";

$ch = curl_init(
"https://api.bybybg.com/v1/remove-bg?format=png"
);

$cfile = new CURLFile(
    $_FILES['file']['tmp_name']
);

curl_setopt_array($ch,[

    CURLOPT_POST => true,

    CURLOPT_POSTFIELDS => [
        'file' => $cfile
    ],

    CURLOPT_RETURNTRANSFER => true,

    CURLOPT_HTTPHEADER => [
        'X-API-KEY: '.$apiKey,
        'Accept: image/png'
    ]

]);

$response = curl_exec($ch);

curl_close($ch);

header('Content-Type:image/png');

echo $response;
SETUP GUIDE

安装步骤

  • 在您的电脑或主机账户中创建一个新的项目文件夹。
  • 按照指定名称创建文件。
  • 将提供的代码粘贴到对应文件中。
  • 将 YOUR_API_KEY 替换为您的真实 ByByBG API 密钥。
  • 上传文件到您的主机,并在浏览器中打开 index.html。
RESPONSE

准备开始了吗?

获取您的 API 密钥,并立即开始集成 AI 背景移除功能。