mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-06 00:48:36 +00:00
fix(billing): harden response-model billing and repair its test fixtures
按上游响应模型计费的准入过宽、且自带用例必然失败,本次一并修复。 严格化准入 - 新增 PricingService.GetIdentifiedModelPricing / BillingService.HasIdentifiedTokenPricing: 只接受价格表中能被确定性识别的条目(精确名、已知拼写变体、去掉日期版本后缀), 不再接受 getFallbackPricing / matchByModelFamily 按子串猜出的系列兜底价。 此前上游只要自报一个含 "haiku" 的编造名字就能被判定"已定价",把账单压到最便宜的 系列价(实测 claude-opus-4.8 基线 $0.0019250 → $0.0000963,20 倍少收)。 GetModelPricing 的对外行为不变,仅把前三步查找抽成共用函数。 - 图片 / 视频 / 网页搜索请求不再走响应模型覆盖:这些路径按张、按秒、按次定价, 与准入检查所验的 token 价不是同一套价格表。 - 准入判断抽成 responseModelBillingDeclaration,两条计费主干共用同一套规则。 正确性与可观测性 - 去掉 recordUsageCore 中 billingModel 的无效赋值(ineffassign 已启用,会让 golangci-lint 直接失败),改由日志表达实际生效的计费基准。 - 补 cost != nil 守卫,与 OpenAI 侧及本文件既有写法对齐。 - 每次实际生效的基准切换记一条 billing.response_model_applied,少收可审计。 - 修正 upstreamResponseModelObserver 上"冲突仅用于诊断、永不影响计费"的过期注释。 测试 - gpt-5.1 与 gpt-5.5 实际共用同一条 gpt-5.4 价格,夹具"价格必须不同"的前置断言 必然失败,OpenAI 侧 3 个用例(含 4 个子用例)从未跑通;改用 gpt-5.4-nano / gpt-5.5。Anthropic 侧 claude-opus-4 不是价格表精确条目,改用 claude-opus-4.8。 - 夹具增加"必须可被确定性识别"的前置断言,避免用例被更靠前的门挡掉而失去判别力。 - 新增:准入规则表驱动用例、可识别性判定用例、编造家族名在两条主干上均被拒的用例。 前端 - 选择该模式时提示"计费基准以上游自报模型为准,只降不升,仅对可信上游启用"。
This commit is contained in:
1 parent
9096492b55
commit
b689e5b401
9 files changed
+336
-51
No files matched your search
@@ -144,6 +144,8 @@ export default {
|
||||
billingModelSourceRequested: 'Bill by requested model',
|
||||
billingModelSourceUpstream: 'Bill by final upstream model',
|
||||
billingModelSourceResponse: 'Bill by upstream response model',
|
||||
billingModelSourceResponseWarning:
|
||||
'Pricing follows the model declared by the upstream response. It can only lower the charge, never raise it — only enable this for upstreams you trust.',
|
||||
billingModelSourceHint: 'Controls which model name is used for pricing lookup',
|
||||
selectedCount: '{count} selected',
|
||||
searchGroups: 'Search groups...',
|
||||
|
||||
@@ -144,6 +144,7 @@ export default {
|
||||
billingModelSourceRequested: '以请求模型计费',
|
||||
billingModelSourceUpstream: '以最终模型计费',
|
||||
billingModelSourceResponse: '按上游响应模型计费',
|
||||
billingModelSourceResponseWarning: '计费基准以上游响应自报的模型为准。该模式只会降低费用、不会抬高,但请仅对可信的上游启用。',
|
||||
billingModelSourceHint: '控制使用哪个模型名称进行定价查找',
|
||||
selectedCount: '已选 {count} 个',
|
||||
searchGroups: '搜索分组...',
|
||||
|
||||
@@ -226,6 +226,9 @@
|
||||
<p class="mt-1 text-xs text-gray-400">
|
||||
{{ t('admin.channels.form.billingModelSourceHint', 'Controls which model name is used for pricing lookup') }}
|
||||
</p>
|
||||
<p v-if="form.billing_model_source === 'response_model'" class="mt-1 text-xs text-amber-500">
|
||||
{{ t('admin.channels.form.billingModelSourceResponseWarning', 'Pricing follows the model declared by the upstream response. It can only lower the charge, never raise it — only enable this for upstreams you trust.') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Platform Management -->
|
||||
|
||||
Reference in new issue
Block a user