Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

createGoogleGenerativeAI

Creates a customized Google Generative AI provider for the Vercel AI SDK. Use the returned provider to create Google language or embedding models with provider-specific settings.

How it works

Use createGoogleGenerativeAI when the default Google provider is insufficient and you need provider-specific settings such as an API key. The returned provider is callable with a model identifier, producing a language model that can be passed to AI SDK functions such as generateText.

Syntax

createGoogleGenerativeAI(options)

Parameters

NameTypeDescription
optionsprovider settings objectConfiguration settings for the customized Google Generative AI provider; the page's example passes a settings object but does not enumerate its fields in the fetched excerpt.

Returns

A configured Google Generative AI provider instance that can be called with a model identifier to create models.

Key points

  • Import createGoogleGenerativeAI from the @ai-sdk/google package.
  • The function creates a separately configured Google provider instance.
  • Call the factory with a settings object, then use the resulting provider to create models.
  • The returned provider selects Google Generative AI models through model identifiers.

Common mistakes

  • Use this factory for customized configuration; the default google provider is available when no customization is needed.

Example: Generate text with a customized Google provider

import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { generateText } from 'ai';

const google = createGoogleGenerativeAI({
  apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY,
});

const { text } = await generateText({
  model: google('gemini-2.0-flash-exp'),
  prompt: 'Explain dependency injection in one sentence.',
});

console.log(text);

Creates a configured Google provider and uses it to select a Gemini model for text generation.

When to use it

Customize authentication and provider settings

Set a custom Google API key or other provider configuration.

Create Google language models

Select Gemini models through a configured provider instance.

Integrate Google models into AI SDK applications

Use Google Generative AI capabilities while retaining the AI SDK interface.

  • google
  • @ai-sdk/google
  • Google Generative AI provider
  • generateText

Source: Google Generative AI Provider. Checked 2026-10-15.