Repository navigation
feat: 生图 usage 计费保底与结算金额折算回包 - #939
Merged
Merged
Conversation
Owner
Author
|
维护独审已完成,当前不接受合并:四项生产源码问题在新提交6019c1f43中均未改变(本次外部增量仅两个历史CI夹具文件)。
父级已确认调用链,反例尚为静态推导,本机未运行动态命令。已启动隔离修复writer,但检测到外部6019c1f43发布后要求其先安全冻结,以防双writer。请当前发布者确认接手以上修复或冻结原分支;当前凭据所见本机无其他实现进程。父级将保持单发布者,不覆盖外部历史。原生截图此前已上传并下载核验,后续正文更新又恢复raw链接,须保留原生附件并删除源树PNG;附件URL见随后正文。未授权生产/付费/发版/部署。 |
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.
解决的问题与行为变化
固定按张采购的图片只按上游 token 收费时,零 usage 或低 token 请求可能无法覆盖成本。OpenAI 分组的 token 价卡新增
image_minimum_charge:最终客户收费取 token 实收与完成图片张数乘保底金额的较大值,用户折扣不再降低保底。原始 token 和账号成本基价保留,补差单独记录。Images 客户可用
X-Image-Usage: billing请求结算用量:结算成功后,从账本八位小数金额折算 usage,原始值放在upstream_usage。每百万折算输出 token 对应 $0.01,整数 token 与实际收费精确对应;它不会把按张请求再次按 token 扣费。默认不带头时不改回包。模型广场单独展示最终每张保底。明确 image 价卡的零图片 Responses 不再走默认一张的收费分支;显式 image 价卡及保底组的 Images 以实际返回张数计量。
关联记录与来源
用户要求三站新增按 usage 计费的图片分组,并提供兼容 token 记账的按张回包。基线
production/feb761541918d25a73779c6ea42ee28f61b5591e。无外部代码引入。历史 RED 检查还原旧实现时,新图片用量测试依赖的符号不存在;已将这两份测试加入既有完整历史覆盖清单。仅作用于经过旧源码摘要校验的 RED 工作树,候选 GREEN 保留全部测试。另为 Free Fast 的局部历史覆盖增加精确基线声明适配:只补 DTO 字段,旧计费/缓存快照生产逻辑与测试断言不变;nil 字段省略以保留原缺失字段诊断。另补近期余额通知、Grok限流历史与NewAPI成本独立测试的完整历史覆盖适配。管理员新功能提示
image-usage-minimum-charge-20261119,登记在NEW_FEATURE_NOTICES.imageUsageBilling。PricingEntryCard,同一 ID。NewFeatureBadge;这是新功能 ID,普通修复不更换。复现与验收
image价卡无输出图片时扣费为零,有 2 张时只收 2 张,不叠加响应 token。X-Image-Usage: billing,JSON/SSE 结算后输出等价 usage;多图 SSE 只在最后一个图片完成事件附总量。image_usage_billing_test.go、image_billing_response_test.go、image_count_billing_switch_test.go、PlazaModelPricingTable.spec.ts。协议、调度或传输补充
实际验证
git diff --cached --checkgofmt -w(改动 Go 文件)backend/:GOMAXPROCS=2 go test -p 2 -tags=unit ./internal/service ./internal/handler -run 'Test(ImageMinimumCharge|ImageBilling|RecordImageUsageFloor|ImageReceiptComes|ExplicitImageCard)' -count=1 -timeout=5m/tmp/image-free-fast-red-20261119/: 还原工作流指定历史生产文件,运行同一组 Free Fast/缓存定向测试及free-fast-cost-evidence.py redgo test -p 2 -json -tags=unit ./internal/service -run '^TestOpenAI409WSTicketBoundEgress$' -count=1 -timeout=5m;assert-ws-readable.py RED 1 ... ws-ticket6019c1f43ab145c0c5d9d1c0e562876686e9cf06的全部检查兼容性与运行影响
文档与用户可见变化
接入与计价说明 区分按张、真实 token 与结算折算 token;说明最低收费、单位、SSE 行为、失败处理、区域节点限制和回滚边界。新生图分组仍需部署后另行配置保底,PR 合并不代表上线。
组件截图(本地虚构数据;来源与文件摘要见截图目录 manifest):
Agent 使用声明
提交前自查