UNPKG

@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.

28 lines (23 loc) 772 B
import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library'; let authInstance: GoogleAuth | null = null; let authOptions: GoogleAuthOptions | null = null; function getAuth(options: GoogleAuthOptions) { if (!authInstance || options !== authOptions) { authInstance = new GoogleAuth({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], ...options, }); authOptions = options; } return authInstance; } export async function generateAuthToken(options?: GoogleAuthOptions) { const auth = getAuth(options || {}); const client = await auth.getClient(); const token = await client.getAccessToken(); return token?.token || null; } // For testing purposes only export function _resetAuthInstance() { authInstance = null; }