fix: account for cache tokens in channel tests#4979
Conversation
Reuse normal text quota calculation for channel model tests so cache read/write tokens and other text quota adjustments are included. Also infer separated cache usage when compatible upstreams report cache tokens outside prompt tokens. Co-authored-by: Codex <noreply@openai.com>
WalkthroughThis PR extends quota calculation to recognize and correctly bill Anthropic-format separated cache-read tokens. It adds cache-detection logic, exposes a new public ChangesCache-aware quota calculation and integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
渠道模型测试的非阶梯计费原先使用了一套简化公式,只计算普通输入和输出 tokens,没有复用正式请求链路中的文本计费逻辑,因此遇到 cache read/write tokens 时会漏算缓存部分。这个改动让渠道测试结算复用正常文本请求的 quota 计算,并补充缓存 token 语义推断和回归测试,避免测试日志中的消耗金额与实际模型用量不一致。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
已通过本地回归测试:
docker run --rm -v /Users/dave/workspace/new-api:/workspace -w /workspace golang:1.25.1 go test ./service ./controller -count=1Summary by CodeRabbit
Bug Fixes
New Features
Tests