基于
docs/testing/video-pricing-test-plan.md| 测试环境:WSL CN (23000)
BASE=http://127.0.0.1:23000
ADMIN_COOKIE="session_m=<从浏览器获取>"
TOKEN="sk-<admin-token>"
登录方式:打开 $BASE → 登录 → DevTools → Application → Cookies → 复制 session_m 的值。
curl -s "$BASE/api/option/model_pricing" \
-H "Cookie: $ADMIN_COOKIE" -H "New-Api-User: 1" | jq
curl -s -X PUT "$BASE/api/option/model_pricing/hailuo-video" \
-H "Cookie: $ADMIN_COOKIE" -H "New-Api-User: 1" \
-H "Content-Type: application/json" -d '{
"schema_version": 1, "scope": "model",
"billing_unit": "per_call", "preconsume_strategy": "exact",
"dimensions": [
{"key": "resolution", "source": "request.resolution", "type": "string", "default": null},
{"key": "duration", "source": "request.duration", "type": "number", "default": null}
],
"table": [
{"resolution": "768P", "duration": 10, "price": 0.04, "source": "manual"},
{"resolution": "1080P", "duration": 10, "price": 0.08, "source": "manual"}
],
"fallback": {"strategy": "reject"}
}' | jq
curl -s "$BASE/api/option/model_pricing/hailuo-video" \
-H "Cookie: $ADMIN_COOKIE" -H "New-Api-User: 1" | jq
curl -s -X DELETE "$BASE/api/option/model_pricing/hailuo-video" \
-H "Cookie: $ADMIN_COOKIE" -H "New-Api-User: 1" | jq
使用 P02 的 body 修改字段来触发各种校验错误:
curl -s -X PUT "$BASE/api/option/model_pricing/test-v" \
-H "Cookie: $ADMIN_COOKIE" -H "New-Api-User: 1" \
-H "Content-Type: application/json" -d '{
"schema_version": 1, "scope": "model",
"billing_unit": "per_call", "preconsume_strategy": "minimum",
"dimensions": [{"key":"r","source":"request.resolution","type":"string","default":null}],
"table": [{"r":"x","price":0.04,"source":"manual"}],
"fallback": {"strategy": "reject"}
}' | jq
# 预期: {"success": false, "message": "billing_unit per_call requires..."}
需要先配置定价,再提交视频任务,观察 quota 变化。
# 1. 配置定价表
curl -s -X PUT "$BASE/api/option/model_pricing/hailuo-video" \
-H "Cookie: $ADMIN_COOKIE" -H "New-Api-User: 1" \
-H "Content-Type: application/json" -d '{
"schema_version": 1, "scope": "model",
"billing_unit": "per_call", "preconsume_strategy": "exact",
"dimensions": [
{"key": "res", "source": "request.resolution", "type": "string", "default": null}
],
"table": [{"res": "768P", "price": 0.04, "source": "manual"}],
"fallback": {"strategy": "reject"}
}'
# 2. 查询当前配额
Q_BEFORE=$(curl -s "$BASE/api/user/self" \
-H "Authorization: Bearer $TOKEN" | jq '.data.quota')
echo "Quota before: $Q_BEFORE"
# 3. 提交视频任务
TASK_ID=$(curl -s -X POST "$BASE/v1/videos" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"model":"hailuo-video","prompt":"test","resolution":"768P"}' \
| jq -r '.id')
echo "Task: $TASK_ID"
# 4. 等待完成(约 45 秒)
sleep 50
# 5. 查询任务结果
curl -s "$BASE/v1/videos/$TASK_ID" \
-H "Authorization: Bearer $TOKEN" | jq
# 6. 查询配额
Q_AFTER=$(curl -s "$BASE/api/user/self" \
-H "Authorization: Bearer $TOKEN" | jq '.data.quota')
echo "Quota after: $Q_AFTER"
echo "Delta: $((Q_BEFORE - Q_AFTER))"
# 预期 delta = 20000 (= 0.04 × 500000)
curl -i -X POST "$BASE/v1/videos" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"model":"hailuo-video","prompt":"reject test","resolution":"NOT_IN_TABLE"}'
# 预期: HTTP 400, quota 不变
配置 "res": "*" + "dur": 10,发送任意 resolution → 匹配 wildcard 行 → quota 扣 0.05×500000=25000
配置 "fallback": {"strategy": "max"},发不匹配请求 → 按表中最高价 0.10 计费
配置 "fallback": {"strategy": "default", "default_price": 0.07} → 不匹配时按 0.07×500000=35000 计费
# 配置 Doubao/Seedance 的 per_1m_tokens 定价
curl -s -X PUT "$BASE/api/option/model_pricing/seedance-2" \
-H "Cookie: $ADMIN_COOKIE" -H "New-Api-User: 1" \
-H "Content-Type: application/json" -d '{
"schema_version": 1, "scope": "model",
"billing_unit": "per_1m_tokens", "preconsume_strategy": "minimum",
"dimensions": [
{"key": "res", "source": "request.resolution", "type": "string", "default": null}
],
"table": [{"res": "1080P", "price": 200, "source": "manual"}],
"fallback": {"strategy": "reject"}
}'
# 提交任务(需 DoubaoVideo 渠道)
curl -s -X POST "$BASE/v1/videos" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"model":"seedance-2","prompt":"test","resolution":"1080P","_mock_total_tokens":1000000}'
# 预扣: PreConsumedQuota × 200 × ratio / 1M ≈ 1 quota
# 结算: 1000000 × 200 / 1M × QuotaPerUnit × ratio
# 对已完成的视频任务进行 remix
curl -s -X POST "$BASE/v1/videos/$ORIGINAL_VIDEO_ID/remix" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"model":"hailuo-video","prompt":"remix version"}'
# 预期: 继承原任务的定价配置, 预扣与原始任务相同
| # | 操作 | 验证点 | ✓ |
|---|---|---|---|
| 1 | 创建配置 | API 返回 200,含完整配置 | |
| 2 | 非法 schema_version=2 | API 返回 400 | |
| 3 | 精确匹配提交任务 | quota 扣除 = price × 500000 | |
| 4 | 不匹配+reject | 400 + quota 不变 | |
| 5 | Wildcard 匹配 | 正确匹配 * 行 | |
| 6 | Fallback max | 扣表中最高价 | |
| 7 | Fallback default | 扣 default_price | |
| 8 | 删除配置 | 200 | |
| 9 | 删除后读取 | 404 |