Gemini Integration
Oracle supports Gemini in two distinct ways:
- Gemini API mode (
--engine api) viaGEMINI_API_KEY - Gemini web (cookie) mode (
--engine browser) via your signed-in Chrome cookies atgemini.google.com(no API key required)
#Usage (API)
- Get an API Key: Obtain a key from Google AI Studio.
- Set Environment Variable: Export the key as
GEMINI_API_KEY. - Run Oracle: Use the
--model(or-m) flag to select Gemini.
``bash export GEMINI_API_KEY="your-google-api-key" ``
``bash oracle --engine api --model gemini --prompt "Explain quantum entanglement" ` Use an explicit current model ID: `bash oracle --engine api --model gemini-3.5-flash --prompt "..." ` Gemini 3.1 Pro is also available; Oracle dispatches it to Google's preview model id: `bash oracle --engine api --model gemini-3.1-pro --prompt "..." ` For the lowest-cost current model: `bash oracle --engine api --model gemini-3.1-flash-lite --prompt "..." ``
#Usage (Gemini web / cookies)
Gemini web mode is a cookie-based client for gemini.google.com. It does not use GEMINI_API_KEY and does not drive ChatGPT.
Prereqs:
- Chrome installed.
- Signed into
gemini.google.comin the Chrome profile Oracle uses (default:Defaultprofile).
Examples:
# Text run
oracle --engine browser --model gemini-3.5-flash --prompt "Say OK."
# Deep Think browser run (manual-login profile recommended on macOS)
oracle --engine browser --browser-manual-login \
--model gemini-3-deep-think \
--prompt "Think carefully, then answer in one paragraph."
# Generate an image (writes an output file)
oracle --engine browser --model gemini-3.1-pro \
--prompt "a cute robot holding a banana" \
--generate-image out.jpg --aspect 1:1
# Edit an image (input via --edit-image, output via --output)
oracle --engine browser --model gemini-3.1-pro \
--prompt "add sunglasses" \
--edit-image in.png --output out.jpg
Notes:
- Current explicit IDs are
gemini-3.1-flash-lite,gemini-3.5-flash, andgemini-3.1-pro. - Legacy
gemini-3-pro,gemini-2.5-pro, andgemini-2.5-flashbrowser names remain accepted and map to current Gemini web models. - If your logged-in Gemini account can’t access the requested model, Oracle auto-falls back to Gemini 3.1 Flash-Lite and logs the fallback in verbose mode.
- Pass
--no-gemini-fallbackto fail instead when the requested web model is unavailable. - Gemini web requests accept response headers up to 64 KiB automatically, including Google's large security and reporting policies; no Node options are required. These requests honor
HTTP_PROXY,HTTPS_PROXY, andNO_PROXY(including lowercase equivalents) and Node's TLS trust configuration. - This path runs fully in Node/TypeScript (no Python/venv dependency).
- Local MCP consultations and detached workers use the same Gemini executor as the CLI and preserve the session's saved Gemini options. The explicit model key takes precedence over ChatGPT picker labels.
- Gemini browser runs also support
--remote-host. Upgrade both endpoints, sign into Gemini on the service host, then runoracle --engine browser --model gemini-3.5-flash --remote-host <host:port> --remote-token <token> --prompt "Say OK.". New runs and restarts dispatch the Gemini web executor on that host; Google cookies and browser state stay there. Host manual-login profiles andoracle serve --browser-attach-runningare supported. Text, file attachments, YouTube prompts, thoughts, and--no-gemini-fallbackare forwarded; image generation/editing still require a local Gemini run. --browser-model-strategyonly affects ChatGPT automation; Gemini web always uses the explicit Gemini model ID.gemini-3-deep-thinkis browser-only for now.--engine apirejects it instead of silently falling back to regular Gemini Pro.- Oracle intentionally does not expose generic
low/medium/highGemini aliases. Explicit IDs keep model choice, billing, and thinking-effort configuration distinct. - If Chrome cookie extraction fails, the missing-cookie error now includes any cookie-reader warnings plus
--browser-manual-login/--browser-inline-cookies-fileguidance.
#Implementation details
#Gemini API adapter
src/oracle/gemini.ts— adapter using@google/genaithat returns aClientLike.- Model IDs:
gemini-3.1-flash-liteandgemini-3.5-flashuse their stable API IDs;gemini-3.1-promaps togemini-3.1-pro-preview; legacygemini-3-promaps togemini-3-pro-preview. - Request mapping:
OracleRequestBody→ Gemini request;web_search_previewmaps to Gemini search tooling. - Response mapping: Gemini responses →
OracleResponse. - Streaming: wraps Gemini’s async iterator as
ResponseStreamLike. src/oracle/run.ts— selectsGEMINI_API_KEYvsOPENAI_API_KEYbased on model prefix.src/oracle/config.ts/src/oracle/types.ts— model config +ModelName.
#Gemini web client (cookie-based)
src/gemini-web/models.ts— centralizes current private web model headers, legacy aliases, and fallback selection.src/gemini-web/client.ts— talks togemini.google.comand downloads generated images via authenticatedgg-dlredirects.src/gemini-web/http.ts— uses a reusable, Gemini-only Undici dispatcher with a 64 KiB response-header limit. It does not change the global dispatcher or replay failed requests. Embedders with custom dispatcher/proxy/TLS settings can usecreateGeminiWebDispatcher(options)and passdispatchertofetchGeminiWebResource; an explicitly supplied dispatcher owns its header limit. Global dispatcher customizations do not configure this dedicated transport.src/gemini-web/executor.ts— browser-engine executor for Gemini (loads Chrome cookies and runs the web client).
#Testing
- Unit/regression:
pnpm vitest run tests/gemini.test.ts tests/gemini-web - Live (API):
ORACLE_LIVE_TEST=1 pnpm vitest run tests/live/gemini-live.test.ts - Live (Gemini web/cookies):
ORACLE_LIVE_TEST=1 pnpm vitest run tests/live/gemini-web-live.test.ts