Skip to content

fix: allow custom Gemini models instead of strict list check#94

Open
bluzername wants to merge 1 commit into1rgs:mainfrom
bluzername:fix/gemini-custom-model-validation
Open

fix: allow custom Gemini models instead of strict list check#94
bluzername wants to merge 1 commit into1rgs:mainfrom
bluzername:fix/gemini-custom-model-validation

Conversation

@bluzername
Copy link
Copy Markdown

Problem

When using a newer or custom Gemini model (like gemini-3.1-flash-lite-preview) by setting PREFERRED_PROVIDER="google" and defining SMALL_MODEL/BIG_MODEL in .env, the proxy fails with OpenAI 401 error because it doesnt recognize the model as Gemini.

I was trying to use gemini-3.1-flash-lite-preview which is newer model not in the hardcoded list and the proxy kept sending my requests to OpenAI with the dummy API key instead of Google.

Root Cause

The GEMINI_MODELS list in server.py only contains gemini-2.5-flash and gemini-2.5-pro. Any model not in this strict list falls through to the OpenAI path, even if the model name clearly starts with "gemini".

This happens in 6 places across two validators (MessagesRequest and TokenCountRequest):

  • Haiku mapping: SMALL_MODEL in GEMINI_MODELS
  • Sonnet mapping: BIG_MODEL in GEMINI_MODELS
  • Prefix addition: clean_v in GEMINI_MODELS

Fix

Added is_gemini_model() helper that checks both the known list AND startswith("gemini"):

def is_gemini_model(model_name: str) -> bool:
    return model_name in GEMINI_MODELS or model_name.startswith("gemini")

Replaced all 6 occurrences of in GEMINI_MODELS with is_gemini_model(). This way:

  • Known models still work exactly as before (no behavior change)
  • New/custom Gemini models like gemini-3.1-flash-lite-preview are correctly routed to Google instead of falling back to OpenAI
  • The GEMINI_MODELS list stays as a reference but is no longer the only gate

Python syntax verified.

Closes #87

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: Custom Gemini models fail with OpenAI 401 error due to strict GEMINI_MODELS list fallback

1 participant