fix(pricing): require source-backed model prices - #77
Conversation
Walkthrough本 PR 依据新建的 ADR 0013 对定价解析架构进行重构:删除全局别名映射与内置私有定价覆盖;将 OpenAI 推理档位归一化逻辑下沉至会话解析器;将"正价过滤"语义改为"可用价(含 0)过滤";未命中自定义或目录定价时成本回退 Changes定价来源权威重构(ADR 0013)
估计代码审查工作量🎯 4 (Complex) | ⏱️ ~60 minutes 可能相关的 Issues
可能相关的 PRs
诗
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
4f572cd to
b49be7c
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/tokscale-core/src/model_aliases.rs`:
- Around line 52-58: The model alias normalization in model_aliases.rs only
handles hyphen-separated tiers, so `_tier` variants like gpt-5.5_xhigh are not
being mapped to the base model and can miss pricing. Update the normalization
logic in the alias parsing path around the existing rsplit_once('-') handling to
also recognize underscore tier suffixes (and preserve the current
fast/reasoning-tier checks in is_openai_gpt_source_base_model /
OPENAI_REASONING_TIERS), then add tests covering underscore-based aliases such
as gpt-5.5_xhigh and gpt-5.4-mini_xhigh to ensure they resolve to the base model
for pricing lookup.
In `@README.md`:
- Line 409: The “Exact Match” source list is inconsistent with other
documentation references and should be updated to include models.dev alongside
LiteLLM/OpenRouter. Edit the README section containing the Exact Match
description so it matches the existing mentions in the document and keeps the
query strategy wording consistent across the README.
In `@README.zh-cn.md`:
- Line 378: The query strategy description for “精确匹配” is inconsistent with the
broader source list because it only mentions LiteLLM/OpenRouter and omits
models.dev. Update the wording in the README.zh-cn section that describes this
strategy so it matches the three-source declaration used elsewhere, keeping the
text aligned with the symbols and terminology around the query strategy list and
source coverage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: af519999-2cb4-4f0c-bfb4-2f65d295fa2d
📒 Files selected for processing (16)
README.mdREADME.zh-cn.mdcrates/tokscale-cli/src/tui/cache.rscrates/tokscale-core/src/lib.rscrates/tokscale-core/src/message_cache.rscrates/tokscale-core/src/model_aliases.rscrates/tokscale-core/src/pricing/aliases.rscrates/tokscale-core/src/pricing/lookup.rscrates/tokscale-core/src/pricing/mod.rscrates/tokscale-core/src/sessions/droid.rscrates/tokscale-core/src/sessions/pi.rscrates/tokscale-core/tests/anthropic_catalog.rscrates/tokscale-core/tests/fixtures/local_model_ids.txtdocs/adr/0011-token-derived-local-cost.mddocs/adr/0013-pricing-source-authority.mddocs/upstream/2026-06-22.md
💤 Files with no reviewable changes (1)
- crates/tokscale-core/src/pricing/aliases.rs
| if let Some((base, tier)) = model.rsplit_once('-') { | ||
| if (tier == "fast" || OPENAI_REASONING_TIERS.contains(&tier)) | ||
| && is_openai_gpt_source_base_model(base) | ||
| { | ||
| return Some(base.to_string()); | ||
| } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
补上 _tier 后缀解析,否则下划线档位会漏定价。
当前只按 - 拆分,gpt-5.5_xhigh / gpt-5.4-mini_xhigh 这类下划线 tier 不会规范化,后续 pricing lookup 会按未命中回退 $0.00。PR 目标提到支持下划线变体,建议同时补测试覆盖。
建议修复
- if let Some((base, tier)) = model.rsplit_once('-') {
- if (tier == "fast" || OPENAI_REASONING_TIERS.contains(&tier))
- && is_openai_gpt_source_base_model(base)
- {
- return Some(base.to_string());
- }
+ for separator in ['-', '_'] {
+ if let Some((base, tier)) = model.rsplit_once(separator) {
+ if (tier == "fast" || OPENAI_REASONING_TIERS.contains(&tier))
+ && is_openai_gpt_source_base_model(base)
+ {
+ return Some(base.to_string());
+ }
+ }
}Also applies to: 316-330
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/tokscale-core/src/model_aliases.rs` around lines 52 - 58, The model
alias normalization in model_aliases.rs only handles hyphen-separated tiers, so
`_tier` variants like gpt-5.5_xhigh are not being mapped to the base model and
can miss pricing. Update the normalization logic in the alias parsing path
around the existing rsplit_once('-') handling to also recognize underscore tier
suffixes (and preserve the current fast/reasoning-tier checks in
is_openai_gpt_source_base_model / OPENAI_REASONING_TIERS), then add tests
covering underscore-based aliases such as gpt-5.5_xhigh and gpt-5.4-mini_xhigh
to ensure they resolve to the base model for pricing lookup.
| @@ -376,13 +376,11 @@ tokscale pricing "claude-3-5-sonnet" --provider litellm | |||
|
|
|||
| 1. **自定义价格覆盖** - `~/.config/tokscale/custom-pricing.json` 中大小写不敏感的完整 key 精确匹配 | |||
| 2. **精确匹配** - 在 LiteLLM/OpenRouter 数据库中直接查找 | |||
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
查询策略中的“精确匹配”来源缺少 models.dev。
Line 378 仅提到 LiteLLM/OpenRouter,但 Line 1325 已声明三源(含 models.dev)。建议保持一致,避免中文读者误解查询覆盖范围。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@README.zh-cn.md` at line 378, The query strategy description for “精确匹配” is
inconsistent with the broader source list because it only mentions
LiteLLM/OpenRouter and omits models.dev. Update the wording in the README.zh-cn
section that describes this strategy so it matches the three-source declaration
used elsewhere, keeping the text aligned with the symbols and terminology around
the query strategy list and source coverage.
b49be7c to
8f609b5
Compare
Summary
Validation
Summary by cubic
Switch pricing to source-backed catalogs and exact custom overrides only, removing built-in/private prices and global aliases. Parsers now canonicalize OpenAI reasoning-tier routes; catalog lookups accept zero-price rows, prefer original providers in
models.dev, and keep cost at $0.00 when no price matches.Refactors
models.devonly; removed builtin pricing and alias resolver.models.devshares a model part;anthropic/remains canonical when tied.tokscale pricing <model>stays a catalog query. Added ADR 0013; bumped cache schema versions.Migration
~/.config/tokscale/custom-pricing.json.Written for commit 8f609b5. Summary will update on new commits.
Summary by CodeRabbit
新功能
Bug 修复
$0.00,避免被错误估价。文档