Skip to content

fix: accept x-goog-api-key header for bot token in proxy#20

Open
mleungdev wants to merge 3 commits into
jgarzik:mainfrom
mleungdev:fix/proxy-google-auth
Open

fix: accept x-goog-api-key header for bot token in proxy#20
mleungdev wants to merge 3 commits into
jgarzik:mainfrom
mleungdev:fix/proxy-google-auth

Conversation

@mleungdev
Copy link
Copy Markdown

@mleungdev mleungdev commented Feb 14, 2026

Summary

Two bugs in the keyring proxy that break Google/Gemini support:

  1. Missing x-goog-api-key auth — The Google GenAI SDK (@google/genai) sends API keys via the x-goog-api-key header. The proxy only checked Authorization: Bearer (OpenAI) and x-api-key (Anthropic), returning 401 for all Google requests.

  2. Query parameters dropped — Fastify strips query params from wildcard route params (req.params['*']), so ?alt=sse was silently lost. Google then returns JSON instead of SSE, causing the SDK's stream parser to fail with "Incomplete JSON segment at the end".

Both bugs are in proxy/src/routes/proxy.ts. The proxy already defines Google vendor support in types.ts (including authHeader: 'x-goog-api-key'), so these are oversights in the request handling path.

Test plan

  • Verified: proxy returns 200 for Google requests with x-goog-api-key auth (was 401)
  • Verified: ?alt=sse is preserved, upstream returns text/event-stream (was application/json)
  • Verified: end-to-end bot response works — bot replies correctly in Discord via Gemini
  • Verified: Authorization: Bearer and x-api-key auth still work unchanged
  • CI tests pass

🤖 Generated with Claude Code

ghostfacesama and others added 3 commits February 14, 2026 13:41
The Google GenAI SDK (@google/genai) sends API keys via the
x-goog-api-key header. The proxy already supports this header on the
outgoing side (VENDOR_CONFIGS.google.authHeader), but the incoming bot
token extraction only checked Authorization: Bearer and x-api-key.

This causes all Google/Gemini requests through the proxy to fail with
401 "Missing authorization" since the bot's proxy token is sent via
x-goog-api-key but never extracted.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fastify strips query parameters from wildcard route params, so
?alt=sse (required by Google's streaming API) was silently dropped.
This caused Google to return JSON instead of SSE, which the GenAI
SDK's stream parser couldn't handle ("Incomplete JSON segment").

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests cover:
- Bot token extraction from all three auth headers (Bearer, x-api-key, x-goog-api-key)
- 401/403 for missing/invalid tokens
- Query parameter preservation (?alt=sse, multiple params, no params)
- Vendor validation (unknown vendor, missing API keys)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants