googleapis/js-genai
TypeScript/JavaScript SDK for Gemini and Vertex AI.
Google Gen AI SDK for TypeScript & JavaScript
What it is – An official Google‑provided client library (@google/genai) that lets JavaScript/TypeScript code call the Gemini family of large language models. It supports both the public Gemini Developer API (via an API key) and the Gemini Enterprise Agent Platform (via Google Cloud credentials).
Key capabilities
- Model calls –
generateContent,generateContentStream,generateImages,generateVideos, etc. - Stateful chats –
ai.chatsobjects keep conversation history for multi‑turn interactions. - Caching –
ai.cacheslets you store large prompt prefixes on the server to reduce token cost. - File handling –
ai.filesuploads large assets (images, audio, PDFs) that can be referenced in prompts. - Live sessions –
ai.liveenables real‑time text/audio/video interaction. - Function calling / tools – Declare functions or use built‑in tools (Google Search, code execution, Model Context Protocol) and let Gemini call them automatically.
- Interactions API – A higher‑level wrapper (
ai.interactions) that manages state, tool orchestration, and long‑running tasks such as deep‑research agents.
Typical usage
import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({apiKey: process.env.GEMINI_API_KEY});
const resp = await ai.models.generateContent({
model: 'gemini-2.5-flash',
contents: 'Why is the sky blue?'
});
console.log(resp.text);
The same class works in Node, the browser, or in an enterprise environment where you pass enterprise: true plus project and location.
Installation – npm install @google/genai (requires Node 20+, later versions need Node 22+).
Documentation & samples – Full API reference at https://googleapis.github.io/js-genai/ and a collection of runnable examples in the repository’s sdk-samples folder.
Why it matters – It gives developers a single, up‑to‑date way to access Google’s newest Gemini 2.0+ features (multimodal input, streaming, automatic function calling, MCP, etc.) without dealing with raw HTTP calls or older SDKs.
Related
- Project
- Project
- Project
- Project
- Project