feat(gemini): add Gemini model support via GEMINI_API_KEY
Summary
- Adds
gemini/<model>routing in_resolve_llm_paramsβ LiteLLM picks upGEMINI_API_KEYautomatically; thinking-capable models (e.g.gemini-2.5-pro,gemini-2.5-flash) receivethinking_config.thinking_budgetmapped from effort levels (low=1024, medium=8192, high=24576). - Registers
gemini/gemini-2.5-proandgemini/gemini-2.5-flashin the model switcher suggested list and the backendAVAILABLE_MODELSlist. - Exposes Gemini 2.5 Pro in the frontend chat model picker.
- Documents
GEMINI_API_KEYinREADME.md. - Adds unit tests covering effortβbudget mapping, edge cases (minimalβlow normalisation, strict/non-strict invalid effort), and regression guards for Anthropic / OpenAI / HF router paths.
Test plan
- [ ]
uv run pytest tests/unit/test_llm_params_gemini.py -vpasses - [ ] Set
GEMINI_API_KEYand runuv run python tests/unit/test_llm_params_gemini.py --livefor a live smoke-test - [ ] Open the frontend model picker β "Gemini 2.5 Pro" appears in the list
- [ ] Switch to
gemini/gemini-2.5-proin/modelβ no routing-info error
π€ Generated with Claude Code
@claude please review this PR. Focus on correctness, security, LiteLLM/Bedrock routing impact, and whether it's safe to merge against current main. Keep it concise and prefer inline comments where it matters.
Claude finished @akseljoonas's task in 1m 50s ββ View job
PR Review: feat(gemini): add Gemini model support via GEMINI_API_KEY
- [x] Read changed files
- [x] Review correctness
- [x] Review security / access control
- [x] Review LiteLLM/Bedrock routing impact
- [x] Assess merge safety
- [x] Post findings
Summary
The routing logic is correct and non-breaking. The Bedrock/Anthropic/OpenAI paths are untouched. However, there are two issues worth addressing before merging β one is a meaningful security/cost gap, and one is a minor inconsistency.
Issues
π΄ Missing quota gate for Gemini 2.5 Pro
backend/routes/agent.py lines 56β62
{
"id": "gemini/gemini-2.5-pro",
"provider": "gemini",
"tier": "free", # β no quota / no org-membership gate
},
Gemini 2.5 Pro is comparable in cost to Claude Opus, but it has:
- No
_require_hf_for_geminiequivalent - No daily-quota check (
_enforce_claude_quotaonly fires on"anthropic" in model_id)
If GEMINI_API_KEY is set server-side in the Space, every authenticated user gets unlimited Gemini 2.5 Pro β billed to the Space owner with no cap. The Anthropic path has both an org-membership gate and a per-user daily cap; Gemini needs at least one of those.
If the intended deployment never sets GEMINI_API_KEY in the Space env, this is moot and the model is effectively dead on arrival. But the model listing in the frontend picker will still appear clickable and fail silently, which is confusing.
Either add an access guard (HF org membership check, at minimum), or explicitly document the intent ("Gemini only works when the operator sets GEMINI_API_KEY in their own deployment β not enabled on the public Space") and hide it from the frontend picker when the key isn't present. Fix this β
π‘ gemini-2.5-flash is in CLI suggested list but not in AVAILABLE_MODELS
agent/core/model_switcher.py line 30 vs backend/routes/agent.py
# model_switcher.py β CLI suggested list
{"id": "gemini/gemini-2.5-flash", "label": "Gemini 2.5 Flash"},
# agent.py β backend AVAILABLE_MODELS β Flash is absent
CLI users who pick gemini/gemini-2.5-flash from /model can use it fine (the CLI doesn't gate against AVAILABLE_MODELS). But any web-frontend call to POST /api/session/{id}/model with Flash will return 400 Unknown model. Flash is also absent from the frontend model picker.
Either add Flash to AVAILABLE_MODELS (and apply the same quota/access considerations as Pro), or drop it from SUGGESTED_MODELS for now. Fix this β
Minor Notes
frontend/src/components/Chat/ChatInput.tsx line 49
avatarUrl: 'https://www.gstatic.com/lamda/images/gemini_favicon_f069958c85030456e93de685481c559f160ea06.svg',
Hardcoded external asset from gstatic.com β hash in the filename is stable now, but if Google ever rotates it, the avatar silently breaks. Low risk, but worth noting if bundled SVGs are used elsewhere.
agent/core/llm_params.py line 81β82
# LiteLLM maps reasoning_effort β thinking_config.thinkingBudget natively for Gemini;
# we keep this dict for unit-test assertions and documentation only.
_GEMINI_THINKING_BUDGETS = {"low": 1024, "medium": 8192, "high": 24576}
The dict isn't used in any live code path, only imported in tests to assert ordering. That's fine as documentation, but the test_thinking_budgets_are_ordered test only checks relative ordering β it won't catch if LiteLLM's actual budget values differ. Not blocking.
Routing Safety β
The routing order in _resolve_llm_params is correct β gemini/ is checked explicitly before the HF fallback, so Gemini IDs will never accidentally route to the HF router. Bedrock, Anthropic, and OpenAI paths are unaffected; the new block is a clean insertion with no side effects on existing logic. Unit tests cover the other-provider regression cases.
Verdict: The core implementation is correct. The cost/access-control gap on Gemini (no quota gate) is the main blocker β address it or document the deployment intent clearly before merging.