@ai-sdk/google-vertex
Version:
The **[Google Vertex provider](https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs.
50 lines (43 loc) • 1.48 kB
text/typescript
import { loadOptionalSetting, resolve } from '@ai-sdk/provider-utils';
import { GoogleAuthOptions } from 'google-auth-library';
import { generateAuthToken } from './google-vertex-auth-google-auth-library';
import {
createVertex as createVertexOriginal,
GoogleVertexProvider,
GoogleVertexProviderSettings as GoogleVertexProviderSettingsOriginal,
} from './google-vertex-provider';
export interface GoogleVertexProviderSettings
extends GoogleVertexProviderSettingsOriginal {
/**
* Optional. The Authentication options provided by google-auth-library.
* Complete list of authentication options is documented in the
* GoogleAuthOptions interface:
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
*/
googleAuthOptions?: GoogleAuthOptions;
}
export type { GoogleVertexProvider };
export function createVertex(
options: GoogleVertexProviderSettings = {},
): GoogleVertexProvider {
const apiKey = loadOptionalSetting({
settingValue: options.apiKey,
environmentVariableName: 'GOOGLE_VERTEX_API_KEY',
});
if (apiKey) {
return createVertexOriginal(options);
}
return createVertexOriginal({
...options,
headers: async () => ({
Authorization: `Bearer ${await generateAuthToken(
options.googleAuthOptions,
)}`,
...(await resolve(options.headers)),
}),
});
}
/**
Default Google Vertex AI provider instance.
*/
export const vertex = createVertex();