API 访问
从购买到首次请求的最短路径
一个账户只有一个密钥,可同时调用视频和图片接口。你可以在这里查看、复制或重置,无需管理名称、权限或密钥列表。
你的 API 密钥
正在加载 API 访问状态…
两种能力
视频与图片,同时可用
一个密钥共用同一账户积分,同时让两种能力保持清晰、独立的接口契约。
视频背景移除 API
移除视频背景,可选择透明或纯色输出,并在支持时保留音频。
- 支持 MP4、MOV、WebM、M4V 和 GIF 输入,并提供多种输出格式。
- 按服务端测得时长计费:每开始 1 秒消耗 1 积分。
图片背景移除 API
通过专用图片接口移除背景,并下载透明 PNG。
- 支持不超过 10 MiB 的 JPEG、PNG、WebP、GIF 和 AVIF 输入。
- 固定费用:每张图片 1 积分,符合条件的失败会自动返还。
五步接入
上传一次,跟踪一个任务
视频和图片使用独立端点,但遵循同一套清晰可预期的异步流程。
- 1
请求上传
声明文件名、MIME 类型和大小,获取短期上传 URL。
- 2
直接上传
使用返回的准确请求头,以 PUT 方式上传一次文件。
- 3
创建任务
使用 UUID Idempotency-Key 创建对应媒体任务。
- 4
轮询状态
查询与供应商无关的任务状态,直到完成或失败。
- 5
下载结果
在 7 天内把已完成结果流式保存到自己的存储。
标准文档
人与 AI 工具共用一份参考
按照完整流程接入任一媒体类型,也可以把同一份源码直接复制给编程助手。
Public API v1
Use one API key for both video and image background removal. The API is designed for server-to-server calls. Do not expose your key in browser code or public repositories.
Base URL and authentication
Set these placeholders in your server environment:
BASE_URL="https://backgroundremover.video"
API_KEY="<YOUR_API_KEY>"
Every API request requires the Bearer header:
Authorization: Bearer <YOUR_API_KEY>
API keys are account-wide. One key works for both capabilities. Requests are limited to 60 calls per 60 seconds across the key. A rate-limited response includes Retry-After.
Common asynchronous flow
Both capabilities use the same five-step flow:
- Request a short-lived upload URL.
- Upload the file with the exact returned PUT headers.
- Create a task with a UUID
Idempotency-Key. - Poll the task until
statusiscompletedorfailed. - Download the completed result within 7 days.
The upload URL expires after 15 minutes and can create its object only once. Request a new upload URL if it expires; never reuse an uploadId across accounts or capabilities.
Image background removal
Image inputs support JPEG, PNG, WebP, GIF, and AVIF up to 10 MiB. Every image task costs 1 credit and returns a transparent PNG.
1. Request an image upload
curl --request POST "$BASE_URL/api/v1/image-background-removal/uploads" \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data '{
"fileName": "<IMAGE_FILE_NAME.jpg>",
"contentType": "image/jpeg",
"contentLength": 123456
}'
Example response:
{
"uploadId": "<UPLOAD_ID>",
"method": "PUT",
"url": "<PRESIGNED_UPLOAD_URL>",
"headers": {
"Content-Type": "image/jpeg",
"Content-Length": "123456",
"If-None-Match": "*"
},
"expiresAt": "<UTC_TIMESTAMP>"
}
2. Upload the image
Send the exact headers returned by the upload request:
curl --request PUT "<PRESIGNED_UPLOAD_URL>" \
--header "Content-Type: image/jpeg" \
--header "Content-Length: 123456" \
--header 'If-None-Match: *' \
--upload-file "<LOCAL_IMAGE_PATH>"
3. Create the image task
Generate a UUID and reuse it only when retrying the identical request.
curl --request POST "$BASE_URL/api/v1/image-background-removal/tasks" \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--header "Idempotency-Key: <UUID>" \
--data '{
"uploadId": "<UPLOAD_ID>",
"fileName": "<IMAGE_FILE_NAME.jpg>"
}'
4. Poll the image task
curl "$BASE_URL/api/v1/image-background-removal/tasks/<TASK_ID>" \
--header "Authorization: Bearer $API_KEY"
An image task includes the server-verified input MIME type and size:
{
"id": "<TASK_ID>",
"type": "image_background_removal",
"status": "processing",
"stage": "queued",
"creditAmount": 1,
"creditsReturned": false,
"inputContentType": "image/jpeg",
"inputSize": 123456,
"createdAt": "<UTC_TIMESTAMP>",
"expiresAt": null,
"result": null,
"error": null
}
5. Download the transparent PNG
curl --location "$BASE_URL/api/v1/image-background-removal/tasks/<TASK_ID>/download" \
--header "Authorization: Bearer $API_KEY" \
--output "<OUTPUT_FILE.png>"
Video background removal
Video inputs support MP4, MOV, WebM, M4V, and GIF. Each uploaded video must be shorter than 60 seconds. The server reads the uploaded media duration and charges 1 credit for each started second. There is no additional product-level file-size limit in v1.
1. Request a video upload
curl --request POST "$BASE_URL/api/v1/video-background-removal/uploads" \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data '{
"fileName": "<VIDEO_FILE_NAME.mp4>",
"contentType": "video/mp4",
"contentLength": 12345678
}'
2. Upload the video
Use the url and exact headers returned by the upload request:
curl --request PUT "<PRESIGNED_UPLOAD_URL>" \
--header "Content-Type: video/mp4" \
--header "Content-Length: 12345678" \
--header 'If-None-Match: *' \
--upload-file "<LOCAL_VIDEO_PATH>"
The upload route signs an object from fileName, contentType, and contentLength; it does not read the media bytes or determine duration. A signed upload therefore does not mean the video duration is accepted. The task route performs the authoritative duration check after the upload is complete.
3. Create the video task
The defaults are green, mp4_h264, preserveAudio: true, and autoZoom: false. This example requests a transparent WebM result:
curl --request POST "$BASE_URL/api/v1/video-background-removal/tasks" \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--header "Idempotency-Key: <UUID>" \
--data '{
"uploadId": "<UPLOAD_ID>",
"fileName": "<VIDEO_FILE_NAME.mp4>",
"backgroundColor": "transparent",
"outputFormat": "webm_vp9",
"preserveAudio": true,
"autoZoom": false
}'
backgroundColor accepts transparent, black, white, gray, red, green, blue, yellow, cyan, magenta, or orange. outputFormat accepts webm_vp9, mp4_h264, mp4_h265, mov_h265, mov_proresks, mkv_h264, mkv_h265, mkv_vp9, or gif. Transparent backgrounds require webm_vp9, mov_proresks, or mkv_vp9.
Do not send a duration, credit amount, provider, model, remote URL, storage key, or user ID. The server determines duration, credits, and ownership.
POST /tasks rejects a server-measured duration of exactly 60 seconds or longer with 400 INVALID_REQUEST and this message: The video must be shorter than 60 seconds. Shorten or split it, upload the new file, and try again. The rejection creates no task and consumes no credits. The uploaded object remains subject to the normal 7-day storage lifecycle, so upload a shortened or split file under a new upload URL before trying again.
4. Poll the video task
curl "$BASE_URL/api/v1/video-background-removal/tasks/<TASK_ID>" \
--header "Authorization: Bearer $API_KEY"
A video task includes the server-verified duration and processing options:
{
"id": "<TASK_ID>",
"type": "video_background_removal",
"status": "processing",
"stage": "queued",
"durationMs": 12500,
"creditAmount": 13,
"creditsReturned": false,
"options": {
"backgroundColor": "transparent",
"outputFormat": "webm_vp9",
"preserveAudio": true,
"autoZoom": false
},
"createdAt": "<UTC_TIMESTAMP>",
"expiresAt": null,
"result": null,
"error": null
}
5. Download the video result
curl --location "$BASE_URL/api/v1/video-background-removal/tasks/<TASK_ID>/download" \
--header "Authorization: Bearer $API_KEY" \
--output "<OUTPUT_FILE.webm>"
Video downloads support a single standard Range request. Unsatisfiable or multiple ranges are rejected.
Task status, results, and retention
Task status is processing, completed, or failed. While processing, stage is queued, running, or saving. A completed task provides a download path in result.downloadUrl; a failed task provides a safe product-level error and indicates whether consumed credits were returned.
Uploads and results expire after 7 days. This lifecycle also removes an uploaded video that is rejected when POST /tasks checks its duration. A completed task can become unavailable after its file expires, so copy results to your own storage promptly.
Idempotency
Every task creation request requires an Idempotency-Key containing a UUID. Retrying the same account, capability, key, and canonical JSON request returns the existing task. Reusing the key with different input or options returns 409 IDEMPOTENCY_CONFLICT. Image and video task IDs use separate namespaces.
Credits
- Image background removal costs exactly 1 credit.
- Video background removal costs
ceil(durationMs / 1000)credits using the duration measured by the server. - Task creation returns
402 INSUFFICIENT_CREDITSwhen the account balance is too low. - Credits consumed for an eligible terminal processing failure are restored automatically.
- Buying any credit pack enables API key generation; API tasks then use the same account balance as the web product.
Errors
JSON errors use one stable envelope:
{
"error": {
"code": "INVALID_REQUEST",
"message": "The request is invalid."
}
}
| HTTP | Code | Meaning |
|---|---|---|
| 400 | INVALID_REQUEST, UNSUPPORTED_MEDIA | Invalid JSON or fields, a video that is not shorter than 60 seconds, or unsupported/unreadable media |
| 401 | INVALID_API_KEY | Missing, malformed, reset, or unknown Bearer key |
| 402 | INSUFFICIENT_CREDITS | The shared account balance is too low |
| 403 | ACCOUNT_NOT_ALLOWED | The account is unavailable, unverified, or banned |
| 404 | RESOURCE_NOT_FOUND | The upload or owned task does not exist |
| 409 | IDEMPOTENCY_CONFLICT, RESULT_NOT_READY | The UUID conflicts or processing is not complete |
| 410 | RESULT_UNAVAILABLE | The result expired or is no longer available |
| 416 | RANGE_NOT_SATISFIABLE | A video download range cannot be served |
| 429 | RATE_LIMITED | The key exceeded 60 requests in 60 seconds |
| 500 | INTERNAL_ERROR | A safe unexpected-error response |
The API intentionally does not enable permissive browser CORS. Call it from a trusted server and keep API keys, upload URLs, and signed headers out of logs.
计费、限制与隐私
重要规则,提前说明
小而可预期的契约,让接入和运维都更容易维护。
Bearer 身份验证
从服务端以 Bearer token 发送一个私密密钥;不接受 query 或 x-api-key 凭证。
简单限流
同一密钥在每个 60 秒窗口内,跨两种能力最多请求 60 次。
共用积分
图片每张 1 积分,视频每开始 1 秒 1 积分,两者共用当前账户余额。
私密的临时文件
上传文件和结果 7 天后过期;签名上传 URL 15 分钟后过期。
常见问题
API 常见问题解答
了解访问资格、处理流程、安全和文件保留的关键信息。
图片支持不超过 10 MiB 的 JPEG、PNG、WebP、GIF 和 AVIF;视频支持 MP4、MOV、WebM、M4V 和 GIF。
使用已验证邮箱的账户登录,并成功购买任意积分包。仅有赠送积分不能生成 API 密钥。
每张图片消耗 1 积分;视频按服务端测得的时长,每开始 1 秒消耗 1 积分。两者共用现有账户余额。
是。先上传文件并创建任务,然后轮询状态,处理完成后再下载结果。
旧密钥会立即失效。继续调用 API 前,请将所有集成都更新为新显示的密钥。
上传文件和处理结果会在 7 天后过期。请在到期前把结果下载到自己的存储中。
不支持宽松的浏览器 CORS。请妥善保管 API 密钥,并从可信服务端、后端任务或自动化平台调用。