Google Generative AI JavaScript SDK

The original JavaScript/TypeScript SDK for Google's Gemini API, now in maintenance-only mode and superseded by the unified Google Gen AI SDK.

SDK
npm
v0.24.1
1,237 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
50 /100 Fair
Development Activity 0
Maintenance 44
Community 68
Maturity 48
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 78
Code Quality 82
Innovation 72
Learning Curve 90

@google/generative-ai is the Node.js and browser SDK for calling Google’s Gemini API directly (not via Vertex AI). It provides a GoogleGenerativeAI client for minting GenerativeModel instances, then generateContent()/generateContentStream() for single-turn or streamed responses, a ChatSession helper for multi-turn conversations, plus support for function calling, system instructions, safety settings, token counting, and embeddings. A separate @google/generative-ai/server entry point exposes Node-only file upload and context-caching APIs for reference from prompts.

With the release of Gemini 2.0, Google unified this SDK with its Vertex AI SDK into a single @google/genai package and put this repository into limited maintenance: critical bug fixes only, with its stated end-of-life date (November 30, 2025) already passed. It remains widely installed — over 4 million weekly npm downloads — reflecting the large base of existing integrations that adopted it before the unification and have not yet migrated to the new SDK.

What You Get

  • A typed GoogleGenerativeAI client with getGenerativeModel() for text, multimodal, and function-calling requests against Gemini models
  • Streaming (generateContentStream) and non-streaming (generateContent) response handling, with streamed chunks consumable via async iteration
  • A ChatSession helper that manages multi-turn conversation history automatically
  • Content caching and file upload support via the isolated @google/generative-ai/server entry point (Node-only)
  • Built-in support for system instructions, safety settings, generation config, tool/function-calling schemas, and token counting

Common Use Cases

  • Adding a Gemini-powered chat feature - a team wires up ChatSession in a Node backend or browser app to get multi-turn conversational responses without hand-rolling history management
  • Multimodal prompting - passing images and text together as Part[] for an app that needs to reason over screenshots or documents
  • Function calling - defining Tool/ToolConfig schemas so the model can request structured function calls that the app then executes and returns results for
  • Server-side file and cache management - using the /server subpath to upload large files or set up cached content for repeated prompts, cutting token costs on Node-hosted services

Under The Hood

Architecture The package is layered: src/gen-ai.ts exposes the top-level GoogleGenerativeAI client, which mints GenerativeModel instances (src/models/generative-model.ts) that in turn delegate each operation to a methods/ layer (generate-content.ts, chat-session.ts, count-tokens.ts, embed-content.ts). Those methods funnel through a shared requests/ layer (request.ts builds the target URL and headers and issues the fetch call, request-helpers.ts formats request bodies, response-helpers.ts parses responses, stream-reader.ts aggregates server-sent-event chunks for streaming). A separate server/ subpackage, exposed via the @google/generative-ai/server export condition, provides GoogleAIFileManager and GoogleAICacheManager against a distinct Node-only REST surface. errors.ts centralizes a small typed error hierarchy that every layer throws through consistently. There is no dependency-injection container; the design relies on straightforward object construction, with request.ts’s URL/header-building functions acting as the single choke point every method ultimately depends on.

Tech Stack Written in strict TypeScript (5.2.2) with zero runtime dependencies, calling Gemini’s REST API directly via the native fetch/Headers APIs. Built with Rollup into dual CJS/ESM bundles for both the main and server entry points, with Microsoft’s API Extractor generating curated .d.ts files and API reports for each surface separately (api-extractor.json / api-extractor.server.json) — a level of public-API surface discipline beyond a typical small SDK. Documentation is generated straight from TSDoc comments via API Documenter into docs/reference/{main,server}. Release management uses Changesets with dedicated GitHub Actions workflows for release-PR creation and npm publishing. The package targets Node >=18 and browsers as a dual build, gating Node-only file/cache APIs behind the separate /server export.

Code Quality Twenty-three *.test.ts files sit alongside their source files, using Mocha, Chai, chai-as-promised, and Sinon for unit coverage of request formatting and response parsing, plus a separate test-integration/node suite and @web/test-runner-based browser integration tests. Error handling is explicit and typed rather than swallowed: request.ts checks response.ok and throws a structured GoogleGenerativeAIFetchError carrying status, statusText, and parsed error details, and a small class hierarchy (GoogleGenerativeAIError and subclasses for fetch/response/request-input/abort errors) is used consistently across the codebase. Naming is consistent and mirrors the underlying Gemini API task names. Linting (ESLint + typescript-eslint + import/unused-imports plugins) and Prettier formatting run as part of npm test and CI (.github/workflows/test.yml).

API Design The public API is intentionally small: new GoogleGenerativeAI(apiKey).getGenerativeModel({model}) followed by .generateContent() or .generateContentStream(), which accept either a bare string, an array of string/Part, or a fully-typed request object — minimizing boilerplate for the common case while still exposing systemInstruction, tools, safetySettings, and generationConfig for advanced use. ChatSession wraps multi-turn history management, and streaming responses are exposed as an async-iterable so consumers can for await chunks without manually parsing SSE. The dedicated /server entry point cleanly isolates Node-only file and cache APIs from the isomorphic client, and TSDoc {@link} cross-references throughout support IDE tooltips and the generated reference docs. The tradeoff is that, being deprecated in favor of @google/genai, its ergonomics deliberately preserve the old API’s shape rather than adopt the newer SDK’s conventions.

Used by 12 apps in this directory

TypeScript
100%
Other

Activepieces

AI Assistants · Automation · Mcp

24,756

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

View details
92
Repo Health
85
Technical
64
Dependency
Built with
TypeScript 100%
Updated 4 days ago
TypeScript
99%
Apache 2.0

Bubble Lab

AI Development · Automation

1,094

Open-core workflow engine for building AI-powered automations in TypeScript that run natively inside Slack — no context switching required.

View details
35
Repo Health
78
Technical
71
Dependency
Built with
TypeScript 99%
Updated 5 months ago
TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,049

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
73
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 5 days ago
TypeScript
62%
Other

Flowise

AI Development · Automation · Developer Tools

55,490

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
82
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 62%
JavaScript 27%
Updated 1 months ago
JavaScript
88%
GPL 3.0

Glass by Pickle

AI Assistants

7,604

A privacy-first desktop AI assistant that sees your screen, hears your meetings, and turns live context into structured summaries—without sending a single byte to the cloud.

View details
43
Repo Health
76
Technical
68
Dependency
Built with
JavaScript 88%
TypeScript 12%
Updated 11 months ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,301

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 4 days ago
Python
82%
MIT

LiteLLM

AI Development · Developer Tools

59,745

Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.

View details
92
Repo Health
81
Technical
69
Dependency
Built with
Python 82%
TypeScript 12%
Updated 4 days ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

206,147

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 92%
Updated 4 days ago
TypeScript
98%
Apache 2.0

rowboat

AI Assistants · AI Development

17,983

Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.

View details
85
Repo Health
72
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers