---
slug: "pi-gemini-oauth-apikey"
source_type: "readme"
source_url: "https://cdn.jsdelivr.net/gh/vforvaick/pi-gemini-oauth-apikey@master/README.md"
repo: "https://github.com/vforvaick/pi-gemini-oauth-apikey"
source_file: "README.md"
branch: "master"
---
# pi-gemini-oauth-apikey

Multi-account **Google Cloud Code Assist (Gemini CLI) OAuth rotation pool** for
[pi](https://pi.dev). Register N Google accounts as separate providers and
auto-rotate on 429/`RESOURCE_EXHAUSTED` — get ~N × 1500 RPD of free Gemini quota.

Complements [`pi-key-pool`](https://github.com/ssdiwu/pi-key-pool) (which rotates
**API keys**): this package rotates **OAuth accounts** (Code Assist tier,
~6× the per-account RPD, separate quota bucket).

## What it does

- Registers `gemini-pool-1` … `gemini-pool-N` as OAuth providers
- Each is independently loggable via `/login`
- On a 429/rate-limit error, marks the current account exhausted, switches to
  the next available one, and **replays your last message automatically**
- Time-based cooldown recovery (quota 60s, capacity 30s, network skipped)

## Why

`pi-multi-pass` supports multi-account OAuth rotation but its Gemini login
(`loginGeminiCli`) was removed from upstream pi, so `/subs login google-gemini-cli-N`
throws `is not a function`. This package reuses
[`@qraxiss/pi-gemini-auth`](https://github.com/qraxiss/pi-gemini-auth) (which
restored that OAuth flow as a standalone package) for the login/provider
implementation, and adds the rotation layer on top. No pi-core patching.

## Install

```bash
pi install npm:pi-gemini-oauth-apikey
```

Then restart pi. (You can now uninstall `@qraxiss/pi-gemini-auth` as an active
extension — this package depends on it as a library instead.)

## Configure

Optional. Edit `~/.pi/agent/gemini-pool.json` (defaults to 4 slots if absent):

```json
{
  "accounts": [
    { "id": "1", "label": "Work Pro" },
    { "id": "2", "label": "Personal Pro" },
    { "id": "3", "label": "Side Pro" },
    { "id": "4", "label": "Backup Pro" }
  ],
  "cooldown": { "quota": 60000, "capacity": 30000, "network": 0 }
}
```

## Login each account

```
/login        → pick "Gemini Pool 1" → browser OAuth (account 1)
/login        → pick "Gemini Pool 2" → account 2
... (repeat per account)
/model gemini-pool-1/gemini-2.5-flash
```

That's it. When `gemini-pool-1` hits a 429, the turn transparently retries on
`gemini-pool-2`, and so on. When all are exhausted you get a warning and a
cooldown timer.

## How it works

```
before_agent_start  →  remember last user prompt
agent_end           →  if stopReason=="error" && isRateLimit(msg):
                         markExhausted(current); pickNext() → setModel + sendUserMessage
```

`failover.ts` is a pure, unit-tested state machine (round-robin + cooldown +
auth-gated availability). Provider/OAuth/streaming come from qraxiss.

## Tests

```bash
node --test --experimental-strip-types test/*.test.ts
```

Stdlib only (`node:test`) — no test dependencies.

## License

MIT
