Multi-account Gemini Business pool with intelligent rotation for OpenCode
🇷🇺 Русский | 🇬🇧 English
Auth plugin for OpenCode — pool multiple Gemini Business accounts with automatic rotation, failover, and load balancing.
opencode-gemini-business is an OpenCode plugin that enables multi-account rotation for Gemini Business API (business.gemini.google), providing automatic failover and load balancing across multiple accounts.
Important: This plugin uses the Gemini Business / Enterprise API, NOT Google AI Studio.
| Feature | Description |
|---|---|
| 🔄 Multi-Account Rotation | Automatically rotate between multiple Gemini Business accounts |
| 🛡️ Automatic Failover | Retry failed requests with different accounts seamlessly |
| 🔐 JWT Authentication | Built-in XSRF token retrieval and JWT (HS256) signing |
| 📡 Streaming Support | Full SSE streaming, JSON-lines, and fallback parsing |
| ⚙️ Flexible Strategies | Round-robin, least-used, or random rotation |
| 🔑 Auto Auth Setup | add-account automatically creates OpenCode auth record |
| Model | Internal API ID | Best For |
|---|---|---|
gemini-2.5-flash |
gemini-2.5-flash |
Everyday tasks, fast responses |
gemini-2.5-pro |
gemini-2.5-pro |
Complex reasoning |
gemini-3-flash |
gemini-3-flash-preview |
Next-gen fast model |
gemini-3-pro |
gemini-3-pro-preview |
Next-gen reasoning |
Add to ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-gemini-business@latest"],
"provider": {
"gemini-business": {
"name": "Gemini Business",
"options": {
"baseURL": "https://business.gemini.google/v1",
"apiKey": "unused"
},
"models": {
"gemini-2.5-flash": { "name": "Gemini 2.5 Flash" },
"gemini-2.5-pro": { "name": "Gemini 2.5 Pro" },
"gemini-3-flash": { "name": "Gemini 3 Flash" },
"gemini-3-pro": { "name": "Gemini 3 Pro" }
}
}
}
}Install the CLI tool:
npm install -g opencode-gemini-businessThen add your account:
opencode-gemini-business add-account \
"My Account" \
"e1f353e7-0291-44cf-9085-e0b6efd20e41" \
"CSE.AXUaAj_MKeqeFLr_..." \
"COS.AfQtEyCcW1aLwKb3..." \
"1370433092"Arguments:
| # | Argument | Description |
|---|---|---|
| 1 | Account name | Display name for the account |
| 2 | team_id |
UUID from URL /cid/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/ |
| 3 | __Secure-C_SES |
Cookie value (starts with CSE.) |
| 4 | __Host-C_OSES |
Cookie value (starts with COS.) |
| 5 | csesidx |
Number from URL ?csesidx=... |
Or use environment variables:
export GEMINI_ACCOUNT_NAME="My Account"
export GEMINI_TEAM_ID="e1f353e7-0291-44cf-9085-e0b6efd20e41"
export GEMINI_SECURE_C_SES="CSE.AXUaAj_MKeqeFLr_..."
export GEMINI_HOST_C_OSES="COS.AfQtEyCcW1aLwKb3..."
export GEMINI_CSESIDX="1370433092"
opencode-gemini-business add-accountNote:
add-accountautomatically creates the auth record in~/.local/share/opencode/auth.json, so you don't need to runopencode auth login.
# Flash model (fast)
opencode run --model=gemini-business/gemini-2.5-flash "Fix this bug"
# Pro model (best quality)
opencode run --model=gemini-business/gemini-2.5-pro "Design architecture"
# Next-gen models
opencode run --model=gemini-business/gemini-3-flash "Quick task"
opencode run --model=gemini-business/gemini-3-pro "Complex reasoning"Set as default model in opencode.json:
{
"model": "gemini-business/gemini-2.5-flash"
}Login to business.gemini.google and look at the URL:
https://business.gemini.google/home/cid/e1f353e7-0291-44cf-9085-e0b6efd20e41/r/session/123?csesidx=1370433092
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
team_id (UUID after /cid/) csesidx
Method 1: Browser Extension (Recommended)
- Install Get cookies.txt LOCALLY
- Open
business.gemini.googleand export cookies - Find
__Secure-C_SES(starts withCSE.) and__Host-C_OSES(starts withCOS.)
Method 2: DevTools
- Open DevTools (F12) → Application → Cookies →
https://business.gemini.google - Copy
__Secure-C_SESand__Host-C_OSESvalues
# List all accounts
opencode-gemini-business list-accounts
# Test account connectivity
opencode-gemini-business test-account <account_id>
# Remove account
opencode-gemini-business remove-account <account_id>
# Help
opencode-gemini-business help| Strategy | Behavior |
|---|---|
round-robin (default) |
Cycles through accounts in order |
least-used |
Selects least recently used account |
random |
Random selection |
Configure in ~/.config/opencode/gemini-business-accounts.json (auto-created on first add-account).
- Plugin registers as an OpenCode auth provider for
gemini-business - When a request comes in,
loader()returns a customfetch()function - Custom
fetch()intercepts the request from@ai-sdk/openai-compatible - Instead of calling
baseURL/chat/completions, it:- Picks an account via rotation strategy
- Gets XSRF token and creates JWT (HS256)
- Creates a session via
widgetCreateSession - Sends the actual request to
widgetStreamAssist - Converts the response back to OpenAI-compatible format
- Supports both streaming (SSE) and non-streaming responses
Q: Where do I find team_id?
Look at the URL in your browser: https://business.gemini.google/home/cid/e1f353e7-0291-44cf-9085-e0b6efd20e41/...
The UUID after /cid/ is your team_id.
Q: Do I need to run `opencode auth login`?
No. The add-account command automatically creates the auth record in ~/.local/share/opencode/auth.json. If for some reason it wasn't created, you can run opencode auth login, select gemini-business, and enter any key (e.g. unused).
Q: Session expired errors?
The plugin automatically refreshes sessions (cached for 50 minutes). If you see persistent errors, your cookies may have expired — re-extract them from the browser.
Q: Difference from Google AI Studio?
This plugin uses Gemini Business API (business.gemini.google) — enterprise accounts with higher rate limits. NOT Google AI Studio (aistudio.google.com).
- Credentials are stored locally in
~/.config/opencode/gemini-business-accounts.json - Never commit credentials to git
- Rotate cookies regularly
- The plugin does not send credentials to any third-party services
MIT © opencode-gemini-business contributors