anthropics / anthropic-sdk-typescript

Access to Anthropic's safety-first language model APIs
https://www.npmjs.com/package/@anthropic-ai/sdk
MIT License
509 stars 49 forks source link

[Vertex AI] The constructor does not expose a way to pass custom google credentials #330

Closed lbguilherme closed 3 months ago

lbguilherme commented 3 months ago

Doing new AnthropicVertex() will use the default google credentials. But sometimes this is not what we want to do. Currently we had to use this hack to get it working:

const anthropic = new AnthropicVertex({
  region: '...',
  projectId: '...',
});

anthropic._auth = new GoogleAuth({
  scopes: 'https://www.googleapis.com/auth/cloud-platform',
  credentials: JSON.parse(process.env.GOOGLE_CREDENTIALS!),
});
anthropic._authClientPromise = anthropic._auth.getClient();

It would be better if an optional credentials option could be passed into the AnthropicVertex constructor.

rattrayalex commented 3 months ago

Thank you for filing, I agree that sounds like a good idea! We'll look into it more soon.

RobertCraigie commented 3 months ago

What do you think about supporting an authConfig?: GoogleAuth option instead? This way we wouldn't have to add support for each config option individually

const anthropic = new AnthropicVertex({
  region: '...',
  projectId: '...',
  authConfig: new GoogleAuth({
      scopes: 'https://www.googleapis.com/auth/cloud-platform',
      credentials: JSON.parse(process.env.GOOGLE_CREDENTIALS!),
    })
});
RobertCraigie commented 3 months ago

A googleAuth client option will be included in the next release!