Add GPT-5.4 model pricing and test cases#395
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough向定价系统添加了对 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
|
@coderabbitai re-review !Stop making breaking changes, do a proper review! |
|
🧠 Learnings used✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/pricing/calculator_test.go (1)
85-90:⚠️ Potential issue | 🟠 Major这个用例没有真正校验
gpt-5.4的定价。现在只断言“非零”,所以
InputPriceMicro/OutputPriceMicro只要不是零,哪怕配错了也会通过。按internal/pricing/default_prices.go当前配置,50_000input +5_000output 应该精确等于200_000_000nanoUSD,建议对新增模型补一个精确断言。可直接落地的改法
+func TestCalculator_Calculate_GPT54ExactCost(t *testing.T) { + calc := GlobalCalculator() + metrics := &usage.Metrics{ + InputTokens: 50_000, + OutputTokens: 5_000, + } + + const want = uint64(200_000_000) + if got := calc.Calculate("gpt-5.4", metrics); got != want { + t.Errorf("Calculate() = %d, want %d", got, want) + } +}Also applies to: 118-126, 153-160
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/pricing/calculator_test.go` around lines 85 - 90, The test cases for the new model (gpt-5.4) only assert non-zero prices, which allows incorrect InputPriceMicro/OutputPriceMicro to pass; update the table-driven tests in internal/pricing/calculator_test.go for the gpt-5.4 entries to assert the exact expected cost: using the configured InputPriceMicro=50_000 and OutputPriceMicro=5_000 from internal/pricing/default_prices.go, compute the total price in nanoUSD (expected 200_000_000) and replace the loose wantZero check with an equality assertion against that exact value (use the same test harness that computes cost from metrics/InputPriceMicro/OutputPriceMicro), and apply the same precise assertion fix to the other affected test cases mentioned (the entries at the other ranges).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/pricing/calculator_test.go`:
- Line 228: 当前测试 TestPriceTable_Get_PrefixMatch 只用了精确键 "gpt-5.4",未触发 prefix
分支;在测试数据里再加入一个以 "gpt-5.4" 为前缀但带后缀的变体(例如 "gpt-5.4-rc" 或 "gpt-5.4-suffix")并调用
pt.Get("gpt-5.4-rc") 或相反(调用 pt.Get("gpt-5.4") 但只在表中存在带后缀的键),以确保代码路径进入 prefix
逻辑;更新断言以验证返回的是通过前缀匹配得到的预期价格/标识(参考函数/方法名:TestPriceTable_Get_PrefixMatch 与
pt.Get)。
---
Outside diff comments:
In `@internal/pricing/calculator_test.go`:
- Around line 85-90: The test cases for the new model (gpt-5.4) only assert
non-zero prices, which allows incorrect InputPriceMicro/OutputPriceMicro to
pass; update the table-driven tests in internal/pricing/calculator_test.go for
the gpt-5.4 entries to assert the exact expected cost: using the configured
InputPriceMicro=50_000 and OutputPriceMicro=5_000 from
internal/pricing/default_prices.go, compute the total price in nanoUSD (expected
200_000_000) and replace the loose wantZero check with an equality assertion
against that exact value (use the same test harness that computes cost from
metrics/InputPriceMicro/OutputPriceMicro), and apply the same precise assertion
fix to the other affected test cases mentioned (the entries at the other
ranges).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a6c3017f-15eb-49dc-b8a2-e00d7579f603
📒 Files selected for processing (2)
internal/pricing/calculator_test.gointernal/pricing/default_prices.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: playwright
- GitHub Check: e2e
🔇 Additional comments (1)
internal/pricing/default_prices.go (1)
279-285:gpt-5.4的价格项补得很干净。字段形状和相邻的
gpt-5.x条目保持一致,后续维护时也更容易按系列检索。
| {"gpt-5.1-codex", true}, | ||
| {"gpt-5.2", true}, | ||
| {"gpt-5.3", true}, | ||
| {"gpt-5.4", true}, |
There was a problem hiding this comment.
这里没有覆盖到真正的前缀匹配路径。
pt.Get("gpt-5.4") 会先命中精确匹配并直接返回,不会进入 prefix 分支。既然这个测试叫 TestPriceTable_Get_PrefixMatch,建议再加一个带后缀的 gpt-5.4 变体来覆盖新增模型的前缀匹配行为。
建议补一个真实的 prefix case
{"gpt-5.2", true},
{"gpt-5.3", true},
{"gpt-5.4", true},
+ {"gpt-5.4-preview", true}, // prefix match
{"gemini-2.5-pro", true},🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/pricing/calculator_test.go` at line 228, 当前测试
TestPriceTable_Get_PrefixMatch 只用了精确键 "gpt-5.4",未触发 prefix 分支;在测试数据里再加入一个以
"gpt-5.4" 为前缀但带后缀的变体(例如 "gpt-5.4-rc" 或 "gpt-5.4-suffix")并调用 pt.Get("gpt-5.4-rc")
或相反(调用 pt.Get("gpt-5.4") 但只在表中存在带后缀的键),以确保代码路径进入 prefix
逻辑;更新断言以验证返回的是通过前缀匹配得到的预期价格/标识(参考函数/方法名:TestPriceTable_Get_PrefixMatch 与
pt.Get)。
🧩 Analysis chain🏁 Script executed: Length of output: 23782 🌐 Web query: 💡 Result: OpenAI’s official GPT‑5.4 API pricing (per 1M tokens) is: $2.50 input, $0.25 cached input, $15.00 output. [1][2] Notes: Data residency / regional processing endpoints add +10% for GPT‑5.4 usage. [1] For >272K input tokens on GPT‑5.4’s 1.05M context window, pricing can be higher (multipliers apply). [2]
✅ Pricing CorrectnessThe
✅ No Breaking ChangesThe change is purely additive — a new ✅ No RegressionsAll existing model entries remain untouched. The ✅
|
This pull request adds support for the new
gpt-5.4model to the pricing calculator, including its pricing details and relevant test coverage. The changes ensure that the calculator recognizesgpt-5.4and applies the correct pricing.Support for new model:
gpt-5.4to thePriceTableindefault_prices.go, specifying input, output, and cache read prices.Test coverage:
gpt-5.4inTestCalculator_Calculateto verify calculation logic for the new model.TestPriceTable_Get_PrefixMatchto includegpt-5.4, ensuring the model is recognized by prefix matching logic.Summary by CodeRabbit
新功能
测试