快速入门
以原始 body 发送含图片的 POST 请求。无需授权标头——API 使用 x402 进行付款。
# Step 1: discovery — returns HTTP 402 with payment details curl -X POST https://x402.clearcanvas.app/v1/remove-background \ -H "Content-Type: image/png" \ --data-binary @photo.png # Step 2: paid request — attach X-PAYMENT header with signed USDC transfer curl -X POST https://x402.clearcanvas.app/v1/remove-background \ -H "Content-Type: image/png" \ -H "X-PAYMENT: <base64-signed-payload>" \ --data-binary @photo.png \ --output result.png
通过 x402 认证
x402 是标准 HTTP 付款协议。首次请求时,API 返回 HTTP 402 并附付款详情。使用 Coinbase x402 SDK 在 Base 上签署 USDC 转账,然后附带 X-PAYMENT 标头重新发送。
在 GitHub 上查看 x402 SDK →TypeScript
import fs from 'fs';
import { wrapFetchWithPayment } from '@coinbase/x402';
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const fetch402 = wrapFetchWithPayment(fetch, account);
const res = await fetch402('https://x402.clearcanvas.app/v1/remove-background', {
method: 'POST',
headers: { 'Content-Type': 'image/png' },
body: fs.readFileSync('photo.png'),
});
const buffer = await res.arrayBuffer();
fs.writeFileSync('result.png', Buffer.from(buffer));Python
import os
import httpx
from x402.client import wrap_httpx # pip install x402
client = wrap_httpx(private_key=os.environ["PRIVATE_KEY"])
resp = client.post(
"https://x402.clearcanvas.app/v1/remove-background",
content=open("photo.png", "rb").read(),
headers={"Content-Type": "image/png"},
)
open("result.png", "wb").write(resp.content)请求格式
- •端点
- •Body:原始图片字节(PNG、JPEG 或 WebP)
- •Content-Type:image/png | image/jpeg | image/webp
- •可选:?format=webp 输出 WebP 格式
响应格式
- •HTTP 200——二进制图片(PNG 或 WebP)
- •HTTP 402——需要付款(x402 详情在 body 中)
错误处理
- •400——无效图片(格式错误、magic bytes 不符或超出尺寸限制)
- •413——文件过大(> 25 MB)
- •415——不支持的 Content-Type
- •429——超过速率限制(未付费请求:每分钟 30 次/IP)
- •500——处理失败(retryable: true)
- •503——处理器暂时不可用(retryable: true)
限制与格式
- •最大文件大小:25 MB
- •最大尺寸:10,000 × 10,000 像素
- •支持输入:PNG、JPEG、WebP
- •输出:PNG(默认)或 WebP
网络
API 在 Base 主网上运行。支付以真实 USDC 结算(每张图片 $0.05)。在发起请求前,请确保您的钱包在 Base 上持有 USDC。