Files
hermes-agent/agent
lepetitprince716-prog 6293fca019 fix(gemini): route Vertex AI express keys (AQ.) to aiplatform instead of 403ing on AI Studio
Google issues two Gemini key families: AI Studio keys (AIza...) and Vertex AI
express-mode keys (AQ....). Express keys only authenticate against
aiplatform.googleapis.com; the native adapter hardcoded the Studio host, so an
express key had no working path (403), and an explicit aiplatform base URL was
not even recognised as native Gemini and used the wrong model path.

- normalize_gemini_base_url(base_url, api_key="") routes an AQ. key that would
  land on generativelanguage to
  https://aiplatform.googleapis.com/v1beta1/publishers/google; an explicit proxy
  base is never rewritten. The express base carries the publishers/google
  prefix so every {base}/models/{model}:... builder (chat, tier probe, Gemini
  TTS) needs no path branching; an explicit aiplatform host root / v1beta1 base
  is completed to that form.
- is_native_gemini_base_url accepts the express host but NOT the OAuth Vertex
  provider's .../projects/{p}/locations/{r}/endpoints/openapi base, which is
  OpenAI-compatible and must stay off the native adapter.
- GeminiNativeClient, probe_gemini_tier and both Gemini TTS call sites pass the
  key through.

Cherry-picked from the reporter's earlier PR #96587 and reshaped onto current
main; #114343 and #101918 proposed the same routing.

Fixes #114335

Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
Co-authored-by: cloim <cloimism@gmail.com>
2026-09-18 09:28:39 -07:00
..
…
…
…