mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-07 17:27:58 +08:00
Three guards on the response_model billing basis, all scoped to the opt-in channel mode so existing channels are unaffected. 1. Per-unit billing gate was stale. Audio (AudioUsage) and the search surcharge (SearchCount) reached the billing paths after this branch was cut; both are priced per unit rather than per token, so they must be excluded like image/video/web-search already are. Audio pricing ignores the model entirely, so the previous code "adopted" a basis switch that changed nothing and emitted a misleading audit log for it. 2. Never zero out a billable request. A catalog entry whose token prices are explicitly 0 still passes the identified-pricing gate (TokenPricingAbsent only means both prices are missing), so an upstream could declare a free model name and drop the bill to zero. Reject a zero (or negative) recomputation whenever the baseline was billable; an already-zero baseline is unaffected. 3. Never cross from channel pricing to the global table. Channel pricing matches exact keys and prefix wildcards and does not strip date suffixes, while the global table's identified lookup does. Upstreams routinely declare dated model IDs (claude-opus-4-5-20251101), so allowing a cross-source comparison would silently bypass an administrator's channel markup on essentially every request. Admins who want a downgrade target discounted can price it explicitly on the channel. Also skip the recomputation entirely when the declared model equals the baseline: it is provably the same cost and only burned a pricing resolve. The identified-pricing helpers now return whether the model resolved to channel pricing so the third guard costs no extra resolve.