npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gemini-web-api

v0.0.2

Published

TypeScript reverse-engineered asynchronous wrapper for the Google Gemini web app

Readme

Gemini Web-API Node.js Client

This is a TypeScript/Node.js reverse-engineered asynchronous Google Gemini client library. It replicates core web application features including authentication, multi-turn chat sessions, file uploads, and automatic session cookie rotation.

If you are looking for the OpenAI-compatible compatibility server, check out the apps/server application.

Features

  • Browser TLS & HTTP2 Fingerprinting: Uses impit under the hood to bypass bot detection.
  • Session/State Persistence: Persists multi-turn conversations ([cid, rid, rcid] metadata array) to continue conversations smoothly.
  • Auto-Rotation of Cookies: Background interval refreshes session cookies using Google's rotation endpoints and updates cached cookies locally.
  • File Upload Support: Allows uploading local files or buffers directly into the Gemini session for multimodal prompts.

Installation

Install the package via your preferred package manager:

npm install gemini-web-api
# or
pnpm add gemini-web-api
# or
yarn add gemini-web-api

Configure Environment

If using the default filesystem storage adapter, set up the required environment variables in your .env file:

# Default Gemini Web Client session cookies (from gemini.google.com)
GEMINI_SECURE_1PSID="your-secure-1psid-cookie"
GEMINI_SECURE_1PSIDTS="your-secure-1psidts-cookie"

# Optional configuration
GEMINI_COOKIE_PATH="./cookies.json"
GEMINI_ROTATION_INTERVAL_MS=180000
  • GEMINI_SECURE_1PSID (Required): The default account's primary cookie value.
  • GEMINI_SECURE_1PSIDTS (Recommended): The timestamp cookie, automatically updated by the rotator.
  • GEMINI_COOKIE_PATH (Optional): Directory or file path where auto-rotated cookies and cached data will be saved. Defaults to ~/.gemini_webapi.
  • GEMINI_ROTATION_INTERVAL_MS (Optional): Interval in milliseconds for background cookie rotation. Defaults to 3 minutes (180000 ms).

Available Scripts (Development)

If developing inside this package directory:

  • pnpm build: Compiles the TypeScript code into ESM (dist/index.js), CJS (dist/index.cjs), and type definitions (dist/index.d.ts) using tsup.
  • pnpm dev: Runs tsup in watch mode.
  • pnpm lint: Runs tsc --noEmit to check for type errors.
  • pnpm example: Runs the command-line chat demo (examples/chat.ts).

Library Usage Examples

Client Initialization

import { GeminiClient } from "gemini-web-api";

const client = new GeminiClient({
  cookies: {
    "__Secure-1PSID": process.env.GEMINI_SECURE_1PSID!,
    "__Secure-1PSIDTS": process.env.GEMINI_SECURE_1PSIDTS || "",
  },
  verbose: true,
});

// Initialize client (logs in, rotates cookies, sets up background refresh interval)
await client.init();

Active Chat Sessions (Multi-Turn Conversation)

// Start a new chat session with a specific model (default: "gemini-3-flash")
const chat = client.startChat({ model: "gemini-3-flash" });

// Send a simple message and wait for the response
const response = await chat.sendMessage("Hello! Introduce yourself.");
console.log(response.text);

// Or generate stream responses
const stream = chat.generateMessageStream("Tell me a long story.");
for await (const chunk of stream) {
  process.stdout.write(chunk.text);
}

💾 Custom Storage Adapters

By default, the library persists rotated cookie caches to the filesystem (via FileStorageAdapter). You can override this behavior by providing a custom StorageAdapter implementation (e.g., using Redis, databases, or Cloudflare Workers KV storage):

import { GeminiClient, StorageAdapter } from "gemini-web-api";

class MyCustomStorage implements StorageAdapter {
  async get(key: string): Promise<string | null> {
    // Retrieve value from database/cache
  }
  async set(key: string, value: string): Promise<void> {
    // Persist value to database/cache
  }
  async delete(key: string): Promise<void> {
    // Remove value from database/cache
  }
}

const client = new GeminiClient({
  cookies: {
    "__Secure-1PSID": "...",
    "__Secure-1PSIDTS": "...",
  },
  storage: new MyCustomStorage(),
});