Skip to content

fix(gemini): route Google AI Studio auth via x-goog-api-key header (#7893)#11961

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-e28b38e3
Apr 18, 2026
Merged

fix(gemini): route Google AI Studio auth via x-goog-api-key header (#7893)#11961
teknium1 merged 2 commits into
mainfrom
hermes/hermes-e28b38e3

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Gemini AI Studio requests now succeed on both legacy AIza… and new AQ.-prefixed API keys. Google's OpenAI-compat endpoint rejects Authorization: Bearer with HTTP 400 Multiple authentication credentials received for AQ. keys (confirmed by Google AI Dev Forum thread and 8+ user reports on #7893).

Salvaged from @AviArora02-commits' PR #8530 onto current main. Original authorship preserved via cherry-pick. Also supersedes #8128, #9247, #8172 which addressed the same bug with narrower coverage or incorrect logic.

Changes

  • run_agent.py: primary client init + _apply_client_headers_for_base_url (mid-session switch)
  • agent/auxiliary_client.py: _resolve_api_key_provider (pool + non-pool) + resolve_provider_client
  • 5 client-construction sites total, all swap api_key=real_keyapi_key="not-used" + default_headers={x-goog-api-key: real_key} when base_url targets generativelanguage.googleapis.com
  • 2 new regression tests in tests/hermes_cli/test_gemini_provider.py

Validation

Check Result
tests/hermes_cli/test_gemini_provider.py (43 tests) pass
tests/agent/test_auxiliary_client.py (58 tests) pass
E2E — all 5 sites with real imports (AIza key) Bearer suppressed, x-goog-api-key set
E2E — site 1 with AQ.-prefix key Bearer suppressed, x-goog-api-key set
E2E — mid-session switch path api_key="not-used", x-goog-api-key populated

Conflict resolution: PR #8530's test updates targeted tests that #11472 deleted; dropped those re-introductions and kept the new regression coverage in test_gemini_provider.py.

Closes #7893
Supersedes #8128, #9247, #8172, #8530

@teknium1 teknium1 merged commit c20e236 into main Apr 18, 2026
4 of 7 checks passed
@teknium1 teknium1 deleted the hermes/hermes-e28b38e3 branch April 18, 2026 04:30
@prasadus92 prasadus92 mentioned this pull request Apr 18, 2026
19 tasks
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]: HTTP 400 "Multiple authentication credentials received" when using native gemini provider

2 participants