feat: add Gemini 3.1 Pro pricing and model aliases#125
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughIntroduced TieredPricing and TieredCaching wrappers with bracket_pricing semantics; migrated tiered pricing/caching variants to use them and updated many model entries (including gemini-3.1-pro-preview). Threaded bracket_pricing through cost calculations and tests. Added a Codex CLI guard to avoid duplicate assistant emits, a comment tweak in Copilot analyzer, and small dependency updates. Changes
Sequence Diagram(s)(omitted — changes are primarily data-structure and calculation refactors plus small parser guard) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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 |
- Tiered pricing: $2.00/$12.00 per 1M tokens (≤200k), $4.00/$18.00 (>200k) - Google-style caching tiers: $0.20 (≤200k), $0.40 (>200k) - Aliases: gemini-3.1-pro-preview, gemini-3.1-pro - Fix pre-existing clippy::collapsible_match warnings
e844043 to
7588e48
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/models.rs (1)
1008-1009: Add a regression test for the new aliases.A small table-driven test for
get_model_info("gemini-3.1-pro")andget_model_info("gemini-3.1-pro-preview")would lock down the alias mapping and catch future pricing drift around this entry.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/models.rs` around lines 1008 - 1009, Add a table-driven unit test that calls get_model_info for both "gemini-3.1-pro" and "gemini-3.1-pro-preview" and asserts they resolve to the same canonical model and expected pricing; place it near other model tests (e.g., in the tests module or tests/ directory). The test should iterate over inputs ["gemini-3.1-pro", "gemini-3.1-pro-preview"], call get_model_info(input), assert the returned ModelInfo.id (or equivalent canonical identifier) equals "gemini-3.1-pro-preview" (or the current canonical id used in the mapping) and assert the pricing fields match the current expected values to catch future drift. Use descriptive test name and table rows so future updates can update expected price in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/models.rs`:
- Around line 538-566: The Gemini entry "gemini-3.1-pro-preview" is defined with
tiered pricing but the business intent is bracket pricing (charge the full usage
at the >200k rate), so either mark this model as bracketed and/or change the
pricing data and logic: add a bracket_pricing flag on PricingStructure or
PricingTier and set it for gemini-3.1-pro-preview, then update
calculate_tiered_cost() and calculate_tiered_cache_cost() to check that flag
and, when true, select the single tier whose range contains the total tokens and
multiply the entire usage by that tier's rate (instead of applying tiers
progressively). Ensure you update both PricingStructure::Tiered usage for
caching (CachingTier) and the model entry for gemini-3.1-pro-preview to use the
new flag so cache and non-cache calculations behave consistently.
---
Nitpick comments:
In `@src/models.rs`:
- Around line 1008-1009: Add a table-driven unit test that calls get_model_info
for both "gemini-3.1-pro" and "gemini-3.1-pro-preview" and asserts they resolve
to the same canonical model and expected pricing; place it near other model
tests (e.g., in the tests module or tests/ directory). The test should iterate
over inputs ["gemini-3.1-pro", "gemini-3.1-pro-preview"], call
get_model_info(input), assert the returned ModelInfo.id (or equivalent canonical
identifier) equals "gemini-3.1-pro-preview" (or the current canonical id used in
the mapping) and assert the pricing fields match the current expected values to
catch future drift. Use descriptive test name and table rows so future updates
can update expected price in one place.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/models.rs`:
- Around line 1351-1364: The function signature for find_tier declares an
explicit lifetime ('a) that Clippy flags as needless; remove the explicit
lifetime parameter and let elision infer it by changing the signature to drop 'a
and use tiers: &[T] -> Option<&T> (keep the same parameters and the where clause
F: Fn(&T) -> Option<u64>), leaving the function body unchanged so references
compile with elided lifetimes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fd49b170-54d5-4d55-8f77-bd46173f4c31
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
Cargo.tomlsrc/models.rs
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/models.rs (1)
589-604:⚠️ Potential issue | 🔴 CriticalKeep
gemini-3-pro-preview-11-2025bracketed and cache-priced too.This entry still bills progressively and returns
$0cache cost, but Google's Gemini 3 Pro Preview pricing uses the same<=200k/>200kbracket rule for the whole request and includes non-zero context-caching rates. Since Lines 1044-1046 still routegemini-3-pro-previewandgemini-3-prohere, those aliases remain underbilled above 200k tokens and miss cache-read cost entirely. (ai.google.dev)🔧 Proposed fix
"gemini-3-pro-preview-11-2025" => ModelInfo { pricing: PricingStructure::Tiered(TieredPricing { tiers: &[ PricingTier { max_tokens: Some(200_000), input_per_1m: 2.0, output_per_1m: 12.0, }, PricingTier { max_tokens: None, input_per_1m: 4.0, output_per_1m: 18.0, }, ], - bracket_pricing: false, + bracket_pricing: true, }), - caching: CachingSupport::None, + caching: CachingSupport::Google(TieredCaching { + tiers: &[ + CachingTier { + max_tokens: Some(200_000), + cached_input_per_1m: 0.20, + }, + CachingTier { + max_tokens: None, + cached_input_per_1m: 0.40, + }, + ], + bracket_pricing: true, + }), is_estimated: false, },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/models.rs` around lines 589 - 604, The gemini-3-pro-preview-11-2025 model entry is missing bracket_pricing and non-zero caching rates: update the PricingStructure::Tiered(TieredPricing { ... }) for the gemini-3-pro-preview-11-2025 record so bracket_pricing is true (apply <=200k / >200k whole-request brackets) and set CachingSupport from None to the proper priced cache variant with non-zero cache read/write rates; modify the PricingTier values accordingly (use same tiers as gemini-3-pro/3-pro-preview but ensure caching fields are populated) so aliases gemini-3-pro-preview and gemini-3-pro routed here are billed correctly.
🧹 Nitpick comments (1)
src/models.rs (1)
1374-1391: Add one alias-level regression test.The new tests only exercise the canonical
"gemini-3.1-pro-preview"name. A small assertion for"gemini-3.1-pro"would cover the PR's alias change and catch a typo here before it silently falls back to the unknown-model$0path.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/models.rs` around lines 1374 - 1391, Add an alias-level regression test to cover the canonical alias as well as the preview name: add a test that calls calculate_input_cost("gemini-3.1-pro", 250_000) (and optionally calculate_cache_cost("gemini-3.1-pro", 0, 250_000)) and assert the same expected values as the existing gemini_3_1_pro_preview tests; this ensures the alias mapping used by calculate_input_cost and calculate_cache_cost is exercised and prevents silent fallback to the unknown-model path (refer to the existing test functions gemini_3_1_pro_preview_uses_bracket_pricing_for_input and gemini_3_1_pro_preview_uses_bracket_pricing_for_cache_reads for structure and expected assertions).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/models.rs`:
- Around line 589-604: The gemini-3-pro-preview-11-2025 model entry is missing
bracket_pricing and non-zero caching rates: update the
PricingStructure::Tiered(TieredPricing { ... }) for the
gemini-3-pro-preview-11-2025 record so bracket_pricing is true (apply <=200k /
>200k whole-request brackets) and set CachingSupport from None to the proper
priced cache variant with non-zero cache read/write rates; modify the
PricingTier values accordingly (use same tiers as gemini-3-pro/3-pro-preview but
ensure caching fields are populated) so aliases gemini-3-pro-preview and
gemini-3-pro routed here are billed correctly.
---
Nitpick comments:
In `@src/models.rs`:
- Around line 1374-1391: Add an alias-level regression test to cover the
canonical alias as well as the preview name: add a test that calls
calculate_input_cost("gemini-3.1-pro", 250_000) (and optionally
calculate_cache_cost("gemini-3.1-pro", 0, 250_000)) and assert the same expected
values as the existing gemini_3_1_pro_preview tests; this ensures the alias
mapping used by calculate_input_cost and calculate_cache_cost is exercised and
prevents silent fallback to the unknown-model path (refer to the existing test
functions gemini_3_1_pro_preview_uses_bracket_pricing_for_input and
gemini_3_1_pro_preview_uses_bracket_pricing_for_cache_reads for structure and
expected assertions).
Add pricing data and model aliases for Gemini 3.1 Pro Preview.
gemini-3.1-pro-preview,gemini-3.1-proSummary by CodeRabbit