SkuProfit 提供 API 供第三方系统随时调用,输入 SKU 基础数据,返回结构化的成本、毛利、毛利率、 保本价、目标售价与费用拆分。所有金额统一以 USD 输出;非 USD 输入通过实时汇率折算。
请求与响应均为 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 独立限流,默认 120 次/分钟(可按接入方调整)。每个响应包含限流头:
X-RateLimit-Limit: 120 X-RateLimit-Remaining: 118 X-RateLimit-Reset: 1783112400 # 窗口重置的 Unix 秒超限返回 429,并带 Retry-After(秒)。建议客户端读取上述头做退避重试。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| platform | string | 必填 | amazon / tiktok / temu / shein / mercadolibre(美客多,巴西/拉美) |
| country | string | 必填 | US / CA / AU / BR(巴西) |
| category | string | 必填 | 类目,用于匹配佣金与税费,如 home |
| sourcing | string | 可选 | cross_border(默认,跨境进口)/ local(本土采购,自动不计国际物流/关税/进口税/清关) |
| sale_price | number | 必填 | 售价,按 sale_currency 解释 |
| product_cost | number | 必填 | 单件采购成本,按 input_currency 解释 |
| unit_weight_kg | number | 必填 | 单件重量(kg) |
| sku | string | 可选 | 商品编码,便于对账 |
| input_currency | string | 可选 | 成本币种,默认 USD,如 CNY |
| sale_currency | string | 可选 | 售价币种,默认 USD,可为本币 |
| unit_volume_cbm | number | 可选 | 单件体积(cbm),海运按体积计费时必填 |
| shipping_method | string | 可选 | sea / air,默认 sea |
| freight_pricing_mode | string | 可选 | fixed / weight / volume / volume_weight_compare |
| freight_fixed_price | number | 可选 | 一口价运费(USD),计费方式为 fixed 时使用 |
| tax_mode | string | 可选 | none / simple_preset / manual |
| target_margin_rate | number | 可选 | 目标毛利率,默认 0.3 |
| advertising_rate | number | 可选 | 广告预留比例,默认 0.1 |
| return_reserve_rate | number | 可选 | 退货预留比例,默认 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_usd | number | 必填 | 单件总成本(USD) |
| gross_profit_usd | number | 必填 | 毛利(USD) |
| gross_margin_rate | number | 必填 | 毛利率,小数(0.1611 = 16.11%) |
| break_even_price_usd | number|null | 必填 | 保本售价 |
| suggested_price_for_target_margin_usd | number|null | 必填 | 达到目标毛利率所需售价 |
| decision | string | 必填 | pass / watch / fail / invalid |
| cost_detail | object | 必填 | 各费用项拆分(USD) |
| exchange_rate_snapshot | object | 必填 | 本次使用的汇率快照 |
| warnings | string[] | 必填 | 风险/降级提示 |
请求体 { "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", ... }, { ... } ] }'大批量或需要"算完推回总后台"的场景,用异步任务。提交后立即返回 job_id,计算在后台进行。
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/..." }轮询任务状态与结果:
{ "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", ... } ] } }若提交时带了 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 分钟内)pass — 毛利率 ≥ 目标毛利率,可进入下一步watch — 低于目标但 ≥ 最低毛利率(默认 15%),需优化fail — 低于最低毛利率,不建议上架invalid — 数据不足,无法判断| HTTP | code | 说明 |
|---|---|---|
| 401 | MISSING_API_KEY | 未携带 API Key |
| 401 | INVALID_API_KEY | API Key 无效 |
| 401 | API_KEY_EXPIRED | API Key 已过期 |
| 403 | API_KEY_DISABLED | API Key 已被吊销 |
| 403 | INSUFFICIENT_SCOPE | Key 缺少所需权限 |
| 429 | RATE_LIMITED | 超出速率限制,见 Retry-After |
| 422 | VALIDATION_ERROR | 输入校验失败(含字段级明细) |
| 400 | MISSING_RATE_CARD | 缺少平台佣金/物流/尾程等关键费率 |
| 400 | PLATFORM_NOT_SUPPORTED | 平台暂不支持(如 mercadolibre) |
| 400 | MISSING_EXCHANGE_RATE | 无可用汇率 |
| 500 | INTERNAL_ERROR | 服务器内部错误 |
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();/api/calculate 等)仅限本站同源调用;第三方一律使用 /api/v1。