跳到正文
Longplay
开发文档
章节目录 / 设置用量限额与超额计费规则
本页内容

设置用量限额与超额计费规则

操作名
manageBillingLimits
服务端 SDK
manageBillingLimits
Python
manage_billing_limits
Go
ManageBillingLimits
POST/api/v1/billing/controls/manage

后端为 Customer 设置用量上限、提醒阈值和超额规则。

Markdown
API v1更新于

请求#

凭据
Server Key,权限 billing:write。只在后端调用。
SDK
JavaScript createLongplayServer().manageBillingLimits · Python manage_billing_limits · Go ManageBillingLimits
成功状态
HTTP 200
request.shShell
curl -X POST "$LONGPLAY_API_URL/api/v1/billing/controls/manage" \  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \  -H "X-Indiana-Protocol: 0.10" \  -H "Content-Type: application/json" \  -d '{  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",  "command": {    "internal_feature_id": "f317c851-0ef2-4d7a-8e3c-e8a29df676ed",    "entityId": null,    "interval": "month",    "basis": "usage",    "limit": "1000",    "thresholds": [      0.8,      1    ],    "requestId": "0f58d1f8-069f-4288-8ec1-4ed10af55b45"  }}'

响应为示例数据。

请求体参数#

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"

filterobject可选

筛选条件。

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

展开子字段
iduuid必填

授权 的 ID。

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)$

cashPriceobject可选

现金价格。

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"

filterobject可选

筛选条件。

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"

filterobject可选

筛选条件。

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。

可能的错误
codeHTTP何时recovery
INVALID_REQUEST400请求不符合本页的参数。缺少或无法解析协议头时分别返回 UNSUPPORTED_PROTOCOL_VERSION 或 INVALID_PROTOCOL_VERSION。fix_request
UNAUTHENTICATED401凭据缺失、无效、过期或已撤销。authenticate
FORBIDDEN403凭据没有 billing:write 权限。check_permissions
SCOPE_MISMATCH403X-Indiana-Project 或 X-Indiana-Environment 与凭据所属的 App 和环境不一致。check_scope
CONFLICT409同一个 requestId 用了不同的输入(reason: IDEMPOTENCY_CONFLICT)。resolve_conflict
RATE_LIMITED429请求过多;按 Retry-After 等待后用同一请求重试。retry_same_request
SERVICE_UNAVAILABLE503服务暂时不可用;用同一请求重试。retry_same_request
INTERNAL_ERROR500结果未知;先读取原操作,或用原 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

相关:错误码与恢复·请求约定·全部接口