11import { GoogleGenAI } from '@google/genai'
2+ import { OAuth2Client } from 'google-auth-library'
23import { env } from '@/lib/core/config/env'
34import { createLogger } from '@/lib/logs/console/logger'
45import type { StreamingExecution } from '@/executor/types'
@@ -15,9 +16,8 @@ const logger = createLogger('VertexProvider')
1516 * Shares core execution logic with Google Gemini provider.
1617 *
1718 * Authentication:
18- * - Uses OAuth access token (from `gcloud auth print-access-token` or service account)
19- * - Token refresh should be handled at the OAuth layer before calling this provider
20- * - Access token is passed via HTTP Authorization header
19+ * - Uses OAuth access token passed via googleAuthOptions.authClient
20+ * - Token refresh is handled at the OAuth layer before calling this provider
2121 */
2222export const vertexProvider : ProviderConfig = {
2323 id : 'vertex' ,
@@ -54,20 +54,21 @@ export const vertexProvider: ProviderConfig = {
5454 model,
5555 } )
5656
57+ // Create an OAuth2Client and set the access token
58+ // This allows us to use an OAuth access token with the SDK
59+ const authClient = new OAuth2Client ( )
60+ authClient . setCredentials ( { access_token : request . apiKey } )
61+
5762 // Create client with Vertex AI configuration
58- // Pass access token via HTTP Authorization header
5963 const ai = new GoogleGenAI ( {
6064 vertexai : true ,
6165 project : vertexProject ,
6266 location : vertexLocation ,
63- httpOptions : {
64- headers : {
65- Authorization : `Bearer ${ request . apiKey } ` ,
66- } ,
67+ googleAuthOptions : {
68+ authClient,
6769 } ,
6870 } )
6971
70- // Use shared execution logic
7172 return executeGeminiRequest ( {
7273 ai,
7374 model,
0 commit comments