去背景 API 文档

使用一个 API Key 提交图片,获取透明背景 PNG。

POSThttps://api.remox.ai/v1.0/removebg

快速开始

申请 API 接入 →

将已签发的 Key 保存在服务端,不要暴露在浏览器或 App 中。更换 Key 后,客户身份和余额不变。

REMOX_API_KEY

支持 JPG、PNG 和静态 WebP。上传前自行调整尺寸,接口不会自动缩放。

代码示例 →

身份验证

将已签发的 Key 保存在服务端,不要暴露在浏览器或 App 中。更换 Key 后,客户身份和余额不变。

字段允许值
X-API-Keyremox_live_… / remox_test_…
Secret / X-Subuid / X-Platform-User / X-RapidAPI-User—
image_url / Base64 / shadow / refine—

代码示例

cURL
# Set REMOX_API_KEY in your environment first.
curl 'https://api.remox.ai/v1.0/removebg' \
  -H "X-API-Key: $REMOX_API_KEY" \
  -H 'Idempotency-Key: image-0001' \
  -F 'image_file=@/path/to/input.jpg' \
  -F 'size=auto' \
  --max-time 75 --fail-with-body \
  -D response-headers.txt -o remox-result.png
# On non-2xx, the output file contains error JSON, not a PNG.

支持 JPG、PNG 和静态 WebP。上传前自行调整尺寸,接口不会自动缩放。

input.jpg → image/jpeg · PNG → image/png · WebP → image/webp

请求参数

POST /v1.0/removebg · multipart/form-data

支持 JPG、PNG 和静态 WebP。上传前自行调整尺寸,接口不会自动缩放。

字段必填允许值
image_file✓JPG / PNG / WebP · ≤20 MiB (20 × 1024 × 1024 bytes) · max(width, height) ≤1920 px · min(width, height) ≤1080 px
size—auto
response_format—image / json
Idempotency-Key—8–128 · A–Z a–z 0–9 . _ : -

返回结果

200 · PNG

response_format=image · Content-Type: image/png

X-Request-ID · X-Task-ID · X-Idempotency-Key

200 · JSON

response_format=json
{
  "requestId": "req_…",
  "taskId": "task_…",
  "data": {
    "result_url": "https://storage.example/result.png?signature=…&expires=…"
  }
}
data.result_url ≠ result_b64

超时与重试

60 秒后返回 504,任务可能仍在运行。查询状态,或使用相同图片和 Idempotency-Key 重试,避免重复扣费。

GET /v1.0/tasks/{taskId}
{
  "requestId": "req_…",
  "taskId": "task_…",
  "status": "completed",
  "progress": null,
  "pollAfterMs": 2000,
  "result": {
    "downloadPath": "/v1.0/tasks/task_…/result",
    "mimeType": "image/png",
    "expiresAt": "2026-10-17T00:00:00.000Z"
  }
}
GET /v1.0/tasks/{taskId}/result
GET /v1.0/tasks/{taskId}/result?response_format=json

creating → queued → processing → completed / failed / timed_out

Retry-After · pollAfterMs: 2000 · X-API-Key

账户与积分

创建任务时预留积分,成功后扣除,失败或任务到期后释放。同步等待超时本身不会释放积分。

字段允许值
creditsavailable / reserved / consumed
GET /v1.0/accountX-API-Key
POST → AI300 ms
POST → 50460 s
task → timed_out35 min
task_expired90 d
result_expired (Worker)7 d

错误处理

重试前检查 errors 数组和任务状态。保留 requestId 以便排查,不要记录 API Key。

{
  "requestId": "req_…",
  "retryable": false,
  "errors": [
    {
      "code": "invalid_credentials",
      "title": "Invalid API key."
    }
  ]
}
HTTPerrors[].code错误处理
400invalid_request, invalid_file请求参数不正确
400invalid_size, invalid_response_format请求参数不正确
400invalid_idempotency_key, invalid_subject请求参数不正确
402insufficient_credits有效积分不足,请充值
403invalid_credentialsKey 无效或访问受限
403platform_disabled, platform_paused, scope_deniedKey 无效或访问受限
404not_found, upload_not_found接口、任务或上传不存在
409idempotency_conflict重复请求冲突或任务未完成
409result_not_ready重复请求冲突或任务未完成
410task_expired, result_expired任务或结果已过期
413file_too_large图片文件过大
415invalid_image, animated_image_unsupported图片无效或不支持动态图
422image_dimensions_exceeded图片尺寸超限,请先缩放
429rate_limit_exceeded, hourly_quota_exhausted, inflight_limit_exceeded请求频率或额度超限
502upload_failed, upstream_rejected, upstream_unavailable上游调用或结果获取失败
502create_result_unknown, remote_service_error, invalid_result, result_unavailable, task_failed, task_timeout上游调用或结果获取失败
503service_not_configured, credit_price_not_configured, server_error服务配置异常或暂不可用
504sync_timeout同步等待超时,请查询任务状态

retryable: 429 / 5xx

60 秒后返回 504,任务可能仍在运行。查询状态,或使用相同图片和 Idempotency-Key 重试,避免重复扣费。

兼容性

此接口仅支持纯 Key 去背景,不完整兼容 remove.bg 的全部功能。JSON 结果地址是 REMOX 扩展。

申请 API 接入 →