上传图片,AI 抠掉背景并返回透明 PNG。同步返回,通常几秒即可。
鉴权与请求
X-Api-Key: YOUR_API_KEY 请求头中发送你的密钥。在账户页面创建和管理密钥。
| 参数 | 类型 | 必填参数 | 说明 |
|---|---|---|---|
image_file
|
file | 必填* | 待处理图片,multipart 上传。JPG / PNG / WebP,最大 20MB |
image_url
|
string | 必填* | 或一个公开图片 URL(image_file / image_url 二选一) |
size
|
string | 选填 | preview(免费,带水印)/ full(高清,1 点数)/ auto。默认 preview |
format
|
string | 选填 | auto(透明则 PNG,否则 JPG——默认)/ png / jpg |
bg_color
|
string | 选填 | 结果背景:transparent(默认)/ white / 任意 #RRGGBB |
代码示例
选择语言并复制——可直接运行。1curl -X POST "https://api.pixmiller.com/v1/remove" \2 -H "X-Api-Key: YOUR_API_KEY" \3 -F "[email protected]" \4 -F "size=full"
1import requests23resp = requests.post(4 "https://api.pixmiller.com/v1/remove",5 headers={"X-Api-Key": "YOUR_API_KEY"},6 files={"image_file": open("product.jpg", "rb")},7 data={"size": "full"},8)9print(resp.json()["url"])
1import fs from "node:fs";23const form = new FormData();4form.append("image_file", new Blob([fs.readFileSync("product.jpg")]), "product.jpg");5form.append("size", "full");6const resp = await fetch("https://api.pixmiller.com/v1/remove", {7 method: "POST",8 headers: { "X-Api-Key": "YOUR_API_KEY" },9 body: form,10});11console.log((await resp.json()).url);
响应
1{2 "url": "https://cdn.pixmiller.com/result/8Kd2pQ.png"3}
url
处理后图片的临时 URL(原图会在 3 天后自动删除)。
错误
错误会返回对应的 HTTP 状态码,JSON 响应体形如: {"errors":{"code":"…","message":"…"}}.
validation error
缺少或无效的 image_file、文件过大,或同时提供了多个图片来源。
authentication_failed
X-Api-Key 请求头缺失或无效。
not_enough_credit
请求了 size=full,但账户已无高清点数。
invalid_image
图片无法处理 —— 尺寸过小、格式不支持,或解码失败。
throttled
超出速率限制。请放慢请求,并在 Retry-After 指示的时间后重试。
从 remove.bg 迁移
只需换一行 base URL,原有的请求照常可用。POST /v1.0/removebg 上复刻了它的主流路径——同样的 X-Api-Key 请求头、同样的参数名,HTTP 200 直接在响应体里返回图片字节。配套的 GET /v1.0/account 返回你的点数余额。
1curl -H "X-Api-Key: REMOVEBG_KEY" \2 -F "[email protected]" \3 -F "size=auto" \4 -o out.png \5 https://api.remove.bg/v1.0/removebg
1curl -H "X-Api-Key: PIXMILLER_KEY" \2 -F "[email protected]" \3 -F "size=auto" \4 -o out.png \5 https://api.pixmiller.com/v1.0/removebg
| remove.bg 取值 | PixMiller 档位 | 说明 |
|---|---|---|
preview / small / regular
|
preview | 带水印预览图,最长边不超过 640 px。免费,不扣点。与 remove.bg 一样是默认值。 |
medium / hd / 4k / full / 50MP
|
full | 原图清晰度、无水印,按档位的像素上限缩放(1.5 / 4 / 25 / 25 / 50 MP;PNG 输出封顶 10 MP)。每张 1 点。 |
auto
|
auto | 有点数时返回原图清晰度,否则返回免费的带水印预览图。 |
X-Credits-Charged
本次调用实际扣除的点数(免费预览档为 0)。
X-Width / X-Height
返回图片的像素尺寸。
X-Type
检测到的前景类别:person、product、animal、car 或 other(type_level=none 时不返回)。
X-Foreground-Top / -Left / -Width / -Height
主体在返回图片中的包围盒。
X-RateLimit-Limit / -Remaining / -Reset
你的 key 的限速状态,按张计数——一次调用消耗 1 个额度;429 时另附 Retry-After。
remove.bg 的每个参数都会被接受并校验——size、type、type_level、format、roi、crop、crop_margin、scale、position、channels、bg_color、bg_image_url 与 bg_image_file 的行为与 remove.bg 文档一致。以下参数会被接受但不改变输出,与 remove.bg 对非汽车主体的行为相同:
shadow_type, shadow_opacity, add_shadow, semitransparency
- size=preview(及其别名 small / regular,与 remove.bg 一样是默认值)返回我们免费的带水印预览图(最长边不超过 640 px),不扣点;remove.bg 返回 0.25 百万像素的无水印图并收 0.25 点。
- medium、hd、4k、full 与 50MP 都是每张 1 点,与 remove.bg 一致。没有「每月免费预览次数」,故 /v1.0/account 的 free_calls 恒为 0。
- X-Type 是由所用抠图模型推导出的粗分类(person / product / animal / car / other);type_level = 2 与 latest 返回同样的粗分类。
- 阴影(shadow_type / shadow_opacity / add_shadow)与车窗半透明参数会被接受但从不渲染——与 remove.bg 对非汽车主体的行为一致。
- 输入文件上限 20 MB(remove.bg:22 MB)。
本端点的错误使用 remove.bg 的 JSON:API 信封 {"errors":[{"title":"…","code":"…"}]}
状态码为 400 invalid_parameter / 402 insufficient_credits / 403 auth_failed / 429 rate_limit_exceeded。
这是针对主流 HTTP 调用路径的兼容层,不是官方 SDK / CLI 的认证级平替。