
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
@genkit-ai/google-genai
Advanced tools
Genkit AI framework plugin for Google AI & Vertex APIs, including Gemini APIs.
This plugin provides a unified interface to connect with Google's generative AI models, offering access through both the Gemini Developer API and Vertex AI. It is a replacement for the previous googleAI
and vertexAI
plugins.
Official documentation:
npm i --save @genkit-ai/google-genai
This unified plugin exports two main initializers:
googleAI
: Allows access to models via the Gemini Developer API using API key authentication.vertexAI
: Allows access to models via Google Cloud Vertex AI. Authentication can be done via Google Cloud Application Default Credentials (ADC) or a simpler API Key for Express Mode.You can configure one or both in your Genkit setup depending on your needs.
googleAI
)Ideal for quick prototyping and access to models available in Google AI Studio.
Authentication: Requires a Google AI API Key, which you can get from Google AI Studio. You can provide this key by setting the GEMINI_API_KEY
or GOOGLE_API_KEY
environment variables, or by passing it in the plugin configuration.
import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [
googleAI(),
// Or with an explicit API key:
// googleAI({ apiKey: 'your-api-key' }),
],
});
vertexAI
)Suitable for applications leveraging Google Cloud's AI infrastructure.
Authentication Methods:
gcloud auth application-default login
locally). This method requires a Google Cloud Project with billing enabled and the Vertex AI API enabled.import { genkit } from 'genkit';
import { vertexAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [
// Using Application Default Credentials (Recommended for full features)
vertexAI({ location: 'us-central1' }), // Regional endpoint
// vertexAI({ location: 'global' }), // Global endpoint
// OR
// Using Vertex AI Express Mode (Easy to start, some limitations)
// Get an API key from the Vertex AI Studio Express Mode setup.
// vertexAI({ apiKey: process.env.VERTEX_EXPRESS_API_KEY }),
],
});
Note: When using Express Mode, you do not provide projectId
and location
in the plugin config.
You can configure both plugins if you need to access models or features from both services.
import { genkit } from 'genkit';
import { googleAI, vertexAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [
googleAI(),
vertexAI()
],
});
Access models and embedders through the configured plugin instance (googleAI
or vertexAI
).
With googleAI
:
import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [googleAI()],
});
const response = await ai.generate({
model: googleAI.model('gemini-2.5-flash'),
prompt: 'Tell me something interesting about Google AI.',
});
console.log(response.text());
With vertexAI
:
import { genkit } from 'genkit';
import { vertexAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [vertexAI()],
});
const response = await ai.generate({
model: vertexAI.model('gemini-2.5-pro'),
prompt: 'Explain Vertex AI in simple terms.',
});
console.log(response.text());
With googleAI
:
import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [googleAI()],
});
const embeddings = await ai.embed({
embedder: googleAI.embedder('text-embedding-004'),
content: 'Embed this text.',
});
With vertexAI
:
import { genkit } from 'genkit';
import { vertexAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [vertexAI()],
});
const embeddings = await ai.embed({
embedder: vertexAI.embedder('text-embedding-005'),
content: 'Embed this text.',
});
With googleAI
:
import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [googleAI()],
});
const response = await ai.generate({
model: googleAI.model('imagen-3.0-generate-002'),
prompt: 'A beautiful watercolor painting of a castle in the mountains.',
});
const generatedImage = response.media();
With vertexAI
:
import { genkit } from 'genkit';
import { vertexAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [vertexAI()],
});
const response = await ai.generate({
model: vertexAI.model('imagen-3.0-generate-002'),
prompt: 'A beautiful watercolor painting of a castle in the mountains.',
});
const generatedImage = response.media();
import { genkit } from 'genkit';
import { vertexAI } from '@genkit-ai/google-genai';
const ai = genkit({
plugins: [vertexAI()],
});
const response = await ai.generate({
model: vertexAI.model('lyria-002'),
prompt: 'A relaxing, instrumental piano track.',
});
const generatedAudio = response.media();
googleAI
: Easier setup for smaller projects, great for prototyping with Google AI Studio. Uses API keys.vertexAI
: Enterprise-ready, integrates with Google Cloud IAM and other Vertex AI services. Offers a broader range of models and features like Lyria, fine-tuning, and more robust governance. Vertex AI Express Mode provides a low-friction entry point using an API key.Choose the interface based on your project's scale, infrastructure, and feature requirements.
The sources for this package are in the main Genkit repo. Please file issues and pull requests against that repo.
Apache-2.0
FAQs
Genkit AI framework plugin for Google AI & Vertex APIs, including Gemini APIs.
The npm package @genkit-ai/google-genai receives a total of 37,403 weekly downloads. As such, @genkit-ai/google-genai popularity was classified as popular.
We found that @genkit-ai/google-genai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.