From f26823762219f78dce487165331312612c4399b9 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:24:00 -0400 Subject: [PATCH] feat(vertex): add support for overriding google auth (#338) --- packages/vertex-sdk/src/client.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/vertex-sdk/src/client.ts b/packages/vertex-sdk/src/client.ts index 5897175f..eb60436b 100644 --- a/packages/vertex-sdk/src/client.ts +++ b/packages/vertex-sdk/src/client.ts @@ -11,6 +11,17 @@ export type ClientOptions = Omit & { region?: string | null | undefined; projectId?: string | null | undefined; accessToken?: string | null | undefined; + + /** + * Override the default google auth config using the + * [google-auth-library](https://www.npmjs.com/package/google-auth-library) package. + * + * Note that you'll likely have to set `scopes`, e.g. + * ```ts + * new GoogleAuth({ scopes: 'https://www.googleapis.com/auth/cloud-platform' }) + * ``` + */ + googleAuth?: GoogleAuth | null | undefined; }; export class AnthropicVertex extends Core.APIClient { @@ -27,6 +38,7 @@ export class AnthropicVertex extends Core.APIClient { * * @param {string | null} opts.accessToken * @param {string | null} opts.projectId + * @param {GoogleAuth} opts.googleAuth - Override the default google auth config * @param {string | null} [opts.region=process.env['CLOUD_ML_REGION']] * @param {string} [opts.baseURL=process.env['ANTHROPIC_VERTEX__BASE_URL'] ?? https://${region}-aiplatform.googleapis.com/v1] - Override the default base URL for the API. * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. @@ -66,7 +78,8 @@ export class AnthropicVertex extends Core.APIClient { this.projectId = projectId; this.accessToken = options.accessToken ?? null; - this._auth = new GoogleAuth({ scopes: 'https://www.googleapis.com/auth/cloud-platform' }); + this._auth = + options.googleAuth ?? new GoogleAuth({ scopes: 'https://www.googleapis.com/auth/cloud-platform' }); this._authClientPromise = this._auth.getClient(); }