语言: ZH
加入候补名单

商品图片工作室,以 API 提供。

Herofab API 接收商品照片和工具名称,并在后台处理任务;通过查询任务状态或签名 Webhook,即可得知成品图片何时可供下载。

  • Bearer 方式的 API 密钥
  • 签名 Webhook
  • 每批最多 100 个任务
  • OpenAPI 3.1 与 llms.txt
curl https://app.herofab.app/api/v1/jobs -H "Authorization: Bearer $HEROFAB_API_KEY" -H "Idempotency-Key: $(uuidgen)" --json '{"tool": "ghost_mannequin", "inputs": {"garment": "ASSET_ID"}}'
工作原理

从照片到成品图片。

01

发送

上传商品照片,并按工具及其设置创建任务;任务创建时即预留所需积分。

POST /api/v1/assetsPOST /api/v1/jobs

02

查询

查询任务直至完成,或在任务完成时接收签名 Webhook。

GET /api/v1/jobs/{id}

03

下载

通过任务输出的资源 ID 获取成品图片。

GET /api/v1/assets/{id}/content

完整示例:上传照片、创建任务、等待、下载
API=https://app.herofab.app/api/v1
AUTH="Authorization: Bearer $HEROFAB_API_KEY"

# 1 · Upload the product photo
ASSET_ID=$(curl -s "$API/assets" \
  -H "$AUTH" \
  -F [email protected] | jq -r .id)

# 2 · Create the job
BODY=$(jq -n --arg garment "$ASSET_ID" '{tool: "ghost_mannequin",
  inputs: {garment: $garment}, params: {style: "3d", backdrop: "white"}}')
JOB_ID=$(curl -s "$API/jobs" \
  -H "$AUTH" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "$BODY" | jq -r .id)

# 3 · Poll until the job is finished
while :; do
  JOB=$(curl -s "$API/jobs/$JOB_ID" -H "$AUTH")
  STATE=$(jq -r .state <<<"$JOB")
  [ "$STATE" = queued ] || [ "$STATE" = running ] || break
  sleep 2
done
[ "$STATE" = succeeded ] || { jq -r .failure.code <<<"$JOB"; exit 1; }

# 4 · Download the image
OUTPUT_ID=$(jq -r '.outputs[0].asset_id' <<<"$JOB")
EXT=$(jq -r '.outputs[0].content_type | ltrimstr("image/")' <<<"$JOB")
curl -sL "$API/assets/$OUTPUT_ID/content" -H "$AUTH" -o "result.$EXT"
抢先体验

下一个系列,本周即可完成拍摄。

抢先体验开放时赠送20积分,无需绑定银行卡。