跳到主要内容

计费

当前 AIDY 的 provider 计费配置挂在 provider_pricings.pricing 上,schema 定义在 aidy.v2.ext.billing

需要注意两点:

  • aidy.v2.core.ProviderPricing.pricing 在 Management API 里仍然是 google.protobuf.Struct
  • 但其中承载的 JSON 内容,必须符合 aidy.v2.ext.billing.Pricing 的 canonical protobuf JSON 结构

Pricing Proto

原始 proto 定义:

Canonical JSON 示例

最简单的 basePricing

{
"basePricing": {
"textInput": 500,
"textOutput": 1500
}
}

带 cache 定价:

{
"basePricing": {
"textInput": 500,
"textOutput": 1500,
"textInputCacheRead": 50,
"textInputCacheWrite": 800
}
}

带 adjustment 的完整结构示例:

{
"basePricing": {
"textInput": 500,
"textOutput": 1500
},
"adjustments": [
{
"mode": "ADJUSTMENT_MODE_MULTIPLIER",
"when": {
"serviceTier": "priority"
},
"values": {
"textInput": 2,
"textOutput": 2
}
}
]
}

当前实现范围

当前运行时仅实现了 basePricing

也就是说:

  • Management API、seed 和存储层已经按完整 Pricing schema 校验并保存
  • 当前实际扣费逻辑只读取 basePricing
  • adjustments 目前尚未实现,写入后不会参与运行时结算

计费口径

  • 所有 rate 数值都表示“每 1,000,000 tokens 的整数 credit”
  • 当前支持四个文本计费项:
    • textInput
    • textOutput
    • textInputCacheRead
    • textInputCacheWrite
  • 运行时结算口径:
    • textInput = max(input_tokens - cached_read_tokens - cached_creation_tokens, 0)
    • textOutput = output_tokens
    • textInputCacheRead = cached_read_tokens
    • textInputCacheWrite = cached_creation_tokens
  • 四项费用求和后统一四舍五入,0.5 向上,得到最终整数 Credit

不再接受的旧结构

以下 legacy 结构现在都不再接受:

  • input/output
  • textInput_cacheRead / textInput_cacheWrite
  • adjustment 中的字符串 mode,例如 "multiplier"
  • 数组区间写法,例如 [0, "infinity"]