构建 · AI 摄影 SaaS

构建 AI 商品摄影服务

一句话总结

为每个租户配置一个 Photta API key(若调用量较小则共用一个连接池),将每个客户的目录扇出至队列中,针对每个商品调用 /api/v1/tryon/apparel,在 worker 池中 polling 任务的 generation ID,将结果存储到客户的 bucket 中,并在 Photta 的 credit 成本之上加价,对每个计费单元(credit 或渲染出的图像)开具账单。

  • Credits: 2K 分辨率 5 credits · 4K 分辨率 6 credits
  • 常规耗时: 1.5–4 min
  • 处理方式: 异步,轮询

本页所有数据均来自 Photta API 文档 · 已验证

扇出遍历客户的目录,按商品派发 try-on 任务,按 credit 开具账单。只要遵循系统边界,Photta 提供给独立开发者的底层原语就能组合成一个白标 SaaS。

RESPONSE=$(curl -s -X POST https://api.photta.app/api/v1/tryon/apparel \
  -H "Authorization: Bearer $PHOTTA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "product_type": "top",
  "product_images": [
    "https://cdn.yourstore.com/products/shirt-front.jpg"
  ],
  "product_back_image": "https://cdn.yourstore.com/products/shirt-back.jpg",
  "product_category": "t_shirt",
  "mannequin_id": "mnk_f3a9b1",
  "pose_id": "pose_c2d4e5",
  "background": "https://cdn.yourstore.com/backgrounds/studio-loft.jpg",
  "lock_background": true,
  "resolution": "2K",
  "aspect_ratio": "3:4",
  "body_size": "M",
  "expression": "neutral",
  "user_instruction": "Keep the collar pattern crisp and centered."
}')
ID=$(echo "$RESPONSE" | jq -r '.data.id')

工作原理

从单个 key 到多租户服务

编写生产代码前你需要做出的五个架构决策。

  1. 步骤 1

    定义你的产品契约

    确定客户每个计费单元能获得什么:一张渲染图像?一个批次?还是每月 credit 额度池?你的答案决定了后续的一切——队列深度、重试策略、定价页面文案。

  2. 步骤 2

    按租户配置 Photta key

    小规模:使用单个共享 key,在自己的数据库中跟踪各租户的使用量。较大规模:每个租户分配一个 Photta key,通过 Photta 控制台管理——归因更清晰,发生泄漏时的爆炸半径也更小。

  3. 步骤 3

    通过队列进行扇出

    针对客户 Feed 中的每个商品,将一个拍照任务推入队列。切勿在 CSV 导入期间同步提交——否则会触碰每分钟 600 次请求的 rate limit,并因 429 导致任务丢失。

  4. 步骤 4

    在 credit 价格之上增加利润空间

    每次 4K 服装渲染消耗你 6 credits。你发送的每张账单金额应为 credits × 你的利润率。在账本中记录原始 credit 成本,以便财务将 Photta 的账单与你的营收线进行对账。

  5. 步骤 5

    监控延迟与失败率

    按租户跟踪完成时间与失败率。当某个客户的照片耗时始终超过 4 分钟或反复失败时,几乎总是输入数据有问题(损坏的 URL、不受支持的 product_type)——而不是 Photta 的问题。

你将需要的三个模式

扇出、按租户派发、计费账本——摄影 SaaS 的核心支柱。

// For each product in the customer's feed, kick off a try-on.
for (const product of catalog) {
  await photoQueue.add("photo", {
    customerId: product.customer_id,
    productUrl: product.image,
    productType: product.type, // "top" | "bottom" | "top_and_bottom" | "one_piece"
  });
}
const res = await fetch("https://api.photta.app/api/v1/tryon/apparel", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PHOTTA_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    "product_type": "top",
    "product_images": [
      "https://cdn.yourstore.com/products/shirt-front.jpg"
    ],
    "product_back_image": "https://cdn.yourstore.com/products/shirt-back.jpg",
    "product_category": "t_shirt",
    "mannequin_id": "mnk_f3a9b1",
    "pose_id": "pose_c2d4e5",
    "background": "https://cdn.yourstore.com/backgrounds/studio-loft.jpg",
    "lock_background": true,
    "resolution": "2K",
    "aspect_ratio": "3:4",
    "body_size": "M",
    "expression": "neutral",
    "user_instruction": "Keep the collar pattern crisp and centered."
  }),
});
const { data } = await res.json(); // data.id, data.status
// A completed apparel job costs 5 credits at 2K and 6 at 4K.
// Record it to your billing pipeline so you can margin on top of it.
await billingLedger.append({
  customer: data.customerId,
  sku: "photo-4k",
  quantity: 1,
  wholesaleCost: 6, // credits, = your Photta spend
});

开发者常见问题

在 Photta 之上运行服务

我需要为每个租户准备单独的 Photta API key 吗?

不需要,但在规模化时很有帮助。客户较少时,使用单个共享 key 并在自己的数据库中跟踪各租户的使用量就足够了。超出这个规模后,每个租户独立分配 key 可以带来更清晰的归因、更轻松的轮换,以及在发生泄漏时更小的爆炸半径。

credits 耗尽时该怎么办?

API 会返回 402 insufficient_credits 以及所需和可用的数量。设置一个低水位线(例如 100 credits),在任务开始失败前自动充值。失败的任务会退还其 credits,因此偶发的 402 错误不会造成连锁损失。

我应该如何为我的服务定价?

Photta 在 2K 分辨率下收取 5 credits,4K 收取 6 credits。将其换算为您的零售货币(成本 × 利润率 × credit 汇率),并决定是按张计费、按批次计费还是按月计费。大多数摄影 SaaS 产品最终都会采用按张计费并设置月度最低消费。

Photta 提供哪些 SLA?

Photta 文档记录的单任务完成窗口为 1.5 到 4 分钟。目前没有发布硬性的运行时间 SLA。如果您的 SaaS 承诺了自己的交付时间,请在自己的合同中留出缓冲空间(例如,“1 小时内交付照片”可为您提供 10 倍的冗余),并监控每个租户的延迟以尽早发现性能衰退。

我可以对输出进行白标处理(White-label)吗?

可以。返回的图像不带 Photta 品牌标识。您可以将其投递到客户的存储桶中,并在前端挂上您自己的 CDN 域名——您的客户完全无需知道它们是由 Photta 的流水线生成的。API 本身不是白标的——密钥和控制台均带有 Photta 品牌标识。

基于 Photta 构建并发布摄影 SaaS

同样的 API,您的品牌,您的利润。获取 API 密钥,将上述三种模式接入您的 worker,您就完成了一半的上线准备。