Repository navigation
feat: 添加账号级 UltraFast 响应档位计费开关 - #641
Merged
ranxi2001 merged 2 commits intoNov 3, 2026
Merged
Conversation
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.
解决的问题与行为变化
兼容上游可能将整个 API Key 账号下的模型固定服务为 UltraFast:客户端没有指定档位,上游仍返回
service_tier=ultrafast并按该档位收费。现有只允许响应降档的策略会保留普通/priority 请求档位;模型专属6倍规则也无法覆盖该账号的所有模型。extra.openai_response_tier_billing_enabled。model也可读取service_tier。缺失/未知响应档位时按最终出站请求档位回退并记录告警。ultrafast结算的 token 模型统一使用模型标准单价×6,包含缓存读写,再应用有效账号/分组倍率。Fast/priority 保持独立规则,不重复套 Fast 价格。关联记录与来源
ranxi2001/sub2api的production,提交c0de6149ebcfd43002f7540e192f2e5d9bd8b03f(v2.19.2)。这是在本 fork 上整理的本地改动,没有从其他仓库 cherry-pick 提交。复现与验收
使用虚构 OpenAI API Key 账号与离线响应,不需要真实上游凭据:
{"response":{"service_tier":"ultrafast"}}:保留请求普通档,不自动升档。ultrafast,所有受测 token 模型的普通输入、输出、缓存读写按标准价×6。default:允许降档。ultrafast,响应同档或无档位:开关关闭、缺失、开启三种情况均按6倍;例如离线 GPT-6 Sol 用例在分组0.25时实扣$0.01665000。新增回归覆盖 GPT-5.6 Sol/Terra、GPT-6 Astra/Sol、GPT-6.1 Sol/Terra;272000/272001上下文边界、高缓存命中、普通/UltraFast交替计价、5m/1h混合缓存写、显式零价缓存写、实际
RecordUsage扣费命令及模拟耐久仓库重试/缓存失败恢复。HTTP/SSE/WS 使用现有的响应观察和用量结算接口。本次仅扩展档位识别与结算策略,不新增网络重试、故障转移或扣费路径。幂等/缓存恢复测试使用模拟仓库,不作为真实 PostgreSQL/Redis 事务或进程崩溃测试的证明。
实际验证
首轮隔离验证对应实现提交
5fc0ef4724585d65a0d14564ce64fd29978c3a6d,基线为上述c0de614。补充测试提交6d5eb5c90e6bd8f189cc2ef7a7bc8552208946c5仅更新响应观察器的原有契约测试,生产源码不变。后端在断网、限额的隔离容器中执行,不连接生产数据库、Redis 或付费上游。首轮 GitHub 完整单元测试在
TestUpstreamResponseModelObserver_ObservesServiceTier失败:原断言要求无model时忽略终态service_tier,与本 PR 支持兼容上游不重复模型名的行为冲突。已将其更新为普通、Priority、UltraFast 三种明确期望,并保留非终态请求回显必须忽略、模型名不凭空生成、已有模型名不被清空的断言。go test -p 1 -tags unit -json文件列表定向回归TestUpstreamResponseModelObserver_ObservesServiceTier,总计557条 test/subtest 通过记录,零失败、零跳过;该函数及4个新增子测试均通过。测试源文件 SHA-256 与提交前源码一致。6d5eb5c;make test-unit、make test-integration、前端类型/关键测试及构建、golangci-lint 均通过。当前 PR 24 项检查成功、25 项按工作流条件跳过,零失败、零等待。pnpm run buildvue-tsc与 Vite 构建;存在既有 chunk-size 警告。表单测试存在 jsdom localhost 请求警告,未导致失败。CGO_ENABLED=0 go build -p 1 -o /out/sub2api ./cmd/serverae7e0dccb12548fb5d890484cefebc4693cf80c0678ac8dc228d61784913855c。此项未使用embedtag,前端构建单独验证。git diff --check、公开内容凭据/敏感信息检查本地隔离验证仅为上述定向回归:完整 service 包的无关测试图超出隔离构建内存预算,因此按 Go 选定的全部生产源文件与相关测试文件编译并复用现有 fixture helper。后续 GitHub 当前 head 已完成全仓单元/集成测试命令及全量 lint;通过命令不表示所有条件性集成用例都实际运行,也不替代 UltraFast 的真实数据库扣费、进程崩溃恢复或付费上游验收。未进行真实上游 TPS 测试或生产部署。
兼容性与运行影响
extra。开关加入调度精简缓存白名单,沿用正常保存时的账号快照同步与outbox。文档与用户可见变化
docs/openai-ultrafast-billing.md说明账号开关、档位选择表、缓存/长上下文、有效倍率与成本统计倍率区别、适用范围和兼容性。Agent 使用声明
gpt-6-astra(xhigh),以及gpt-6.1-sol(high、xhigh、max);本次 PR 整理使用gpt-6.1-sol/max。名称与强度取自本地会话元数据。提交前自查