refactor(billing): 长上下文阶梯计价改为价格目录数据驱动 - #6353
Open
feeeei wants to merge 1 commit into
Open
Conversation
删除 GPT/Gemini 系列写死的阶梯规则,阶梯一律由目录数据驱动: - 解析层折算 LiteLLM 的 *_above_XXXk_tokens 绝对价字段为阈值+倍率 (阈值取自字段名,倍率 = above/基础价,cache 侧跟随输入倍率, xAI 按 provider 用达到即进高档语义);显式 long_context_* 字段 按"字段存在"优先,显式 threshold=0 或 multiplier=1 可关闭阶梯 - 删除 OpenAI 272K 常量与 applyModelSpecificPricingPolicy 的长上下文 强补分支、fallbackPrices/静态兜底条目的 LongContext 字段、Gemini 旧 边际规则全链路(CalculateCostWithLongContext / RecordUsageWithLongContext / 阶梯表 marginal 基准);保留 fastRatio 与 GPT-5.6 cache_write 1.25x 防御分支、grok 静态兜底阶梯 - 渠道配置定价区间时完全以渠道区间为准,不再叠加目录阶梯 - 长上下文倍率 ≤0 在应用点按 1 计,防止显式字段残缺把分项乘 0 免费 - 目录重载时对比新旧数据,原有阶梯丢失打 WARN 哨兵告警 行为变化:Gemini 由边际 2x(仅 /v1beta、全模型)改为整单换档(数据 驱动、仅带 above_200k 的 pro 系),渠道平价之上叠加目录阶梯;Claude sonnet-4/4.5 随目录数据获得 200K 整单阶梯(与官方定价一致);模型广场 官方参考价列与实付列同源展示目录阶梯。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
请先合并 Wei-Shaw/model-price-repo#19 再合并本 PR。
本 PR 删除了代码侧的全部长上下文阶梯兜底,阶梯完全依赖价格目录数据(
*_above_XXXk_tokens字段)。#19 是配套的目录数据修正;若本 PR先合并,依赖那批修正条目的部署会在间隙期按基础价计费(少收)。之前错了什么
1. 阶梯规则写死在代码里,与数据源长期脱节
input/output_cost_per_token_above_272k_tokens等绝对价字段,但代码从未解析过它们(全仓rg above_272k零命中)long_context_input_token_threshold/*_cost_multiplier三字段——这套约定在远程目录数据里出现 0 次,唯一载体是 resources fallback 文件里 gpt-5.6 三个条目(运行时被同步数据遮蔽,等于死配置)applyModelSpecificPricingPolicy对 GPT 系强补 272K,目录数据无法关闭它2. Gemini 旧规则与 Google 官方定价存在三处偏差
3. Grok 阶梯从未生效:目录条目(无阶梯字段)优先遮蔽了带阶梯的 Go 兜底价卡——数据侧已在 #19 修复,本 PR 合并后自然生效,无需再改代码。
改成了什么
deriveLongContextFromAboveTierFields把目录的above_XXXk绝对价折算成阈值+倍率——阈值取自字段名,倍率 = above 价 ÷ 基础价,cache 侧跟随输入倍率;_flex/_priority变体与above_1hr(缓存时长)不参与。语义与 LiteLLM 官方 cost calculator 同构:整单换档、严格>、唯 xAI 用≥long_context_*字段按"字段存在"优先:写threshold: 0或multiplier: 1即可在数据层显式关闭某模型的阶梯usesOpenAILegacyLongContextPricing、六个 fallback 价卡的 LongContext 字段、Gemini 旧边际链路(CalculateCostWithLongContext/RecordUsageWithLongContext/ 阶梯表 marginal 基准)。保留 fastRatio 与 GPT-5.6 cache_write 1.25x 两个分支——它们防御的目录数据缺陷(LiteLLM 把 5.5 priority 错标 2x、5.6 缺 cache_write 价)至今存在净效果 17 files,+594/−627。
影响了什么
marginal计价基准不再产生,前端枚举保留兼容测试
make test-unit54 个包全绿