fix(billing): correct tiered billing settlement and edge cases
- quota.go: add missing SettleBilling call in PostWssConsumeQuota - text_quota.go: gate InjectTieredBillingInfo on tieredBillingApplied bool instead of tieredResult != nil, so fallback billing still logs metadata - price.go: remove quotaBeforeGroup == 0 from freeModel condition to avoid bypassing settlement for output-only expressions - tiered_settle.go: split cc/cc1h subtraction using UsageSemantic to distinguish OpenAI vs Claude cache creation token formats - pricing.go: only set BillingMode when a non-empty expression exists - useModelPricingEditorState.js: only write billing_mode when finalBillingExpr is non-empty
This commit is contained in:
@@ -330,6 +330,7 @@ func PostTextConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, us
|
||||
summary := calculateTextQuotaSummary(ctx, relayInfo, usage)
|
||||
|
||||
var tieredResult *billingexpr.TieredResult
|
||||
tieredBillingApplied := false
|
||||
if originUsage != nil {
|
||||
var tieredUsedVars map[string]bool
|
||||
if snap := relayInfo.TieredBillingSnapshot; snap != nil {
|
||||
@@ -337,6 +338,7 @@ func PostTextConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, us
|
||||
}
|
||||
tieredOk, tieredQuota, tieredRes := TryTieredSettle(relayInfo, BuildTieredTokenParams(usage, summary.IsClaudeUsageSemantic, tieredUsedVars))
|
||||
if tieredOk {
|
||||
tieredBillingApplied = true
|
||||
tieredResult = tieredRes
|
||||
summary.Quota = composeTieredTextQuota(relayInfo, summary, tieredQuota, tieredRes)
|
||||
}
|
||||
@@ -451,7 +453,7 @@ func PostTextConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, us
|
||||
// prompt/cache fields here, otherwise old upstream payloads may be double-counted.
|
||||
other["input_tokens_total"] = usage.InputTokens
|
||||
}
|
||||
if tieredResult != nil {
|
||||
if tieredBillingApplied {
|
||||
InjectTieredBillingInfo(other, relayInfo, tieredResult)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user