Conversation
When native Gemini model listing fails on a custom API base, query the configured relay's OpenAI-compatible models endpoint. Official Gemini bases retain the original failure path.
Contributor
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the relay URL or response parsing is wrong, model discovery can return an unusable or incomplete list and prevent users from selecting valid Gemini models; reverting removes that behavior, though any requests made with an incorrect bearer header cannot be undone. The change also adds credential-bearing requests to the configured custom relay endpoint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
$Fixes #9766\n\n## Motivation\n\nSome Gemini relays expose an OpenAI-compatible model-list endpoint but do not implement the native Google
models.listroute. As a result, users cannot retrieve models even though chat requests through the relay work.\n\n## Changes\n\n- After a native model-listAPIError, custom Gemini API bases now fall back to their OpenAI-compatible/modelsendpoint.\n- The fallback sends the configured key as a Bearer token unless the provider already has an Authorization header.\n- The fallback uses the existing HTTP client, including its timeout and proxy settings.\n- Official Google Gemini API bases keep the original native-only failure path to avoid an unnecessary compatibility request.\n- If both requests fail, the error names the native and relay failures to make configuration problems easier to diagnose.\n\n## Testing\n\n- Added regression tests for custom relay fallback, URL normalization, authentication headers, and preserving native-only behavior on the official API base.\n- Ranuv run pytest tests/test_gemini_source.py -q(20 passed).\n- Ran Ruff format and check on the changed files.Summary by Sourcery
Enable reliable model discovery through compatible Gemini relays while preserving native behavior for the official Google API.
Bug Fixes:
Enhancements:
Tests: