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:
CaIon
2026-04-24 00:33:54 +08:00
parent 8eeae00737
commit 3e5f2ee1d6
6 changed files with 25 additions and 10 deletions
+14 -5
View File
@@ -22,8 +22,14 @@ func BuildTieredTokenParams(usage *dto.Usage, isClaudeUsageSemantic bool, usedVa
p := float64(usage.PromptTokens)
c := float64(usage.CompletionTokens)
cr := float64(usage.PromptTokensDetails.CachedTokens)
ccTotal := float64(usage.PromptTokensDetails.CachedCreationTokens)
cc1h := float64(usage.ClaudeCacheCreation1hTokens)
cc5m := float64(usage.PromptTokensDetails.CachedCreationTokens)
cc1h := float64(0)
if usage.UsageSemantic == "anthropic" {
cc1h = float64(usage.ClaudeCacheCreation1hTokens)
cc5m = float64(usage.ClaudeCacheCreation5mTokens)
}
img := float64(usage.PromptTokensDetails.ImageTokens)
ai := float64(usage.PromptTokensDetails.AudioTokens)
imgO := float64(usage.CompletionTokenDetails.ImageTokens)
@@ -33,8 +39,11 @@ func BuildTieredTokenParams(usage *dto.Usage, isClaudeUsageSemantic bool, usedVa
if usedVars["cr"] {
p -= cr
}
if usedVars["cc"] || usedVars["cc1h"] {
p -= ccTotal
if usedVars["cc"] {
p -= cc5m
}
if usedVars["cc1h"] {
p -= cc1h
}
if usedVars["img"] {
p -= img
@@ -61,7 +70,7 @@ func BuildTieredTokenParams(usage *dto.Usage, isClaudeUsageSemantic bool, usedVa
P: p,
C: c,
CR: cr,
CC: ccTotal - cc1h,
CC: cc5m,
CC1h: cc1h,
Img: img,
ImgO: imgO,