Skip to content

Gemini CLI 配置

Gemini CLI 使用 Google 官方 npm 包。复制下面这一条指令,按提示粘贴 TimeSniper Key,脚本会自动安装官方包并写入环境变量。

只复制这一条

脚本会做什么

脚本会检测 Node.js,缺失时提示安装;随后安装官方 @google/gemini-cli 包,提示输入 TimeSniper Key,并持久化 GEMINI_API_KEYGOOGLE_GEMINI_BASE_URLGEMINI_MODEL

Windows 手动配置

powershell
npm install -g @google/gemini-cli@latest

$secureKey = Read-Host "Paste TimeSniper API Key" -AsSecureString
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureKey)
try {
  $plainKey = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr)
} finally {
  [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr)
}

[Environment]::SetEnvironmentVariable("GEMINI_API_KEY", $plainKey, "User")
[Environment]::SetEnvironmentVariable("GOOGLE_GEMINI_BASE_URL", "https://timesniper.club", "User")
[Environment]::SetEnvironmentVariable("GEMINI_MODEL", "gemini-3-pro-preview", "User")

$env:GEMINI_API_KEY = $plainKey
$env:GOOGLE_GEMINI_BASE_URL = "https://timesniper.club"
$env:GEMINI_MODEL = "gemini-3-pro-preview"

gemini --version

重新打开 PowerShell 后启动:

powershell
gemini

macOS / Linux 手动配置

bash
npm install -g @google/gemini-cli@latest

printf "Paste TimeSniper API Key: " >&2
stty -echo
read TS_KEY
stty echo
printf "\n" >&2

export TS_KEY
node <<'NODE'
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')

const shell = process.env.SHELL || ''
const profile = shell.includes('zsh')
  ? path.join(process.env.ZDOTDIR || os.homedir(), '.zshrc')
  : path.join(os.homedir(), '.bashrc')
const lines = [
  `export GEMINI_API_KEY=${JSON.stringify(process.env.TS_KEY || '')}`,
  'export GOOGLE_GEMINI_BASE_URL="https://timesniper.club"',
  'export GEMINI_MODEL="gemini-3-pro-preview"'
]
const current = fs.existsSync(profile) ? fs.readFileSync(profile, 'utf8') : ''
const cleaned = current
  .split('\n')
  .filter((item) => !item.startsWith('export GEMINI_API_KEY=') && !item.startsWith('export GOOGLE_GEMINI_BASE_URL=') && !item.startsWith('export GEMINI_MODEL='))
  .join('\n')
fs.writeFileSync(profile, cleaned.replace(/\s*$/, '') + '\n' + lines.join('\n') + '\n')
NODE

export GEMINI_API_KEY="$TS_KEY"
export GOOGLE_GEMINI_BASE_URL="https://timesniper.club"
export GEMINI_MODEL="gemini-3-pro-preview"
gemini --version

重新打开终端后启动:

bash
gemini

手动配置

bash
export GEMINI_API_KEY="sk-你的Key"
export GOOGLE_GEMINI_BASE_URL="https://timesniper.club"
export GEMINI_MODEL="gemini-3-pro-preview"

验证

bash
gemini -p "你好,确认当前模型和服务端是否可用"

如果需要切换模型,只修改 GEMINI_MODEL 即可。Key 分组需要在 TimeSniper 控制台中与目标模型匹配。

使用官方工具包与 TimeSniper 自有配置编写,不复制第三方站点内容。