SP
SkuProfit
API 接口文档
← 返回工作台OpenAPI JSON

概览

SkuProfit 提供 API 供第三方系统随时调用,输入 SKU 基础数据,返回结构化的成本、毛利、毛利率、 保本价、目标售价与费用拆分。所有金额统一以 USD 输出;非 USD 输入通过实时汇率折算。

POST https://<YOUR_HOST>/api/v1/calculate
POST https://<YOUR_HOST>/api/v1/calculate/batch
GET https://<YOUR_HOST>/api/v1/openapi

请求与响应均为 JSON。响应统一为 { success, data }{ success:false, error:{ code, message } }

鉴权

所有 /api/v1 接口需要 API Key。在请求头携带:

Authorization: Bearer sk_live_xxxxxxxx # 或 X-API-Key: sk_live_xxxxxxxx
API Key 由我方为每个接入方单独签发(可设置速率上限、权限范围、有效期)。密钥仅在创建时明文展示一次, 我方仅保存其哈希;请妥善保管、勿泄露、勿写入前端代码。密钥泄露或轮换请联系我方吊销重发。

速率限制

按 API Key 独立限流,默认 120 次/分钟(可按接入方调整)。每个响应包含限流头:

X-RateLimit-Limit: 120 X-RateLimit-Remaining: 118 X-RateLimit-Reset: 1783112400   # 窗口重置的 Unix 秒

超限返回 429,并带 Retry-After(秒)。建议客户端读取上述头做退避重试。

接口:单 SKU 计算

POST /api/v1/calculate

请求字段

字段类型必填说明
platformstring必填amazon / tiktok / temu / shein / mercadolibre(美客多,巴西/拉美)
countrystring必填US / CA / AU / BR(巴西)
categorystring必填类目,用于匹配佣金与税费,如 home
sourcingstring可选cross_border(默认,跨境进口)/ local(本土采购,自动不计国际物流/关税/进口税/清关)
sale_pricenumber必填售价,按 sale_currency 解释
product_costnumber必填单件采购成本,按 input_currency 解释
unit_weight_kgnumber必填单件重量(kg)
skustring可选商品编码,便于对账
input_currencystring可选成本币种,默认 USD,如 CNY
sale_currencystring可选售价币种,默认 USD,可为本币
unit_volume_cbmnumber可选单件体积(cbm),海运按体积计费时必填
shipping_methodstring可选sea / air,默认 sea
freight_pricing_modestring可选fixed / weight / volume / volume_weight_compare
freight_fixed_pricenumber可选一口价运费(USD),计费方式为 fixed 时使用
tax_modestring可选none / simple_preset / manual
target_margin_ratenumber可选目标毛利率,默认 0.3
advertising_ratenumber可选广告预留比例,默认 0.1
return_reserve_ratenumber可选退货预留比例,默认 0.03

完整字段(头程、包材、清关、仓储、各项费用覆盖等)见 OpenAPI。传入 *_fee 覆盖字段时优先于系统费率。

请求示例

curl -X POST https://<YOUR_HOST>/api/v1/calculate \
  -H "Authorization: Bearer sk_live_xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "sku": "ABC-001",
    "platform": "amazon",
    "country": "US",
    "category": "home",
    "input_currency": "CNY",
    "sale_currency": "USD",
    "sale_price": 19.99,
    "product_cost": 36,
    "unit_weight_kg": 0.45,
    "unit_volume_cbm": 0.003,
    "shipping_method": "sea",
    "freight_pricing_mode": "fixed",
    "freight_fixed_price": 1.1
  }'

响应示例

{
  "success": true,
  "data": {
    "sku": "ABC-001",
    "platform": "amazon",
    "country": "US",
    "output_currency": "USD",
    "sale_price_usd": 19.99,
    "total_cost_usd": 16.77,
    "gross_profit_usd": 3.22,
    "gross_margin_rate": 0.1611,
    "break_even_price_usd": 15.32,
    "suggested_price_for_target_margin_usd": 27.10,
    "decision": "watch",
    "cost_detail": { "...": "各费用项 USD" },
    "rate_snapshot": { "...": "本次费率" },
    "exchange_rate_snapshot": { "...": "本次汇率" },
    "warnings": []
  }
}

