Skip to content

fix(gemini): honor custom model ids instead of falling back to default (#227)#317

Merged
edelauna merged 3 commits into
Zoo-Code-Org:mainfrom
proyectoauraorg:fix/227-gemini-custom-model
May 26, 2026
Merged

fix(gemini): honor custom model ids instead of falling back to default (#227)#317
edelauna merged 3 commits into
Zoo-Code-Org:mainfrom
proyectoauraorg:fix/227-gemini-custom-model

Conversation

@proyectoauraorg
Copy link
Copy Markdown
Contributor

@proyectoauraorg proyectoauraorg commented May 24, 2026

Closes #227

Problem

Selecting a custom Gemini model id that isn't in the hardcoded geminiModels map (e.g. gemini-3.5-flash) silently invokes gemini-3.1-pro-preview instead. The settings ModelPicker exposes a "use custom model" option and useSelectedModel keeps the configured id, but GeminiHandler.getModel() discarded any unknown id and fell back to geminiDefaultModelId — so the UI and the actual request disagreed.

Fix

getModel() now honors a custom id when it looks like a Gemini model (gemini- prefix, case-insensitive), using the default model's structural info as a baseline. Pricing fields (inputPrice/outputPrice/cache/tiers) are dropped for unknown models so cost reporting shows "unknown" rather than charging the default model's rates. Ids that don't look like Gemini models (e.g. invalid-model) still fall back to the default, preserving existing behavior.

Tests

Added a getModel case asserting a custom gemini-3.5-flash id is honored (not swapped) and that pricing is left undefined. The existing invalid-model → default test is unchanged. tsc, eslint, prettier, and the gemini suite (20 tests) pass locally.

Summary by CodeRabbit

  • New Features
    • Support for custom Gemini model IDs: configure Gemini identifiers not in the predefined list; these models operate normally but pricing/usage costs are reported as unknown.
  • Tests
    • Added unit tests ensuring custom Gemini IDs preserve configured IDs and leave pricing fields unset, and that inherited/reserved identifier names fall back to defaults while returning model info.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f5677784-5e82-4a26-9e54-f3eea4409bf7

📥 Commits

Reviewing files that changed from the base of the PR and between 7669c0f and eaf7417.

📒 Files selected for processing (2)
  • src/api/providers/__tests__/gemini.spec.ts
  • src/api/providers/gemini.ts

📝 Walkthrough

Walkthrough

GeminiHandler.getModel() now branches: use known geminiModels entry, accept unlisted ids starting with "gemini-" by preserving the id and clearing pricing/tier fields, or fall back to geminiDefaultModelId. Two unit tests cover a custom id and a prototype-key id.

Changes

Custom Gemini Model ID Handling

Layer / File(s) Summary
Model resolution branching and pricing clearing
src/api/providers/gemini.ts
Implements three-way branching in getModel() to use known geminiModels, accept unlisted gemini-* ids by copying default model structure while clearing pricing/tier fields, or fall back to geminiDefaultModelId.
Unit tests for custom and prototype-key cases
src/api/providers/__tests__/gemini.spec.ts
Adds tests verifying that an unknown custom apiModelId is returned as-configured with modelInfo.info present but pricing fields undefined, and that "toString" (an Object prototype key) is not treated as a known model and triggers fallback to the default.
sequenceDiagram
  participant Client as GeminiHandler
  participant Registry as geminiModels
  participant Default as geminiDefaultModelId
  Client->>Registry: lookup(apiModelId)
  alt registry has model
    Registry-->>Client: modelInfo (used)
  else apiModelId starts with "gemini-"
    Client->>Default: copy structure (clear pricing/tiers)
    Default-->>Client: modelInfo (pricing cleared / undefined)
  else fallback
    Default-->>Client: default modelInfo
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniff a new gemini id in the wood,
Not listed, not priced, but looking good.
The handler keeps your name intact and clear,
Yet hides the costs so math won't leer.
Hooray for wild models—welcome here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: honoring custom Gemini model IDs instead of falling back to default, which matches the core fix in the changeset.
Description check ✅ Passed The description includes the linked issue (#227), a clear problem statement, the implemented fix with implementation details, and test coverage information. However, the 'Test Procedure' section describing how reviewers can reproduce/verify the tests is missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/api/providers/__tests__/gemini.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api/providers/gemini.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/api/providers/__tests__/gemini.spec.ts (1)

190-193: ⚡ Quick win

Also assert cache pricing fields are undefined for custom models.

This test already validates unknown core pricing. Add cacheReadsPrice and cacheWritesPrice assertions too, since the implementation explicitly clears both.

Suggested patch
 			expect(modelInfo.info.inputPrice).toBeUndefined()
 			expect(modelInfo.info.outputPrice).toBeUndefined()
+			expect(modelInfo.info.cacheReadsPrice).toBeUndefined()
+			expect(modelInfo.info.cacheWritesPrice).toBeUndefined()
 			expect(modelInfo.info.tiers).toBeUndefined()
🤖 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 `@src/api/providers/__tests__/gemini.spec.ts` around lines 190 - 193, The test
in gemini.spec.ts that asserts unknown core pricing currently checks inputPrice,
outputPrice, and tiers but misses the cache pricing fields; update the same test
block (where modelInfo.info is asserted) to also assert that
modelInfo.info.cacheReadsPrice and modelInfo.info.cacheWritesPrice are undefined
by adding expectations for both properties alongside the existing
input/output/tiers assertions.
🤖 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 `@src/api/providers/gemini.ts`:
- Around line 496-499: The current check uses `modelId && modelId in
geminiModels`, which can match prototype properties and lead to invalid `info`
lookup; update the conditional to use an own-property check (e.g.
`Object.hasOwn(geminiModels, modelId)` or
`Object.prototype.hasOwnProperty.call(geminiModels, modelId)`) so that when
setting `id = modelId` and `info = geminiModels[modelId as GeminiModelId]` you
only match real keys on the `geminiModels` map and avoid prototype-key
collisions.

---

Nitpick comments:
In `@src/api/providers/__tests__/gemini.spec.ts`:
- Around line 190-193: The test in gemini.spec.ts that asserts unknown core
pricing currently checks inputPrice, outputPrice, and tiers but misses the cache
pricing fields; update the same test block (where modelInfo.info is asserted) to
also assert that modelInfo.info.cacheReadsPrice and
modelInfo.info.cacheWritesPrice are undefined by adding expectations for both
properties alongside the existing input/output/tiers assertions.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7dbdc206-4e39-4ec7-9cd0-3963e97b5cca

📥 Commits

Reviewing files that changed from the base of the PR and between 9d022d4 and 9d7cff3.

📒 Files selected for processing (2)
  • src/api/providers/__tests__/gemini.spec.ts
  • src/api/providers/gemini.ts

Comment thread src/api/providers/gemini.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Zoo-Code-Org#227)

Selecting a custom Gemini model id not present in geminiModels (e.g.
gemini-3.5-flash) silently invoked geminiDefaultModelId. The settings
ModelPicker exposes a 'use custom model' option and useSelectedModel keeps
the configured id, so the UI and the actual request disagreed.

getModel() now honors a custom id when it looks like a Gemini model
(gemini- prefix), using the default model's structural info as a baseline
with pricing/tiers dropped so cost shows as unknown rather than the default
model's rates. Ids that don't look like Gemini still fall back to default.
…#227)

modelId in geminiModels also matches inherited Object.prototype keys
(e.g. "toString"), resolving info to a function. Use Object.hasOwn so only
real model keys match; prototype-key ids fall through to the default.
@proyectoauraorg proyectoauraorg force-pushed the fix/227-gemini-custom-model branch from 7669c0f to eaf7417 Compare May 26, 2026 05:59
Copy link
Copy Markdown
Contributor

@edelauna edelauna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks,

there are other providers with the same problem. I wonder if this is worth doing for others?

@edelauna edelauna added this pull request to the merge queue May 26, 2026
Merged via the queue into Zoo-Code-Org:main with commit cef0cc3 May 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini service providers cannot invoke the custom gemini-3.5-flash model.

2 participants