Problem
When using Google Vertex AI models through the gateway, OAuth2 access tokens (starting with ya29.) are being sent as query parameters (?key=ya29...) instead of in the Authorization: Bearer header. Vertex AI requires OAuth tokens in the Authorization header and returns a 401 error when tokens are sent as query parameters.
Error
401 Unauthorized: API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal.
Expected Behavior
OAuth tokens should be sent in the Authorization: Bearer header, not as query parameters.
Current Code Issues
-
packages/models/src/get-provider-endpoint.ts (line ~87):
- Base URL is hardcoded to
https://aiplatform.googleapis.com instead of region-specific
- OAuth tokens are added to query params (line ~237)
-
packages/models/src/get-provider-headers.ts (line ~18):
google-vertex case returns empty headers {}
- Should return
Authorization: Bearer header for OAuth tokens
Environment
- Project ID: ``
- Region:
us-central1
- Token format:
ya29.c.c0AYnqX... (OAuth2 access token)
Workaround
Currently calling Vertex AI directly bypassing the gateway, but would prefer to use the gateway for consistency.
Suggested Fix
- Detect OAuth tokens (starting with
ya29. or 1//)
- Send OAuth tokens in
Authorization: Bearer header
- Use region-specific base URL:
https://${region}-aiplatform.googleapis.com
- Only send API keys (not OAuth tokens) as query parameters
Problem
When using Google Vertex AI models through the gateway, OAuth2 access tokens (starting with
ya29.) are being sent as query parameters (?key=ya29...) instead of in theAuthorization: Bearerheader. Vertex AI requires OAuth tokens in the Authorization header and returns a 401 error when tokens are sent as query parameters.Error
401 Unauthorized: API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal.
Expected Behavior
OAuth tokens should be sent in the
Authorization: Bearerheader, not as query parameters.Current Code Issues
packages/models/src/get-provider-endpoint.ts(line ~87):https://aiplatform.googleapis.cominstead of region-specificpackages/models/src/get-provider-headers.ts(line ~18):google-vertexcase returns empty headers{}Authorization: Bearerheader for OAuth tokensEnvironment
us-central1ya29.c.c0AYnqX...(OAuth2 access token)Workaround
Currently calling Vertex AI directly bypassing the gateway, but would prefer to use the gateway for consistency.
Suggested Fix
ya29.or1//)Authorization: Bearerheaderhttps://${region}-aiplatform.googleapis.com