背景移除 API

通过 API 以编程方式移除图像背景。

概述

背景移除 API 使用先进的 AI 算法自动识别并移除图片背景,输出透明 PNG 格式图片。支持人物、产品、动物等多种类型的图片,提供发丝级抠图精度。

接口地址

POST https://api.aluo.ai/api/remove-bg

请求参数

使用 multipart/form-data 格式提交,支持两种输入方式(二选一):

参数类型必填说明
fileFile二选一图片文件(JPG/PNG/WebP)
imageUrlstring二选一图片 URL 地址
uploadToCDNboolean可选是否上传到 CDN(默认 true)

提示: 最大文件尺寸:4096x4096 像素。支持格式:JPG, PNG, WebP。

响应格式

成功响应

{
  "code": 0,
  "success": true,
  "data": {
    "url": "https://cdn.aluo.ai/...",
    "originalFileName": "image.png",
    "processedFileName": "processed_image.png",
    "fileSize": 123456,
    "contentType": "image/png",
    "width": 1024,
    "height": 1024
  },
  "credits_deducted": 8,
  "credits_remaining": 42
}

错误响应

{
  "code": -1,
  "success": false,
  "error": "No file or imageUrl provided"
}

请求示例

方式一:上传文件

curl -X POST https://api.aluo.ai/api/remove-bg \
  -H "Authorization: Bearer sk-your-api-key-here" \
  -F "file=@/path/to/image.jpg"

方式二:使用图片 URL

curl -X POST https://api.aluo.ai/api/remove-bg \
  -H "Authorization: Bearer sk-your-api-key-here" \
  -F "imageUrl=https://example.com/product.jpg"

Node.js

const fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');

const form = new FormData();
// 方式一:上传文件
form.append('file', fs.createReadStream('/path/to/image.jpg'));
// 方式二:使用 URL
// form.append('imageUrl', 'https://example.com/product.jpg');

const response = await fetch('https://api.aluo.ai/api/remove-bg', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-your-api-key-here',
    ...form.getHeaders()
  },
  body: form
});

const result = await response.json();
console.log(result);

Python

import requests

headers = {
    'Authorization': 'Bearer sk-your-api-key-here'
}

# 方式一:上传文件
files = {
    'file': open('/path/to/image.jpg', 'rb')
}
response = requests.post(
    'https://api.aluo.ai/api/remove-bg',
    headers=headers,
    files=files
)

# 方式二:使用 URL
# data = {
#     'imageUrl': 'https://example.com/product.jpg'
# }
# response = requests.post(
#     'https://api.aluo.ai/api/remove-bg',
#     headers=headers,
#     data=data
# )

result = response.json()
print(result)

积分消耗与处理时间

项目免费用户PRO 用户
积分消耗8 积分/张6 积分/张
处理时间通常 10-30 秒

常见错误

错误信息原因解决方案
No file or imageUrl provided未提供图片必须提供 file 或 imageUrl 之一
Insufficient credits积分不足充值积分或升级到 PRO
Authentication requiredAPI Key 无效检查 Authorization Header