Skip to content

fix: use relay model list for Gemini proxies - #10168

Open
iuiu-py wants to merge 1 commit into
AstrBotDevs:masterfrom
iuiu-py:fix/9766-gemini-relay-models
Open

iuiu-py wants to merge 1 commit into
AstrBotDevs:masterfrom
iuiu-py:fix/9766-gemini-relay-models

Conversation

@iuiu-py

@iuiu-py iuiu-py commented Sep 21, 2026

Copy link
Copy Markdown

$Fixes #9766\n\n## Motivation\n\nSome Gemini relays expose an OpenAI-compatible model-list endpoint but do not implement the native Google models.list route. As a result, users cannot retrieve models even though chat requests through the relay work.\n\n## Changes\n\n- After a native model-list APIError, custom Gemini API bases now fall back to their OpenAI-compatible /models endpoint.\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- Ran uv 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:

  • Allow custom Gemini API bases to retrieve models through an OpenAI-compatible relay endpoint when native model listing fails.

Enhancements:

  • Preserve native-only behavior for the official Google Gemini API and improve errors by reporting both native and relay failures.
  • Support relay URL normalization, configured authentication headers, and existing HTTP client settings.

Tests:

  • Add regression coverage for relay fallback, URL variants, authentication behavior, and official API handling.

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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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.

[Bug] Gemini使用中转站的情况下,无法获取模型

1 participant