geminimock
v0.1.14
Published
OpenAI-compatible chat API server backed by Gemini Code Assist OAuth.
Readme
GeminiMock
OpenAI-compatible chat API server backed by Gemini Code Assist OAuth.
Terms of Service Warning
[!CAUTION] Using this project may violate Google's Terms of Service. Some users have reported account suspension or shadow restrictions.
High-risk scenarios:
- Fresh Google accounts are more likely to be flagged
- Newly created accounts with Pro/Ultra subscriptions may be reviewed or restricted quickly
By using this project, you acknowledge:
- This is an unofficial tool and is not endorsed by Google
- Your account access may be limited, suspended, or permanently banned
- You accept full responsibility for any risk or loss resulting from use
Recommendation:
- Prefer an established account that is not critical to your primary services
- Avoid creating new accounts specifically for this workflow
Install
- global:
npm i -g geminimock - one-off:
npx geminimock models list
Installed CLI command:
geminimock server startgeminimock server stopgeminimock server statusgeminimock auth login [--manual|--web]geminimock auth logoutgeminimock auth logout --allgeminimock auth accounts listgeminimock auth accounts use <id|email>geminimock auth accounts remove <id|email>geminimock models listgeminimock updategeminimock serve
Commands
bun run auth:loginbun run auth:logoutbun run auth:logout:allbun run auth:accounts:listbun run models:listbun run server:startbun run server:stopbun run server:statusbun run self:updatebun run devbun run startbun run testbun run lintbun run typecheckbun run buildbun run verify:releasebun run check:deps
Environment
GEMINI_CLI_API_HOSTdefault:127.0.0.1GEMINI_CLI_API_PORTdefault:43173GEMINI_CLI_MODELdefault:gemini-2.5-proCODE_ASSIST_ENDPOINTdefault:https://cloudcode-pa.googleapis.comCODE_ASSIST_API_VERSIONdefault:v1internalGEMINI_CLI_API_ACCOUNTS_PATHdefault:~/.geminimock/accounts.jsonGEMINI_CLI_API_OAUTH_PATHdefault:~/.geminimock/oauth_creds.jsonGEMINI_CLI_OAUTH_FALLBACK_PATHdefault:~/.gemini/oauth_creds.jsonGEMINI_CLI_OAUTH_CLIENT_IDoptional overrideGEMINI_CLI_OAUTH_CLIENT_SECREToptionalGEMINI_CLI_OAUTH_SOURCE_PATHoptional explicit path to Gemini CLIoauth2.jsfor auto-discoveryGEMINI_CLI_OAUTH_AUTO_DISCOVERYdefault:1(0disables Gemini CLI client auto-discovery)GEMINI_CLI_BIN_PATHoptional explicit path togeminiexecutable@google/gemini-cli-coreis bundled as dependency, so OAuth client config is discovered without separategeminiCLI installGEMINIMOCK_OAUTH_LOGIN_MODEoptional:auto(default),manual,webGEMINIMOCK_OAUTH_FORCE_MANUALoptional:1forces manual login flowGOOGLE_CLOUD_PROJECToptionalGOOGLE_CLOUD_PROJECT_IDoptional
OAuth Login
- Run
bun run auth:login - Browser OAuth opens automatically with local callback and account selection prompt
- If callback cannot complete, paste the authorization code or callback URL in terminal
- On SSH/headless Linux/CI environments, login automatically falls back to manual code flow instead of waiting on localhost callback timeout
- Use
geminimock auth login --manualto force manual flow,--webto force localhost callback flow - OAuth client config is resolved in this order: explicit env vars, installed Gemini CLI auto-discovery, bundled gemini-cli-core discovery
auth loginuses keyboard TUI (Up/Down,Enter,Ctrl+C) to start login, repeat login, or finishLogin Completedscreen showsLast login account: <email>auth logoutuses keyboard TUI (Up/Down,Enter,Q/Esc) to choose which account to logout- In the logout list,
[*]means the current active account - Choosing
Logout ALL accountsopens a second TUI confirm selector (No/Yes) auth logout --allclears all registered accounts and fallback Gemini auth state
Multi-Account Rotation
- accounts are stored in
~/.geminimock/accounts.json - active account is used by default
- automatic rotation occurs on API failures indicating rate/capacity/auth blocking:
- HTTP
429,503,401,403 - or error body containing quota/capacity/resource-exhausted indicators
- HTTP
- current account is put on temporary cooldown and next available account is selected
- project cache is invalidated automatically when active account changes (manual switch or auto-rotation), so server restart is not required
- use
geminimock auth accounts listto inspect active account and IDs - use
geminimock auth accounts use <id|email>to pin a specific account manually
Service Usage Guide
1) Start service
Run OAuth login first:
geminimock auth loginStart in background:
geminimock server start
geminimock server status- default URL is
http://127.0.0.1:43173 - if
43173is in use, an available port is selected automatically - always check actual URL with
geminimock server status - log file:
~/.geminimock/server.log
Run in foreground:
geminimock serveQuick health check:
curl -sS http://127.0.0.1:43173/health2) API endpoints
GET /healthGET /v1/auth/statusGET /v1/modelsPOST /v1/chat/completions
Check auth status:
curl -sS http://127.0.0.1:43173/v1/auth/statusResponse:
{"authenticated":true}List available models from current account/project:
curl -sS http://127.0.0.1:43173/v1/modelsResponse format (OpenAI-style model list):
{
"object": "list",
"data": [
{
"id": "gemini-2.5-flash",
"object": "model",
"created": 0,
"owned_by": "google-code-assist"
}
]
}3) Chat completion call pattern
Basic request:
curl -sS -X POST http://127.0.0.1:43173/v1/chat/completions \
-H 'content-type: application/json' \
-d '{"model":"gemini-2.5-flash","messages":[{"role":"user","content":"Hello"}]}'Basic response format (OpenAI-style):
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1772175296,
"model": "gemini-2.5-flash",
"choices": [
{
"index": 0,
"finish_reason": "STOP",
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
}
}
],
"usage": {
"prompt_tokens": 1,
"completion_tokens": 9,
"total_tokens": 31
}
}Streaming request (stream: true, SSE):
curl -N -sS -X POST http://127.0.0.1:43173/v1/chat/completions \
-H 'content-type: application/json' \
-d '{"model":"gemini-2.5-flash","stream":true,"messages":[{"role":"user","content":"Hello"}]}'Streaming response format:
data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant","content":"Hel"}}]}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":"lo"}}]}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","delta":{}}]}
data: [DONE]4) How answers are generated
- API is stateless per request
- server does not keep conversation memory between calls
- to continue a conversation, send full history in
messageseach call - response text is mapped to
choices[0].message.content - token usage is mapped to
usage.prompt_tokens,usage.completion_tokens,usage.total_tokens
Model resolution behavior:
- if requested model is unavailable, alias mapping may be applied
- example:
gemini-3-flash->gemini-3-flash-preview(when available) - model list normalizes
_vertexsuffix
5) System prompt and role mapping
System prompt usage example:
curl -sS -X POST http://127.0.0.1:43173/v1/chat/completions \
-H 'content-type: application/json' \
-d '{"model":"gemini-2.5-flash","messages":[{"role":"system","content":"You are concise."},{"role":"user","content":"Summarize OAuth in one sentence."}]}'Role mapping rules:
systemmessages are merged and sent as GeminisystemInstructionassistantmaps to Geminimodelusermaps to Geminiuserdeveloperandtoolare accepted but mapped asuser
Important:
- include at least one non-
systemmessage (userorassistant) - sending only
systemmay fail with400 INVALID_ARGUMENTfrom upstream
6) Error response style
Validation/route errors:
{"error":{"message":"..."}}Common upstream errors:
403 PERMISSION_DENIED: active account lacks permission for resolved project/model404 NOT_FOUND: requested model or entity does not exist in current project/account429 RESOURCE_EXHAUSTED: quota/capacity/rate limit
Troubleshooting steps:
- Check current auth:
curl -sS http://127.0.0.1:43173/v1/auth/status - Check available models:
geminimock models list - Check active account and switch if needed:
geminimock auth accounts listgeminimock auth accounts use <id|email>
GitHub Release Automation
- On push to
main,release-publish.ymlruns a single pipeline for version bump, npm publish, and GitHub release. - Bump rule from pushed commit messages:
#majororBREAKING CHANGEor!:-> major#minor-> minor- default (or
#patch) -> patch
- If multiple markers exist in the pushed commit range, priority is
major > minor > patch. - The workflow commits
package.jsonandpackage-lock.jsonwith[skip ci]to avoid duplicate runs from the bump commit. release-publish.ymlcreates release tagv<version>if it does not exist.- Release notes are generated automatically from the merged changes.
release-publish.ymlpublishes to npm using Trusted Publishing (OIDC) if that version is not already published.- Normal workflow: commit and push to
main; version bump, release, and npm publish run automatically.
Trusted Publisher setup values for npm:
- Publisher:
GitHub Actions - Organization or user:
yldst-dev - Repository:
GeminiMock - Workflow filename:
release-publish.yml - Environment name: leave empty
