Skip to content

feat(vertex): add support for overriding google auth #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/vertex-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ export type ClientOptions = Omit<API.ClientOptions, 'apiKey' | 'authToken'> & {
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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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();
}

Expand Down