@@ -11,6 +11,7 @@ import { BaseProvider } from "./base-provider"
1111
1212import { ANTHROPIC_DEFAULT_MAX_TOKENS } from "./constants"
1313import { getModelParams , SingleCompletionHandler } from "../"
14+ import { GoogleAuth } from "google-auth-library"
1415
1516// Types for Vertex SDK
1617
@@ -120,16 +121,56 @@ export class VertexHandler extends BaseProvider implements SingleCompletionHandl
120121 throw new Error ( `Unknown model ID: ${ this . options . apiModelId } ` )
121122 }
122123
123- this . anthropicClient = new AnthropicVertex ( {
124- projectId : this . options . vertexProjectId ?? "not-provided" ,
125- // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
126- region : this . options . vertexRegion ?? "us-east5" ,
127- } )
124+ if ( this . options . vertexJsonCredentials ) {
125+ this . anthropicClient = new AnthropicVertex ( {
126+ projectId : this . options . vertexProjectId ?? "not-provided" ,
127+ // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
128+ region : this . options . vertexRegion ?? "us-east5" ,
129+ googleAuth : new GoogleAuth ( {
130+ scopes : [ "https://www.googleapis.com/auth/cloud-platform" ] ,
131+ credentials : JSON . parse ( this . options . vertexJsonCredentials ) ,
132+ } ) ,
133+ } )
134+ } else if ( this . options . vertexKeyFile ) {
135+ this . anthropicClient = new AnthropicVertex ( {
136+ projectId : this . options . vertexProjectId ?? "not-provided" ,
137+ // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
138+ region : this . options . vertexRegion ?? "us-east5" ,
139+ googleAuth : new GoogleAuth ( {
140+ scopes : [ "https://www.googleapis.com/auth/cloud-platform" ] ,
141+ keyFile : this . options . vertexKeyFile ,
142+ } ) ,
143+ } )
144+ } else {
145+ this . anthropicClient = new AnthropicVertex ( {
146+ projectId : this . options . vertexProjectId ?? "not-provided" ,
147+ // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions
148+ region : this . options . vertexRegion ?? "us-east5" ,
149+ } )
150+ }
128151
129- this . geminiClient = new VertexAI ( {
130- project : this . options . vertexProjectId ?? "not-provided" ,
131- location : this . options . vertexRegion ?? "us-east5" ,
132- } )
152+ if ( this . options . vertexJsonCredentials ) {
153+ this . geminiClient = new VertexAI ( {
154+ project : this . options . vertexProjectId ?? "not-provided" ,
155+ location : this . options . vertexRegion ?? "us-east5" ,
156+ googleAuthOptions : {
157+ credentials : JSON . parse ( this . options . vertexJsonCredentials ) ,
158+ } ,
159+ } )
160+ } else if ( this . options . vertexKeyFile ) {
161+ this . geminiClient = new VertexAI ( {
162+ project : this . options . vertexProjectId ?? "not-provided" ,
163+ location : this . options . vertexRegion ?? "us-east5" ,
164+ googleAuthOptions : {
165+ keyFile : this . options . vertexKeyFile ,
166+ } ,
167+ } )
168+ } else {
169+ this . geminiClient = new VertexAI ( {
170+ project : this . options . vertexProjectId ?? "not-provided" ,
171+ location : this . options . vertexRegion ?? "us-east5" ,
172+ } )
173+ }
133174 }
134175
135176 private formatMessageForCache ( message : Anthropic . Messages . MessageParam , shouldCache : boolean ) : VertexMessage {
0 commit comments