goldyard
  • Joined on 2026-01-26

gcli (0.8.0)

Published 2026-05-04 05:50:27 +00:00 by goldyard

Installation

pip install --index-url https://git.totoro.studio/api/packages/goldyard/pypi/simple/ --extra-index-url https://pypi.org/simple gcli

About this package

CLI tool for Google Gemini Web API (reverse-engineered)

gcli

Google Gemini Web API 的命令行工具。基于逆向工程的 Web 接口,需要 Google 账号(免费或付费订阅均可使用,付费解锁高级模型)。

项目结构

gemini-api/
├── src/gcli/
│   ├── __init__.py      # 版本号
│   ├── cli.py           # 入口:参数解析、子命令路由、管道输入
│   ├── client.py        # GcliClient,封装 gemini_webapi + 订阅层级检测
│   ├── config.py        # 配置管理(代理、Cookie、模型偏好)
│   ├── health.py        # 安全自检(代理 → Cookie → API)
│   ├── models.py        # 模型别名 + 订阅层级检测 + 智能推荐
│   └── chat.py          # 多轮对话 REPL
├── tests/
│   ├── conftest.py      # 测试 fixtures(临时配置工厂)
│   ├── test_cli.py
│   ├── test_client.py
│   ├── test_config.py
│   ├── test_health.py
│   ├── test_models.py
│   └── test_integration.py  # 需要网络 + Cookie
├── pyproject.toml
├── DESIGN.md
├── CLAUDE.md
└── tools.yaml

安装

# 安装(需要 Python >= 3.10)
uv tool install /path/to/gemini-api

# 修改代码后重新安装
uv tool install --force /path/to/gemini-api

# 或者直接从源码运行(开发用)
uv run gcli --help

配置

首次初始化

gcli init

交互式配置:代理地址 + 两个 Cookie 值。配置文件保存在 ~/.gcli/config.json

获取 Cookie

  1. 浏览器打开 gemini.google.com 并登录
  2. F12 → Network → 刷新页面
  3. 从请求头中复制 __Secure-1PSID__Secure-1PSIDTS

环境变量

变量 用途
GCLI_PROXY 覆盖配置文件中的代理地址
GCLI_CONFIG_PATH 自定义配置文件路径

使用

# 单轮问答
gcli "解释什么是 RAG"

# 指定模型
gcli -m flash "1+1=?"
gcli -m ultra "用最强的模型回答"
gcli -m auto "自动选最好的模型"

# 管道输入
cat log.txt | gcli "分析这个日志"
echo "Hello" | gcli "翻译成中文"

# 多轮对话
gcli chat
gcli chat "你好"

# 其他命令
gcli health          # 安全自检
gcli models          # 查看账号层级 + 可用模型
gcli -v "测试"       # 调试模式(显示 prompt 信息)

聊天命令

多轮对话中支持:

  • /model <name> — 切换模型(支持所有别名和完整名)
  • /models — 查看可用模型
  • /clear — 清空对话上下文
  • /quit — 退出
  • /help — 显示帮助

模型与订阅层级

模型权限取决于你的 Google 账号层级。运行 gcli models 查看实际可用的模型。

免费账号:

别名 模型名 说明
pro gemini-3-pro 通用
flash gemini-3-flash 快速响应
thinking gemini-3-flash-thinking 深度思考(默认)

Plus / Advanced (Ultra) — 需要付费订阅:

别名 模型名 说明
ultra gemini-3-flash-thinking-advanced Ultra 深度思考
pro-ultra gemini-3-pro-advanced Ultra Pro
flash-ultra gemini-3-flash-advanced Ultra Flash
pro-plus gemini-3-pro-plus Plus Pro
flash-plus gemini-3-flash-plus Plus Flash
thinking-plus gemini-3-flash-thinking-plus Plus Thinking

也可以直接使用完整模型名。-m auto 会根据你的账号层级自动选最优模型。

订阅层级检测

gcli models 会自动检测并显示:

  • 账号订阅层级(免费 / Pro / Plus / Advanced)
  • 每个模型的可用状态(基础 / 高级)
  • 推荐的最优模型

-m auto 模式会根据检测结果自动选择当前账号可用的最强模型。

测试

# 运行单元测试(排除集成测试)
uv run pytest

# 运行单个测试
uv run pytest tests/test_config.py::test_load_full_config

# 运行集成测试(需要网络 + Cookie)
GCLI_TEST_PROXY=http://127.0.0.1:7890 \
GCLI_TEST_COOKIES='{"__Secure-1PSID":"...","__Secure-1PSIDTS":"..."}' \
uv run pytest -m integration

安全约束

  • 强制代理:客户端拒绝在无代理情况下启动,防止 IP 泄漏
  • Cookie 有效期:自动追踪过期时间,过期阻止启动,即将过期发出警告
  • 快速启动门控:启动时仅检查 Cookie 过期,代理/API 在实际调用时验证,避免不必要的网络请求阻塞

依赖

Requirements

Requires Python: >=3.10
Details
PyPI
2026-05-04 05:50:27 +00:00
6
135 KiB
Assets (2)
Versions (6) View all
0.8.0 2026-05-04
0.7.8 2026-05-04
0.7.7 2026-05-04
0.7.1 2026-04-26
0.6.0 2026-04-26