Skip to content

fix(doctor): use x-goog-api-key for Google generativelanguage endpoint#26961

Closed
zwolniony wants to merge 1 commit into
NousResearch:mainfrom
zwolniony:doctor-google-api-key-auth
Closed

fix(doctor): use x-goog-api-key for Google generativelanguage endpoint#26961
zwolniony wants to merge 1 commit into
NousResearch:mainfrom
zwolniony:doctor-google-api-key-auth

Conversation

@zwolniony

Copy link
Copy Markdown
Contributor

Summary

hermes doctor reports a valid GOOGLE_API_KEY / GEMINI_API_KEY as "invalid API key" with the hint "Check GOOGLE_API_KEY in .env", even when the key works perfectly at runtime. The generic API-key probe sends Authorization: Bearer <key>, but Google's Generative Language API doesn't accept that header for plain API keys — it's reserved for OAuth 2 access tokens. The runtime path uses the correct auth scheme, so only the doctor check is affected.

Reproduction

  1. Set a valid GOOGLE_API_KEY (e.g. from https://aistudio.google.com/app/apikey) on a project where the Gemini API is enabled.
  2. Confirm runtime works: any Hermes call against Gemini succeeds.
  3. Run hermes doctor.

Expected: ✓ Google / Gemini
Actual: ✗ Google / Gemini (invalid API key) → "Check GOOGLE_API_KEY in .env"

Root cause

In hermes_cli/doctor.py, _probe_apikey_provider sends:

headers = {
    "Authorization": f"Bearer {key}",
    ...
}

Google's response:

HTTP 401
"Request had invalid authentication credentials. Expected OAuth 2 access
token, login cookie or other valid authentication credential."
reason: ACCESS_TOKEN_TYPE_UNSUPPORTED
service: generativelanguage.googleapis.com

Plain API keys for generativelanguage.googleapis.com must be sent via ?key=<key> or the x-goog-api-key header. The Authorization: Bearer header is reserved for OAuth 2 access tokens, and Google explicitly rejects API keys sent that way.

Fix

Mirror the existing api.kimi.com special-case directly above: after computing url, detect when the host is generativelanguage.googleapis.com and swap Authorization: Bearer for x-goog-api-key. base_url_host_matches is already imported and used a few lines up.

Matches against the final url (not just base), so it works for both *_BASE_URL-overridden setups and the default URL from the Gemini provider profile.

Test plan

  • Locally: hermes doctor with a working GOOGLE_API_KEY now reports ✓ Google / Gemini.
  • Verified the live Authorization: Bearer <key> request returns 401 ACCESS_TOKEN_TYPE_UNSUPPORTED, while the same key with x-goog-api-key returns 200 + model list.
  • CI green.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard provider/gemini Google Gemini (AI Studio, Cloud Code) duplicate This issue or pull request already exists labels May 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #20642 — this is the 9th+ PR implementing the same Gemini doctor x-goog-api-key fix. The canonical fix is bundled in #20642. See also: #22489, #22286, #22468, #24033, #24266, #21490, #26922 (all duplicates of #20642).

teknium1 added a commit that referenced this pull request May 17, 2026
…tors

Adds release-note attribution mappings for 9 contributors from group 4:
- @EloquentBrush0x (PR #26657)
- @subtract0 (PR #25658)
- @zwolniony (PR #26961)
- @that-ambuj (PR #26582)
- @zccyman (PR #25294)
- @lidge-jun (PR #26814)
- @phoenixshen (PR #26768)
- @AhmetArif0 (PR #26635)
- (francip already mapped from prior PR #26134 attribution)

#27147 dropped from this batch — already landed on main as 4b17c24.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #27308 — your commit was cherry-picked onto current main as part of a batch salvage of low-risk new-contributor PRs. Authorship preserved (fix(doctor): use x-goog-api-key for Google generativelanguage endpoint). Thanks for the contribution.

@teknium1 teknium1 closed this May 17, 2026
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…tors

Adds release-note attribution mappings for 9 contributors from group 4:
- @EloquentBrush0x (PR NousResearch#26657)
- @subtract0 (PR NousResearch#25658)
- @zwolniony (PR NousResearch#26961)
- @that-ambuj (PR NousResearch#26582)
- @zccyman (PR NousResearch#25294)
- @lidge-jun (PR NousResearch#26814)
- @phoenixshen (PR NousResearch#26768)
- @AhmetArif0 (PR NousResearch#26635)
- (francip already mapped from prior PR NousResearch#26134 attribution)

NousResearch#27147 dropped from this batch — already landed on main as 4b17c24.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/gemini Google Gemini (AI Studio, Cloud Code) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants