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

@8-/gemini-web-api

v1.0.2

Published

OpenAI-compatible Gemini Web API reverse proxy running on Bun & Node.js / 兼容 OpenAI 格式的 Gemini Web 反向代理服务

Readme

Gemini Web API

OpenAI-compatible Gemini Web API reverse proxy running on Bun & Node.js. Automatically detects Chrome session cookies. Zero configuration required.

兼容 OpenAI 格式的 Gemini Web 反向代理服务,支持 Bun 与 Node.js 双运行时。 全自动探测本地 Chrome 凭据,无需任何手动配置,开箱即用。


English

Overview

@8-/gemini-web-api is an ultra-lightweight reverse proxy that turns your Google Gemini Web session into a standard OpenAI-compatible API.

No configuration is needed: It automatically discovers your existing Chrome / Brave / Edge browser session, retrieves the encryption key from the macOS Keychain, decrypts your Gemini session cookies, and starts serving OpenAI-compatible endpoints (/v1/chat/completions, /v1/models) instantly.

Key Highlights

  • Zero Configuration: As long as you are logged into gemini.google.com in Chrome (or Brave / Edge), the server automatically extracts and decrypts your tokens. No manual cookie copying or .env required!
  • Dual Runtime Support: Native ultra-high performance on Bun (Bun.serve) and seamless native support on Node.js (>= 22.5.0, via node:sqlite and Web Streams).
  • Zero External Dependencies: 100% built on standard Web APIs (fetch, ReadableStream, crypto.subtle) and built-in Node/Bun modules. Zero node_modules required!
  • OpenAI Drop-in Replacement: Fully compatible with /v1/chat/completions and /v1/models. Works seamlessly with ChatGPT-Next-Web, LobeChat, Cherry Studio, Cline, Roo Code, Cursor, Aider, and official OpenAI SDKs.
  • Robust 4-Tier Tool / Function Calling Engine:
    1. Tier 1 (Fenced Code Blocks): Parses ```tool_call, ```tool_calls, ```json, or bare ``` blocks.
    2. Tier 2 (Tool Call Arrays): Extracts structured "tool_calls": [...] arrays embedded in output.
    3. Tier 3 (Unfenced / Broken Fences): Recovers missing opening backticks (e.g. `tool_call\n{...}````).
    4. Tier 4 (Bare JSON Objects): Bracket-matched scanner for raw JSON objects with name and arguments/args/input.
    • Auto Syntax Healing: Automatically cleans escaped markdown underscores (subagent\_type → subagent_type), trailing commas, unquoted keys, and invalid escapes.
    • Framework Agnostic: Natively normalizes tool call formats from Vercel AI SDK, ZCode, LangChain, and OpenAI SDKs (toolCalls, input, toolName, toolCallId).
  • Reasoning & Thinking Models: Full support for <think> thoughts and reasoning_content deltas in SSE streaming with an automatic tag closure state machine, as well as reasoning_content in non-streaming responses.
  • Dynamic Model Discovery: Automatically discovers available Gemini models (Flash, Pro, etc.) and capacity tiers directly from your web session.
  • Image Proxy: Built-in /gemini-proxy/image endpoint to safely render generated card images without CORS or anti-hotlinking issues.

Installation

Install globally using Bun or npm:

# Using Bun
bun i -g @8-/gemini-web-api

# Using npm
npm i -g @8-/gemini-web-api

Or run instantly without installing:

# Using bunx
bunx @8-/gemini-web-api

# Using npx
npx @8-/gemini-web-api

Usage

1. Start the Server

Simply run:

gemini-web-api

The server will automatically:

  1. Detect your local Chrome / Brave / Edge cookies database.
  2. Read the encryption key from macOS Keychain.
  3. Decrypt your __Secure-1PSID and __Secure-1PSIDTS cookies.
  4. Discover available models from Gemini.
  5. Start listening on http://127.0.0.1:7860.

2. Optional Environment Variables

If you want to customize the port, add an authentication key, or enable thinking mode, set environment variables inline or in a .env file:

# Example: Custom port, API key, and thinking mode
PORT=8000 API_KEY=sk-mysecret ENABLE_THINKING=true gemini-web-api

| Variable | Default | Description | | :--- | :--- | :--- | | PORT | 7860 | Server listening port | | HOST | 127.0.0.1 | Server listening host | | API_KEY | (empty) | Optional Bearer API key for authorization | | ENABLE_THINKING | false | Enable reasoning thoughts (<think> blocks & reasoning_content) | | SECURE_1PSID | (auto-detected) | Manual override for __Secure-1PSID cookie (only needed if no browser is logged in) | | SECURE_1PSIDTS | (auto-detected) | Manual override for __Secure-1PSIDTS cookie |


API Calling Examples

1. Streaming Chat (cURL)

curl -N http://127.0.0.1:7860/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-flash",
    "messages": [
      {"role": "user", "content": "Explain quantum computing in one sentence."}
    ],
    "stream": true
  }'

2. Function Calling / Tool Calling (Python SDK)

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:7860/v1",
    api_key="none"
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather for a city.",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string"}
                },
                "required": ["city"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="gemini-flash",
    messages=[{"role": "user", "content": "What is the weather in Tokyo?"}],
    tools=tools,
    tool_choice="auto"
)

message = response.choices[0].message
if message.tool_calls:
    for tool_call in message.tool_calls:
        print(f"Tool: {tool_call.function.name}")
        print(f"Arguments: {tool_call.function.arguments}")

3. Streaming Chat with Node.js SDK

import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "http://127.0.0.1:7860/v1",
  apiKey: "none",
});

const stream = await openai.chat.completions.create({
  model: "gemini-flash",
  messages: [{ role: "user", content: "Tell me a short joke." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}

简体中文

项目简介

@8-/gemini-web-api 是一个极简的 Google Gemini Web 转 OpenAI 标准接口反向代理服务。

无需繁琐配置:只需在日常使用的 Chrome(或 Brave、Edge)浏览器中登录过 gemini.google.com,程序启动时即可全自动探测浏览器 Cookie 数据库,通过 macOS Keychain 提取密钥并自动解密登录凭据,立即开始提供兼容 OpenAI 的 /v1/chat/completions 与 /v1/models 接口!

核心亮点

  • 开箱即用,零手动配置:自动探测 Chrome / Brave / Edge 浏览器会话,全自动解密并获取登录令牌,彻底告别手动抓包复制 Cookie 的烦恼!
  • Bun 与 Node.js 双运行时支持:在 Bun 下使用原生 Bun.serve 极速响应;在 Node.js (>= 22.5.0) 下利用内置 node:sqlite 与原生 Web Streams 同样流畅运行。
  • 零第三方外部依赖:纯基于 Web 标准接口(fetch、ReadableStream、crypto.subtle)与运行时内置标准模块构建,零 node_modules 外部依赖!
  • 无缝替代 OpenAI 接口:标准 /v1/chat/completions 与 /v1/models 路由,直接兼容 ChatGPT-Next-Web、LobeChat、Cherry Studio、Cline、Roo Code、Cursor、Aider 以及官方 OpenAI SDK。
  • 四级高鲁棒性 Function Calling / 工具调用引擎:
    1. 第一级(围栏代码块):精确解析 ```tool_call、```tool_calls、```json 或裸反引号代码块。
    2. 第二级(数组提取):自动提取内嵌于回复中的 "tool_calls": [...] 结构体。
    3. 第三级(缺失开头围栏容错):支持缺失开头反引号等残缺输出自愈(如 `tool_call\n{...}````)。
    4. 第四级(无围栏裸 JSON 深度探测):括号平衡算法精确提取包含 name 与 arguments/args/input 的独立 JSON 对象,游标防跳步确保多个紧邻调用不遗漏。
    • 语法自动修复:自动反转义 Markdown 下划线(subagent\_type → subagent_type),智能修复未加引号的键名与尾随逗号。
    • 框架协议泛化:原生兼容 Vercel AI SDK、ZCode、LangChain 及各类 Agent 框架自定义字段(toolCalls、input、toolName、toolCallId)。
  • 深度思考与推理模式:完整支持 <think> 思考标签与 SSE reasoning_content 流式字段传输,内置状态机保证思考标签严格闭合,且在非流式调用中完整保留思考链。
  • 动态模型列表发现:启动时自动从 Gemini 网页端动态拉取已解锁的可用模型及配额层级。
  • 图片安全代理:内置 /gemini-proxy/image 接口,解决 Google 生成图片防盗链和跨域展示问题。

安装方式

通过 Bun 或 npm 全局安装:

# 使用 Bun 全局安装
bun i -g @8-/gemini-web-api

# 使用 npm 全局安装
npm i -g @8-/gemini-web-api

或者无需安装,直接使用 bunx / npx 即开即用:

# 使用 bunx
bunx @8-/gemini-web-api

# 使用 npx
npx @8-/gemini-web-api

使用指南

1. 启动服务

安装后直接在终端运行:

gemini-web-api

程序将全自动执行:

  1. 自动探测本地 Chrome、Brave、Edge 浏览器的 Cookie 存储路径;
  2. 自动从 macOS Keychain 安全读取加密密码并推导密钥;
  3. 解密 __Secure-1PSID 与 __Secure-1PSIDTS 凭据;
  4. 动态同步 Gemini 网页端模型配置;
  5. 在 http://127.0.0.1:7860 启动 OpenAI 兼容接口。

2. 可选环境变量配置

如需自定义端口、设置访问密码或启用思考模式,可在命令行直接传入或在当前目录下创建 .env 文件:

# 示例:自定义端口 8000、密码及开启思考模式
PORT=8000 API_KEY=sk-mysecret ENABLE_THINKING=true gemini-web-api

| 环境变量 | 默认值 | 说明 | | :--- | :--- | :--- | | PORT | 7860 | 服务的监听端口 | | HOST | 127.0.0.1 | 监听的主机地址 | | API_KEY | (留空) | 可选的 Bearer 访问密码鉴权 | | ENABLE_THINKING | false | 是否开启思考模式(输出 <think> 与 reasoning_content) | | SECURE_1PSID | (自动探测) | 手动指定 __Secure-1PSID(仅在未登录浏览器时需要) | | SECURE_1PSIDTS | (自动探测) | 手动指定 __Secure-1PSIDTS |


接口调用示例

1. cURL 流式对话调用

curl -N http://127.0.0.1:7860/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-flash",
    "messages": [
      {"role": "user", "content": "用一句话解释相对论"}
    ],
    "stream": true
  }'

2. 工具调用 / Function Calling (Python SDK)

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:7860/v1",
    api_key="none"  # 未设置 API_KEY 时可填任意字符串
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "查询指定城市的天气温度",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {"type": "string"}
                },
                "required": ["city"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="gemini-flash",
    messages=[{"role": "user", "content": "查询东京的天气"}],
    tools=tools,
    tool_choice="auto"
)

message = response.choices[0].message
if message.tool_calls:
    for tool_call in message.tool_calls:
        print(f"触发工具: {tool_call.function.name}, 参数: {tool_call.function.arguments}")

3. Node.js 流式对话 (OpenAI SDK)

import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "http://127.0.0.1:7860/v1",
  apiKey: "none",
});

const stream = await openai.chat.completions.create({
  model: "gemini-flash",
  messages: [{ role: "user", content: "讲个笑话吧" }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}

开源协议

本项目采用 MIT License 授权。