设置用量限额与超额计费规则
- 操作名
manageBillingLimits- 服务端 SDK
manageBillingLimits- Python
manage_billing_limits- Go
ManageBillingLimits
POST/api/v1/billing/controls/manage
后端为 Customer 设置用量上限、提醒阈值和超额规则。
API v1更新于
- 凭据
- Server Key,权限
billing:write。只在后端调用。 - SDK
- JavaScript
createLongplayServer().manageBillingLimits · Python manage_billing_limits · Go ManageBillingLimits - 成功状态
- HTTP 200
1curl -X POST "$LONGPLAY_API_URL/api/v1/billing/controls/manage" \2 -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \3 -H "X-Indiana-Protocol: 0.10" \4 -H "Content-Type: application/json" \5 -d '{6 "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",7 "command": {8 "internal_feature_id": "f317c851-0ef2-4d7a-8e3c-e8a29df676ed",9 "entityId": null,10 "interval": "month",11 "basis": "usage",12 "limit": "1000",13 "thresholds": [14 0.8,15 116 ],17 "requestId": "0f58d1f8-069f-4288-8ec1-4ed10af55b45"18 }19}'
响应为示例数据。
请求体参数#
application/json
customerIduuid必填Customer 的 UUID。
commandobject | object | object必填要执行的命令;其中的 action 或 operation 决定其余字段。
展开子字段
internal_feature_iduuid | uuid | uuid必填Feature 的 ID。
entityIduuid | null | uuid | null | uuid | null必填当前客户范围内的 Entity ID;只用于已配置的 Entity 和许可 Feature。
intervalenum可选周期,取值见允许值。
查看允许值
"day""week""month""year"
anchorenum可选周期对齐方式,取值见允许值。
查看允许值
"billing_cycle""utc"
basisenum可选计量依据:用量(usage)或积分(credits)。
查看允许值
"usage""credits"
limitstring | null可选一页返回的最大记录数量,受契约上限限制。
thresholdsarray可选按上限比例的提醒阈值,如 0.8。
maxItems: 8
includedThresholdsarray可选按套餐内额度比例的提醒阈值。
maxItems: 8
absoluteThresholdsarray可选按绝对数量的提醒阈值。
maxItems: 8
requestIduuid | uuid | uuid必填你的业务请求 UUID;同一次操作重试复用,新的操作生成新值。
control"overage" | "overage"可选传 overage 表示设置或移除某个 Feature 的超额策略(配合 action);省略则设置用量限制规则。
action"set" | "remove"可选本次业务动作。不同动作的目标字段和数量要求不同,见请求结构与示例。
allowedboolean | null可选当前评估时是否允许访问此 Feature。仅用于展示,业务操作仍需后端授权。
overageLimitstring | null可选窗口内只计算超出包含额度的单位数量,预扣占用容量。null 不设上限,0 禁止新增超额。
skipOverageBillingboolean可选显式允许超额时免收现金费用,仍记录用量并执行数量上限。
响应字段#
成功响应都包含 requestId(本次请求 ID,排查时提供)和 scope(App 与环境)。
HTTP 200 · application/json
requestIduuid必填服务端为这次 HTTP 请求生成的 UUID,排查时提供;它不是你的业务 requestId。
scopeobject必填响应实际所属的 App 和环境。Header 只能核对,不能切换 Key 范围。
展开子字段
projectIdstring必填凭据绑定的 App ID。
minLength: 1
environmentenum必填独立数据范围:sandbox 或 live。
查看允许值
"sandbox""live"
controlsobject必填计费控制设置。
展开子字段
authorizationsarray必填授权,字段见下。
maxItems: 100
展开子字段
termsobject | object必填条款内容。
展开子字段
productVersionIduuid | uuid必填Product Version 的 ID。
internal_feature_iduuid | uuid必填Feature 的 ID。
currencyenum | enum必填已发布价格支持的币种代码。
kind"auto_topup" | "postpaid"必填类型,取值见允许值。
thresholdstring可选触发阈值,十进制字符串。
pattern: ^-?(0|[1-9]\d{0,11})(\.\d{1,6})?$
quantitystring可选数量,十进制字符串,避免浮点误差。
pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
purchaseLimitobject可选自动购买的上限(可选)。
purchaseAmountMinorstring可选金额,以最小货币单位计(如美分)。
pattern: ^(?:[1-9]\d{0,7}|1\d{8}|200000000)$
purchaseUnitsstring可选购买数量。
pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
maxAmountMinorPerPeriodstring可选仅用于 postpaid 条款:每个计费周期最多可收取的金额(不含税),以最小货币单位的整数字符串表示(1–200000000)。
pattern: ^(?:[1-9]\d{0,7}|1\d{8}|200000000)$
maxOutstandingMinorstring可选金额,以最小货币单位计(如美分)。
pattern: ^(?:[1-9]\d{0,7}|1\d{8}|200000000)$
statusenum必填状态,取值见允许值。
查看允许值
"prepared""active""revoked""blocked"
createdAtdate-time必填记录创建时的 ISO 8601 UTC 时间。
acceptedAtdate-time | null必填时间(ISO 8601)。
effectiveAtdate-time | null必填时间(ISO 8601)。
revokedAtdate-time | null必填时间(ISO 8601)。
limitsarray必填用量上限设置。
maxItems: 100
展开子字段
internal_feature_iduuid必填Feature 的 ID。
entityIduuid | null必填当前客户范围内的 Entity ID;只用于已配置的 Entity 和许可 Feature。
intervalenum必填周期,取值见允许值。
查看允许值
"day""week""month""year"
anchorenum可选周期对齐方式,取值见允许值。
查看允许值
"billing_cycle""utc"
basisenum必填计量依据:用量(usage)或积分(credits)。
查看允许值
"usage""credits"
limitstring | null必填一页返回的最大记录数量,受契约上限限制。
thresholdsarray必填按上限比例的提醒阈值,如 0.8。
maxItems: 8
includedThresholdsarray可选按套餐内额度比例的提醒阈值。
maxItems: 8
absoluteThresholdsarray可选按绝对数量的提醒阈值。
maxItems: 8
overagesarray可选超额设置。
maxItems: 100
展开子字段
internal_feature_iduuid必填Feature 的 ID。
entityIduuid | null必填当前客户范围内的 Entity ID;只用于已配置的 Entity 和许可 Feature。
allowedboolean | null必填当前评估时是否允许访问此 Feature。仅用于展示,业务操作仍需后端授权。
overageLimitstring | null必填窗口内只计算超出包含额度的单位数量,预扣占用容量。null 不设上限,0 禁止新增超额。
skipOverageBillingboolean必填显式允许超额时免收现金费用,仍记录用量并执行数量上限。
intervalenum必填周期,取值见允许值。
查看允许值
"day""week""month""year"
startsAtdate-time必填时间(ISO 8601)。
endsAtdate-time必填时间(ISO 8601)。
usedstring必填当前计量周期内已用额度。
pattern: ^(0|[1-9]\d{0,23})(\.\d{1,6})?$
reservedstring必填已预留的数量。
pattern: ^(0|[1-9]\d{0,23})(\.\d{1,6})?$
remainingstring | null必填评估时的剩余额度,不预占,也不保证稍后消费成功。
windowsarray必填统计窗口,字段见下。
maxItems: 200
展开子字段
internal_feature_iduuid必填Feature 的 ID。
entityIduuid | null必填当前客户范围内的 Entity ID;只用于已配置的 Entity 和许可 Feature。
intervalenum必填周期,取值见允许值。
查看允许值
"day""week""month""year"
anchorenum可选周期对齐方式,取值见允许值。
查看允许值
"billing_cycle""utc"
basisenum必填计量依据:用量(usage)或积分(credits)。
查看允许值
"usage""credits"
startsAtdate-time必填时间(ISO 8601)。
endsAtdate-time必填时间(ISO 8601)。
usedstring必填当前计量周期内已用额度。
pattern: ^(0|[1-9]\d{0,12})(\.\d{1,12})?$
reservedstring必填已预留的数量。
pattern: ^(0|[1-9]\d{0,12})(\.\d{1,12})?$
limitstring | null必填一页返回的最大记录数量,受契约上限限制。
thresholdsarray必填按上限比例的提醒阈值,如 0.8。
maxItems: 8
notifiedThresholdsarray必填已发送通知的上限比例阈值。
maxItems: 1024
includedThresholdsarray可选按套餐内额度比例的提醒阈值。
maxItems: 8
includedAllowancestring可选套餐内包含的额度。
pattern: ^(0|[1-9]\d{0,17})(\.\d{1,12})?$
notifiedIncludedThresholdsarray可选已发送通知的套餐内额度阈值。
maxItems: 1024
absoluteThresholdsarray可选按绝对数量的提醒阈值。
maxItems: 8
notifiedAbsoluteThresholdsarray可选已发送通知的绝对数量阈值。
maxItems: 1024
autoTopupsarray必填自动充值设置。
maxItems: 100
展开子字段
authorizationIduuid必填授权的 ID。
statusenum必填状态,取值见允许值。
查看允许值
"idle""pending""blocked"
taskIduuid | null必填任务的 ID。
invoiceIduuid | null必填发票的 ID。
hostedInvoiceUrluri | null必填发票托管页面链接。
purchaseCountinteger必填当前 purchaseLimit 窗口(截止于 purchaseWindowEndsAt)内已完成的自动充值购买次数;没有进行中的窗口时为 0。
min: 0 · max: 9007199254740991
purchaseWindowEndsAtdate-time | null必填时间(ISO 8601)。
attemptCountinteger必填当前 10 分钟尝试窗口内的自动充值尝试次数;达到 2 次后自动充值暂停,直到 nextAttemptAt。没有进行中的窗口时为 0。
min: 0 · max: 9007199254740991
failedAttemptCountinteger必填当前 1 小时窗口内失败的自动充值尝试次数;失败 1 次后自动充值暂停,直到 nextAttemptAt。没有进行中的窗口时为 0。
min: 0 · max: 9007199254740991
suspendedAtdate-time | null必填时间(ISO 8601)。
nextAttemptAtdate-time | null必填时间(ISO 8601)。
failureReasonstring | null必填失败原因。
limitedboolean必填匹配的用量限制规则超过 100 条时为 true,此时 limits 只列出前 100 条。
失败时返回错误对象,按 error.code 与 error.recovery 处理。下表是这个接口的凭据、作用域和幂等字段决定的错误;视请求内容还可能返回 NOT_FOUND(引用的资源不存在)、NOT_CONFIGURED(所需的集成未连接)或 PAYLOAD_TOO_LARGE。有些拒绝(如余额不足)不是错误,而是成功响应里的 reason。
可能的错误| code | HTTP | 何时 | recovery |
|---|
INVALID_REQUEST | 400 | 请求不符合本页的参数。缺少或无法解析协议头时分别返回 UNSUPPORTED_PROTOCOL_VERSION 或 INVALID_PROTOCOL_VERSION。 | fix_request |
UNAUTHENTICATED | 401 | 凭据缺失、无效、过期或已撤销。 | authenticate |
FORBIDDEN | 403 | 凭据没有 billing:write 权限。 | check_permissions |
SCOPE_MISMATCH | 403 | X-Indiana-Project 或 X-Indiana-Environment 与凭据所属的 App 和环境不一致。 | check_scope |
CONFLICT | 409 | 同一个 requestId 用了不同的输入(reason: IDEMPOTENCY_CONFLICT)。 | resolve_conflict |
RATE_LIMITED | 429 | 请求过多;按 Retry-After 等待后用同一请求重试。 | retry_same_request |
SERVICE_UNAVAILABLE | 503 | 服务暂时不可用;用同一请求重试。 | retry_same_request |
INTERNAL_ERROR | 500 | 结果未知;先读取原操作,或用原 ID 和原输入重放。 | recover_operation |
可能的错误
INVALID_REQUEST
- HTTP
- 400
- 何时
- 请求不符合本页的参数。缺少或无法解析协议头时分别返回
UNSUPPORTED_PROTOCOL_VERSION 或 INVALID_PROTOCOL_VERSION。 - recovery
fix_request
UNAUTHENTICATED
- HTTP
- 401
- 何时
- 凭据缺失、无效、过期或已撤销。
- recovery
authenticate
FORBIDDEN
- HTTP
- 403
- 何时
- 凭据没有
billing:write 权限。 - recovery
check_permissions
SCOPE_MISMATCH
- HTTP
- 403
- 何时
X-Indiana-Project 或 X-Indiana-Environment 与凭据所属的 App 和环境不一致。- recovery
check_scope
CONFLICT
- HTTP
- 409
- 何时
- 同一个
requestId 用了不同的输入(reason: IDEMPOTENCY_CONFLICT)。 - recovery
resolve_conflict
RATE_LIMITED
- HTTP
- 429
- 何时
- 请求过多;按
Retry-After 等待后用同一请求重试。 - recovery
retry_same_request
SERVICE_UNAVAILABLE
- HTTP
- 503
- 何时
- 服务暂时不可用;用同一请求重试。
- recovery
retry_same_request
INTERNAL_ERROR
- HTTP
- 500
- 何时
- 结果未知;先读取原操作,或用原 ID 和原输入重放。
- recovery
recover_operation
相关:错误码与恢复·请求约定·全部接口