Google Generative AI
Official SDK for Google Gemini API to build AI-powered applications.
Model SDKsNPM
3. Used by agents' projects
Dependency in 171 public GitHub projects set up for AI coding agents that we scanned (2.7%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
ai.google.dev/gemini-api/docs/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Google Generative AI does
Google's own TypeScript/JavaScript client for Gemini. One <code>GoogleGenAI</code> object reaches either the Gemini Developer API or Google's enterprise platform, and the maintainers publish a separate instruction file for coding agents because, they write, models "may suggest outdated or legacy code" for it.
Google Generative AI popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Google Generative AI is used
- Google Generative AI is a dependency in 171 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (3.5% of the 4,867 JavaScript/TypeScript ones), #5 of 92 in model sdks.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 792; those are left out of every share on this page.
- The most used alternative in our scan is OpenAI (286 projects).
- Projects that use it most often also use dotenv (56.7%), Lucide React (58.5%), React (72.5%).
- It is more common in projects set up for Gemini CLI (5.7%) than for GitHub Copilot (2.7%).
By coding agent
Often used with
Google Generative AI in practice
Strengths
Pass an <code>apiKey</code> for the Developer API. For the enterprise platform, pass <code>enterprise: true</code> with a project and location. In Node you can leave the constructor empty and set <code>GOOGLE_API_KEY</code>. For the enterprise platform, set <code>GOOGLE_GENAI_USE_ENTERPRISE</code>, <code>GOOGLE_CLOUD_PROJECT</code> and <code>GOOGLE_CLOUD_LOCATION</code> instead.
The maintainers publish <code>codegen_instructions.md</code> and recommend pasting it into your development environment. They say generative models may not know recent SDK updates and "may suggest outdated or legacy code".
Automatic continuation is on by default. When a response stops with <code>finishReason</code> set to <code>CONTINUATION</code> and returns a <code>continuationToken</code>, the SDK sends follow-up requests with that token until generation completes. It then returns the merged response. You can turn this off with <code>automaticContinuation: false</code>.
With the Interactions API you continue a conversation by passing the previous interaction's id instead of resending history. The README's Deep Research example starts the agent with <code>background: true</code>. It then polls <code>ai.interactions.get</code> once a second and stops when the status is <code>completed</code>, <code>failed</code> or <code>cancelled</code>.
Watch out for
The README warns that in the next major version you will not be able to invoke automatic function calling from direct <code>Models.generateContent</code> calls or their stream variants. It says to invoke it from the <code>Chats</code> module instead.
The README lists fields to be removed, each with a replacement. <code>GenerationConfigThinkingConfig</code> gives way to <code>ThinkingConfig</code>. For video generation, the README's table names the method in snake_case as <code>Models.generate_videos</code>. Its <code>prompt</code>/<code>text</code>/<code>image</code> arguments give way to <code>source</code>. <code>LiveConnectConfig.generation_config</code> is replaced by setting fields on <code>LiveConnectConfig</code> directly.
The current prerequisite is Node.js 20. From SDK version 3.0.0, Node.js 22 or later is required. The README advises pinning the SDK to <code>< 3.0.0</code> to avoid unexpected updates.
Quickstart: one generateContent call
import {GoogleGenAI} from '@google/genai';
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY});
async function main() {
const response = await ai.models.generateContent({
model: 'gemini-flash-latest',
contents: 'Why is the sky blue?',
});
console.log(response.text);
}
main();More about Google Generative AI
Head to head
- Anthropic SDK vs Google Generative AI used together in 42 projects
- OpenAI vs Google Generative AI used together in 51 projects
Packages around it
- @google/generative-ai: Earlier Gemini SDK package
- lucide-react: Icon components
- react: UI library
- dotenv: Env file loader
- typescript: Typed JavaScript
- tailwindcss: Utility CSS
Alternatives
Google Generative AI This page
Official TypeScript SDK for accessing OpenAI APIs including GPT and embeddings.
Official TypeScript SDK for calling Claude API and building agent applications.
Official JavaScript client library for Ollama to run and interact with local language models.
Official TypeScript SDK for calling Groq's fast language models API.
Official TypeScript SDK for calling Mistral's language models and APIs.
JavaScript client library for calling Replicate's AI model API.
Get started
Install it.
npm install @google/genaiRules for your agent
## Google Gen AI SDK (@google/genai)
- Read the official `codegen_instructions.md` before writing code for this SDK. The maintainers say models may suggest outdated or legacy code for it.
- Import `GoogleGenAI` from `@google/genai` and reach features through the instance: `ai.models`, `ai.chats`, `ai.files`, `ai.caches`, `ai.live`, `ai.interactions`.
- Keep API keys out of client-side code. The README says to use server-side implementations in production.
- On 2.x the prerequisite is Node.js 20 or later. Version 3.0.0 will require Node.js 22 and bring the listed removals. To defer that migration, the README advises pinning the SDK to `< 3.0.0` to avoid unexpected updates.
- Use `ThinkingConfig`, not `GenerationConfigThinkingConfig`. Use the `source` argument for video generation. The README lists the old forms for removal. Also note that the next major version will only run automatic function calling from `Chats`, not from direct `generateContent` calls.
- When sending `FunctionCall` or `FunctionResponse` parts, pass a full `Content[]` with explicit roles. Otherwise the SDK throws an exception.
- The SDK uses beta endpoints by default. Set `apiVersion: 'v1'` when you need stable endpoints. For API errors the SDK provides an `ApiError` class. The README's example catches the error and logs `e.name`, `e.message` and `e.status`.