The Google GenAI SDK.
Provides access to the GenAI features through either the Gemini API or the Vertex AI API.
The GoogleGenAIOptions.vertexai value determines which of the API services to use.
When using the Gemini API, a GoogleGenAIOptions.apiKey must also be set, when using Vertex AI GoogleGenAIOptions.project and GoogleGenAIOptions.location must also be set.
Initializing the SDK for using the Gemini API:
import {GoogleGenAI} from '@google/genai';const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'}); Copy
import {GoogleGenAI} from '@google/genai';const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
Initializing the SDK for using the Vertex AI API:
import {GoogleGenAI} from '@google/genai';const ai = new GoogleGenAI({ vertexai: true, project: 'PROJECT_ID', location: 'PROJECT_LOCATION'}); Copy
import {GoogleGenAI} from '@google/genai';const ai = new GoogleGenAI({ vertexai: true, project: 'PROJECT_ID', location: 'PROJECT_LOCATION'});
Readonly
The Google GenAI SDK.
Remarks
Provides access to the GenAI features through either the Gemini API or the Vertex AI API.
The GoogleGenAIOptions.vertexai value determines which of the API services to use.
When using the Gemini API, a GoogleGenAIOptions.apiKey must also be set, when using Vertex AI GoogleGenAIOptions.project and GoogleGenAIOptions.location must also be set.
Example
Initializing the SDK for using the Gemini API:
Example
Initializing the SDK for using the Vertex AI API: