fix: accept x-goog-api-key header for bot token in proxy#20
Open
mleungdev wants to merge 3 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs in the keyring proxy that break Google/Gemini support:
Missing
x-goog-api-keyauth — The Google GenAI SDK (@google/genai) sends API keys via thex-goog-api-keyheader. The proxy only checkedAuthorization: Bearer(OpenAI) andx-api-key(Anthropic), returning 401 for all Google requests.Query parameters dropped — Fastify strips query params from wildcard route params (
req.params['*']), so?alt=ssewas 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 intypes.ts(includingauthHeader: 'x-goog-api-key'), so these are oversights in the request handling path.Test plan
x-goog-api-keyauth (was 401)?alt=sseis preserved, upstream returnstext/event-stream(wasapplication/json)Authorization: Bearerandx-api-keyauth still work unchanged🤖 Generated with Claude Code