opencode-gemini-business 2.0.5 β 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.en.md +278 -0
- package/README.md +159 -272
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +84 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -25
- package/dist/index.js.map +1 -1
- package/dist/opencode-gemini-business-2.2.0.tgz +0 -0
- package/dist/src/browser-auth.d.ts +35 -0
- package/dist/src/browser-auth.d.ts.map +1 -0
- package/dist/src/browser-auth.js +212 -0
- package/dist/src/browser-auth.js.map +1 -0
- package/dist/src/gemini-business-api.d.ts.map +1 -1
- package/dist/src/gemini-business-api.js +85 -25
- package/dist/src/gemini-business-api.js.map +1 -1
- package/dist/src/types.d.ts +19 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/README.ru.md +0 -397
- package/dist/opencode-gemini-business-2.0.5.tgz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [2.2.0](https://github.com/izzzzzi/opencode-gemini-business/compare/v2.1.0...v2.2.0) (2026-03-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* browser-based account login, update model list, swap README lang ([d0eb82f](https://github.com/izzzzzi/opencode-gemini-business/commit/d0eb82fabf337004f330646fb1ec1af38cb87d96))
|
|
7
|
+
|
|
8
|
+
# [2.1.0](https://github.com/izzzzzi/opencode-gemini-business/compare/v2.0.5...v2.1.0) (2026-02-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update tests for named export and async plugin factory ([582bada](https://github.com/izzzzzi/opencode-gemini-business/commit/582badaa32aefd7cee8c39642224f06972e15b2e))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* auto-create auth record, update models and streaming ([13c5e8a](https://github.com/izzzzzi/opencode-gemini-business/commit/13c5e8a065051deadc4663757b42cbba189fcaec))
|
|
19
|
+
|
|
1
20
|
## [2.0.5](https://github.com/izzzzzi/opencode-gemini-business/compare/v2.0.4...v2.0.5) (2026-02-15)
|
|
2
21
|
|
|
3
22
|
|
package/README.en.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# π opencode-gemini-business
|
|
4
|
+
|
|
5
|
+
**Multi-account Gemini Business pool with intelligent rotation for OpenCode**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/opencode-gemini-business)
|
|
8
|
+
[](https://www.npmjs.com/package/opencode-gemini-business)
|
|
9
|
+
[](https://github.com/izzzzzi/opencode-gemini-business/releases)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://www.typescriptlang.org/)
|
|
12
|
+
[](https://nodejs.org/)
|
|
13
|
+
|
|
14
|
+
[π·πΊ Π ΡΡΡΠΊΠΈΠΉ](README.md) | **π¬π§ English**
|
|
15
|
+
|
|
16
|
+
<br />
|
|
17
|
+
|
|
18
|
+
*Auth plugin for [OpenCode](https://github.com/anomalyco/opencode) β pool multiple Gemini Business accounts with automatic rotation, failover, and load balancing.*
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## π Overview
|
|
25
|
+
|
|
26
|
+
**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.
|
|
27
|
+
|
|
28
|
+
> **Important**: This plugin uses the **Gemini Business / Enterprise API**, NOT Google AI Studio.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## β¨ Features
|
|
33
|
+
|
|
34
|
+
| Feature | Description |
|
|
35
|
+
|---------|-------------|
|
|
36
|
+
| π **Multi-Account Rotation** | Automatically rotate between multiple Gemini Business accounts |
|
|
37
|
+
| π‘οΈ **Automatic Failover** | Retry failed requests with different accounts seamlessly |
|
|
38
|
+
| π **JWT Authentication** | Built-in XSRF token retrieval and JWT (HS256) signing |
|
|
39
|
+
| π‘ **Streaming Support** | Full SSE streaming, JSON-lines, and fallback parsing |
|
|
40
|
+
| βοΈ **Flexible Strategies** | Round-robin, least-used, or random rotation |
|
|
41
|
+
| π **Auto Auth Setup** | `add-account` automatically creates OpenCode auth record |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## π€ Supported Models
|
|
46
|
+
|
|
47
|
+
| Model | Internal API ID | Best For |
|
|
48
|
+
|-------|:---------------:|---------|
|
|
49
|
+
| `gemini-2.5-flash` | `gemini-2.5-flash` | Everyday tasks, fast responses |
|
|
50
|
+
| `gemini-2.5-pro` | `gemini-2.5-pro` | Complex reasoning |
|
|
51
|
+
| `gemini-3-flash` | `gemini-3-flash-preview` | Next-gen fast model |
|
|
52
|
+
| `gemini-3.1-pro` | `gemini-3.1-pro-preview` | Advanced reasoning (preview) |
|
|
53
|
+
| `auto` | *(empty)* | Gemini auto-selects the best model |
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## π Quick Start
|
|
58
|
+
|
|
59
|
+
### Step 1: Configure OpenCode
|
|
60
|
+
|
|
61
|
+
Add to `~/.config/opencode/opencode.json`:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"$schema": "https://opencode.ai/config.json",
|
|
66
|
+
"plugin": ["opencode-gemini-business@latest"],
|
|
67
|
+
"provider": {
|
|
68
|
+
"gemini-business": {
|
|
69
|
+
"name": "Gemini Business",
|
|
70
|
+
"options": {
|
|
71
|
+
"baseURL": "https://business.gemini.google/v1",
|
|
72
|
+
"apiKey": "unused"
|
|
73
|
+
},
|
|
74
|
+
"models": {
|
|
75
|
+
"gemini-2.5-flash": { "name": "Gemini 2.5 Flash" },
|
|
76
|
+
"gemini-2.5-pro": { "name": "Gemini 2.5 Pro" },
|
|
77
|
+
"gemini-3-flash": { "name": "Gemini 3 Flash" },
|
|
78
|
+
"gemini-3.1-pro": { "name": "Gemini 3.1 Pro" },
|
|
79
|
+
"auto": { "name": "Auto Select" }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Step 2: Add Gemini Business account
|
|
87
|
+
|
|
88
|
+
Install the CLI tool:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install -g opencode-gemini-business
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Then add your account (requires Google Chrome or Chromium):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
opencode-gemini-business add-account
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
A Chrome window will open β sign in to your Gemini Business account and send any message in the chat. Cookies and credentials are captured automatically. That's it!
|
|
101
|
+
|
|
102
|
+
> **Note:** `add-account` automatically creates the auth record in `~/.local/share/opencode/auth.json`, so you don't need to run `opencode auth login`.
|
|
103
|
+
|
|
104
|
+
<details>
|
|
105
|
+
<summary>Manual mode (advanced)</summary>
|
|
106
|
+
|
|
107
|
+
If you prefer to provide credentials manually or don't have Chrome installed:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
opencode-gemini-business add-account --manual \
|
|
111
|
+
"My Account" \
|
|
112
|
+
"e1f353e7-0291-44cf-9085-e0b6efd20e41" \
|
|
113
|
+
"CSE.AXUaAj_MKeqeFLr_..." \
|
|
114
|
+
"COS.AfQtEyCcW1aLwKb3..." \
|
|
115
|
+
"1370433092"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
| # | Argument | Description |
|
|
119
|
+
|:-:|----------|-------------|
|
|
120
|
+
| 1 | Account name | Display name for the account |
|
|
121
|
+
| 2 | `team_id` | UUID from URL `/cid/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/` |
|
|
122
|
+
| 3 | `__Secure-C_SES` | Cookie value (starts with `CSE.`) |
|
|
123
|
+
| 4 | `__Host-C_OSES` | Cookie value (starts with `COS.`) |
|
|
124
|
+
| 5 | `csesidx` | Number from URL `?csesidx=...` |
|
|
125
|
+
|
|
126
|
+
Or use environment variables:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
export GEMINI_ACCOUNT_NAME="My Account"
|
|
130
|
+
export GEMINI_TEAM_ID="e1f353e7-0291-44cf-9085-e0b6efd20e41"
|
|
131
|
+
export GEMINI_SECURE_C_SES="CSE.AXUaAj_MKeqeFLr_..."
|
|
132
|
+
export GEMINI_HOST_C_OSES="COS.AfQtEyCcW1aLwKb3..."
|
|
133
|
+
export GEMINI_CSESIDX="1370433092"
|
|
134
|
+
|
|
135
|
+
opencode-gemini-business add-account --manual
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
</details>
|
|
139
|
+
|
|
140
|
+
### Step 3: Use it
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Flash model (fast)
|
|
144
|
+
opencode run --model=gemini-business/gemini-2.5-flash "Fix this bug"
|
|
145
|
+
|
|
146
|
+
# Pro model (best quality)
|
|
147
|
+
opencode run --model=gemini-business/gemini-2.5-pro "Design architecture"
|
|
148
|
+
|
|
149
|
+
# Next-gen models
|
|
150
|
+
opencode run --model=gemini-business/gemini-3-flash "Quick task"
|
|
151
|
+
opencode run --model=gemini-business/gemini-3.1-pro "Advanced reasoning"
|
|
152
|
+
opencode run --model=gemini-business/auto "Let Gemini choose"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Set as default model in `opencode.json`:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"model": "gemini-business/gemini-2.5-flash"
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## π Extracting Credentials
|
|
166
|
+
|
|
167
|
+
### Where to find each value
|
|
168
|
+
|
|
169
|
+
Login to [business.gemini.google](https://business.gemini.google) and look at the URL:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
https://business.gemini.google/home/cid/e1f353e7-0291-44cf-9085-e0b6efd20e41/r/session/123?csesidx=1370433092
|
|
173
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
|
|
174
|
+
team_id (UUID after /cid/) csesidx
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Cookies
|
|
178
|
+
|
|
179
|
+
**Method 1: Browser Extension (Recommended)**
|
|
180
|
+
|
|
181
|
+
1. Install [Get cookies.txt LOCALLY](https://chromewebstore.google.com/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc)
|
|
182
|
+
2. Open `business.gemini.google` and export cookies
|
|
183
|
+
3. Find `__Secure-C_SES` (starts with `CSE.`) and `__Host-C_OSES` (starts with `COS.`)
|
|
184
|
+
|
|
185
|
+
**Method 2: DevTools**
|
|
186
|
+
|
|
187
|
+
1. Open DevTools (F12) β **Application** β **Cookies** β `https://business.gemini.google`
|
|
188
|
+
2. Copy `__Secure-C_SES` and `__Host-C_OSES` values
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## π§ Account Management
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# List all accounts
|
|
196
|
+
opencode-gemini-business list-accounts
|
|
197
|
+
|
|
198
|
+
# Test account connectivity
|
|
199
|
+
opencode-gemini-business test-account <account_id>
|
|
200
|
+
|
|
201
|
+
# Remove account
|
|
202
|
+
opencode-gemini-business remove-account <account_id>
|
|
203
|
+
|
|
204
|
+
# Help
|
|
205
|
+
opencode-gemini-business help
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## βοΈ Rotation Strategies
|
|
211
|
+
|
|
212
|
+
| Strategy | Behavior |
|
|
213
|
+
|----------|----------|
|
|
214
|
+
| `round-robin` (default) | Cycles through accounts in order |
|
|
215
|
+
| `least-used` | Selects least recently used account |
|
|
216
|
+
| `random` | Random selection |
|
|
217
|
+
|
|
218
|
+
Configure in `~/.config/opencode/gemini-business-accounts.json` (auto-created on first `add-account`).
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## π οΈ How It Works
|
|
223
|
+
|
|
224
|
+
1. Plugin registers as an OpenCode auth provider for `gemini-business`
|
|
225
|
+
2. When a request comes in, `loader()` returns a custom `fetch()` function
|
|
226
|
+
3. Custom `fetch()` intercepts the request from `@ai-sdk/openai-compatible`
|
|
227
|
+
4. Instead of calling `baseURL/chat/completions`, it:
|
|
228
|
+
- Picks an account via rotation strategy
|
|
229
|
+
- Gets XSRF token and creates JWT (HS256)
|
|
230
|
+
- Creates a session via `widgetCreateSession`
|
|
231
|
+
- Sends the actual request to `widgetStreamAssist`
|
|
232
|
+
- Converts the response back to OpenAI-compatible format
|
|
233
|
+
5. Supports both streaming (SSE) and non-streaming responses
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## β FAQ
|
|
238
|
+
|
|
239
|
+
<details>
|
|
240
|
+
<summary><b>Q: Where do I find team_id?</b></summary>
|
|
241
|
+
|
|
242
|
+
Look at the URL in your browser: `https://business.gemini.google/home/cid/e1f353e7-0291-44cf-9085-e0b6efd20e41/...`
|
|
243
|
+
|
|
244
|
+
The UUID after `/cid/` is your `team_id`.
|
|
245
|
+
</details>
|
|
246
|
+
|
|
247
|
+
<details>
|
|
248
|
+
<summary><b>Q: Do I need to run `opencode auth login`?</b></summary>
|
|
249
|
+
|
|
250
|
+
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`).
|
|
251
|
+
</details>
|
|
252
|
+
|
|
253
|
+
<details>
|
|
254
|
+
<summary><b>Q: Session expired errors?</b></summary>
|
|
255
|
+
|
|
256
|
+
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.
|
|
257
|
+
</details>
|
|
258
|
+
|
|
259
|
+
<details>
|
|
260
|
+
<summary><b>Q: Difference from Google AI Studio?</b></summary>
|
|
261
|
+
|
|
262
|
+
This plugin uses **Gemini Business API** (`business.gemini.google`) β enterprise accounts with higher rate limits. NOT Google AI Studio (`aistudio.google.com`).
|
|
263
|
+
</details>
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## π Security
|
|
268
|
+
|
|
269
|
+
- Credentials are stored locally in `~/.config/opencode/gemini-business-accounts.json`
|
|
270
|
+
- Never commit credentials to git
|
|
271
|
+
- Rotate cookies regularly
|
|
272
|
+
- The plugin does not send credentials to any third-party services
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## π License
|
|
277
|
+
|
|
278
|
+
[MIT](LICENSE) Β© opencode-gemini-business contributors
|