响应关键字段

字段类型必填说明
total_cost_usdnumber必填单件总成本(USD)
gross_profit_usdnumber必填毛利(USD)
gross_margin_ratenumber必填毛利率,小数(0.1611 = 16.11%)
break_even_price_usdnumber|null必填保本售价
suggested_price_for_target_margin_usdnumber|null必填达到目标毛利率所需售价
decisionstring必填pass / watch / fail / invalid
cost_detailobject必填各费用项拆分(USD)
exchange_rate_snapshotobject必填本次使用的汇率快照
warningsstring[]必填风险/降级提示

接口:批量计算

POST /api/v1/calculate/batch

请求体 { "items": [ CalcInput, ... ] }单条失败不影响其它:失败项返回 success:false 与错误码。

curl -X POST https://<YOUR_HOST>/api/v1/calculate/batch \
  -H "Authorization: Bearer sk_live_xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{ "items": [ { "platform": "amazon", "country": "US", ... }, { ... } ] }'

异步批量 + Webhook 回调

大批量或需要"算完推回总后台"的场景,用异步任务。提交后立即返回 job_id,计算在后台进行。

POST /api/v1/batch-jobs
curl -X POST https://<YOUR_HOST>/api/v1/batch-jobs \
  -H "Authorization: Bearer sk_live_xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [ { "platform":"amazon","country":"US","category":"home",
                 "sale_price":19.99,"product_cost":36,"unit_weight_kg":0.45 } ],
    "callback_url": "https://your-backend/skuprofit/webhook"
  }'
# -> 202 { "job_id":"...", "status":"pending", "poll_url":"/api/v1/batch-jobs/..." }

轮询任务状态与结果:

GET /api/v1/batch-jobs/{id}
{ "status":"completed", "total":1, "success_count":1, "failed_count":0,
  "callback_status":"delivered",
  "result": { "event":"batch.completed", "items":[ { "index":0, "success":true,
              "gross_margin_rate":0.22, "decision":"watch", ... } ] } }

回调(Webhook)与验签

若提交时带了 callback_url,任务完成后我们会 POST 结果到该地址,请求头包含:

X-SkuProfit-Event: batch.completed
X-SkuProfit-Timestamp: 1751622000
X-SkuProfit-Signature: sha256=<hmac>

验签(防伪造):用组织的 Webhook 签名密钥(在「API 与用量」页获取)计算

expected = "sha256=" + HMAC_SHA256(secret, timestamp + "." + rawBody)
// 与 X-SkuProfit-Signature 常量时间比较;并校验 timestamp 新鲜度(如 5 分钟内)
回调请在 2xx 内快速返回;失败会自动重试(最多 3 次,指数退避)。可用轮询作为兜底。

决策值

错误码

HTTPcode说明
401MISSING_API_KEY未携带 API Key
401INVALID_API_KEYAPI Key 无效
401API_KEY_EXPIREDAPI Key 已过期
403API_KEY_DISABLEDAPI Key 已被吊销
403INSUFFICIENT_SCOPEKey 缺少所需权限
429RATE_LIMITED超出速率限制,见 Retry-After
422VALIDATION_ERROR输入校验失败(含字段级明细)
400MISSING_RATE_CARD缺少平台佣金/物流/尾程等关键费率
400PLATFORM_NOT_SUPPORTED平台暂不支持(如 mercadolibre)
400MISSING_EXCHANGE_RATE无可用汇率
500INTERNAL_ERROR服务器内部错误

接入示例(Node.js)

const res = await fetch("https://<YOUR_HOST>/api/v1/calculate", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SKUPROFIT_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    platform: "amazon", country: "US", category: "home",
    input_currency: "CNY", sale_currency: "USD",
    sale_price: 19.99, product_cost: 36, unit_weight_kg: 0.45,
    freight_pricing_mode: "fixed", freight_fixed_price: 1.1,
  }),
});
const { success, data, error } = await res.json();

安全与合规