请求
在代码里调用
把密钥放在环境变量 TAPCUB_API_KEY 里。接口地址前缀:https://api.pathclue.com/v1。
terminal
curl -X POST "https://api.pathclue.com/v1/images/remove-background?background=transparent" \
-H "Authorization: Bearer $TAPCUB_API_KEY" \
-H "Content-Type: application/octet-stream" \
--data-binary @photo.jpg \
-o result.pngindex.mjs
import { readFile, writeFile } from 'node:fs/promises';
const res = await fetch('https://api.pathclue.com/v1/images/remove-background?background=transparent', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.TAPCUB_API_KEY}`,
'Content-Type': 'application/octet-stream',
},
body: await readFile('photo.jpg'),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
await writeFile('result.png', Buffer.from(await res.arrayBuffer()));main.py
import os
import requests
res = requests.post(
"https://api.pathclue.com/v1/images/remove-background",
headers={"Authorization": f"Bearer {os.environ['TAPCUB_API_KEY']}", "Content-Type": "application/octet-stream"},
params={
"background": "transparent",
},
data=open("photo.jpg", "rb"),
timeout=120,
)
res.raise_for_status()
with open("result.png", "wb") as f:
f.write(res.content)index.php
<?php
$ch = curl_init('https://api.pathclue.com/v1/images/remove-background?background=transparent');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('TAPCUB_API_KEY'),
'Content-Type: application/octet-stream',
],
CURLOPT_POSTFIELDS => file_get_contents('photo.jpg'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 300) {
throw new RuntimeException("HTTP $status: $body");
}
file_put_contents('result.png', $body);main.go
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
body, err := os.ReadFile("photo.jpg")
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", "https://api.pathclue.com/v1/images/remove-background?background=transparent", bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("TAPCUB_API_KEY"))
req.Header.Set("Content-Type", "application/octet-stream")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
if res.StatusCode >= 300 {
panic(fmt.Sprintf("HTTP %d: %s", res.StatusCode, out))
}
if err := os.WriteFile("result.png", out, 0o644); err != nil {
panic(err)
}
}请求体直接放文件本身,选项写在查询串里。
返回的就是文件本身,按示例里的写法保存即可。
参数
请求参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
background | string | 否 | "transparent" | transparent(默认)、white,或纯色底的十六进制颜色如 #f5f5f5。结果都是 PNG。 |
output | enum可选值: binary | json | 否 | "binary" | binary 直接返回 PNG;json 在 image 里返回 base64,另带宽高。 |
返回
返回示例
成功的响应带 X-Credits-Charged(本次扣的点数)和 X-Credits-Balance(余额)两个响应头。出错时返回 {"error":{"code","message"}},一律不扣点。
HTTP
HTTP/1.1 200 OK
Content-Type: image/png
X-Image-Width: 2048
X-Image-Height: 1536
<image/png …>价格和限制
怎么收费
| 价格 | 每张 10 点 |
|---|---|
| 折合美元 | 约 $0.01 · $10 / 1,000 |
| 点数 | 只用付费点数 |
| 限速 | 免费 10 次 / 分钟 · Plus 60 次 / 分钟 · Pro 300 次 / 分钟 |
| 何时扣点 | 只有成功才扣,出错和超时不扣 |
用例
可以用来做什么
商品图
抠出商品,换白底或品牌背景。
头像
自动整理头像和团队照片。
设计流水线
不用手工修图,直接把抠图放进模板。
返回什么?
和输入图片同样尺寸、背景透明的 PNG。
图片会保存吗?
不会。图片处理完、响应发出后立即删除,也不进日志。
高清抠图 API 怎么收费?
每次成功调用扣 每张 10 点(约 $0.01),1 点约合 0.001 美元。调用失败——参数错误、目标网站打不开、超时或我们这边出错——都不扣。
能用免费点数吗?
不能。文档处理和图片接口只能用工具套餐或额度包里的付费点数。想先看效果,可以在 tapcub.com 上用对应的免费工具试。
限速是多少?
免费账号每把密钥每分钟 10 次、每天 1,000 次;Plus 每分钟 60 次,Pro 每分钟 300 次。超出时返回 HTTP 429 并带 Retry-After 头,不扣点。
怎么拿到 API 密钥?
登录 TapCub 控制台,验证邮箱后在「工具套餐 → API」页新建密钥。密钥以 tck_ 开头,只显示一次;调用时放在 Authorization: Bearer 请求头里。