pi-multi-account 1.0.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 +27 -0
- package/LICENSE +21 -0
- package/README.md +107 -0
- package/index.ts +1184 -0
- package/package.json +69 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2026-06-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial public release.
|
|
13
|
+
- Automatic multi-account failover & rotation across Anthropic (Claude),
|
|
14
|
+
OpenAI / ChatGPT Codex, and Qwen / Alibaba.
|
|
15
|
+
- Auto-discovery of authenticated accounts from `~/.pi/agent/auth.json`; the
|
|
16
|
+
rotation grows on login and drops accounts on logout, token expiry, or
|
|
17
|
+
authorization errors.
|
|
18
|
+
- Quota / rate-limit failover with provider-reset-aware cooldowns and circular
|
|
19
|
+
fallback ordering.
|
|
20
|
+
- Optional auto-continue of the interrupted task after a switch.
|
|
21
|
+
- Thinking-level preservation across model switches.
|
|
22
|
+
- Commands `/multi-account`, `/provider-failover`, `/failover` with
|
|
23
|
+
`status | rediscover | add | next | reset | reload | enable | disable`.
|
|
24
|
+
- Plaintext-free credential handling (SHA-256 fingerprints only); `0600`
|
|
25
|
+
config/state files.
|
|
26
|
+
|
|
27
|
+
[1.0.0]: https://github.com/Sarrius/pi-multi-account/releases/tag/v1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pi-multi-account contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# pi-multi-account
|
|
2
|
+
|
|
3
|
+
Automatic multi-account failover & rotation for [Pi Agent](https://pi.dev/), across **Anthropic (Claude)**, **OpenAI / ChatGPT Codex**, and **Qwen / Alibaba**.
|
|
4
|
+
|
|
5
|
+
When the account you are using hits a quota or rate limit, `pi-multi-account` transparently switches to the next authenticated account/model and (optionally) resumes the interrupted task — so a long agent run does not die just because one account ran out of budget.
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
- **Auto-discovers** every authenticated account from `~/.pi/agent/auth.json` (Anthropic Claude Pro/Max, OpenAI/ChatGPT Codex, and Qwen/Alibaba) and builds the failover rotation dynamically — no manual config editing.
|
|
10
|
+
- **Grows the rotation on login.** Run `/login anthropic-account-3` (or `openai-codex-account-5`) to add an account; the next discovery sweep adds it to the rotation automatically. A spare login slot per family is pre-registered so `/login <id>` works out of the box.
|
|
11
|
+
- **Drops accounts automatically** the moment their token is expired, revoked, logged out, or returns an auth error — and restores them automatically once you re-login.
|
|
12
|
+
- **Fails over on quota / rate-limit** (429 / 402 / 403 and friends): the exhausted account goes on cooldown (parsed from the provider's own reset metadata when available) and Pi switches to the next available account/model.
|
|
13
|
+
- **Optional auto-continue**: queues a safe continuation prompt after a switch so the agent keeps going from the last safe point.
|
|
14
|
+
- **Keeps your thinking level** stable across switches instead of letting it drift downward.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pi install npm:pi-multi-account
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Restart Pi or run `/reload` after installation.
|
|
23
|
+
|
|
24
|
+
> **Anthropic OAuth aliases** (`anthropic-account-2`, …) require [`@gotgenes/pi-anthropic-auth`](https://www.npmjs.com/package/@gotgenes/pi-anthropic-auth) for request shaping. The base `anthropic` provider and all OpenAI Codex / Qwen accounts work without it.
|
|
25
|
+
|
|
26
|
+
### Recommended setting
|
|
27
|
+
|
|
28
|
+
Set Pi provider-level retries to zero so the SDK does not keep retrying an exhausted account before failover kicks in. In `~/.pi/agent/settings.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{ "retry": { "provider": { "maxRetries": 0 } } }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Add accounts by logging into numbered slots, then let discovery pick them up:
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
/login anthropic-account-2
|
|
40
|
+
/login openai-codex-account-2
|
|
41
|
+
/multi-account rediscover
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Check what's in the rotation at any time:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
/multi-account status
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Example status output:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
pi-multi-account: enabled · auto-discover ON
|
|
54
|
+
Current: anthropic/claude-opus-4-8
|
|
55
|
+
Rotation (3): anthropic → openai-codex → openai-codex-account-2
|
|
56
|
+
Registered login slots: anthropic-account-2, openai-codex-account-2
|
|
57
|
+
Cooldowns: none
|
|
58
|
+
Invalidated (need re-login): none
|
|
59
|
+
Pending auto-resume: none
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Commands
|
|
63
|
+
|
|
64
|
+
All three names are aliases for the same command: `/multi-account`, `/provider-failover`, `/failover`.
|
|
65
|
+
|
|
66
|
+
| Subcommand | Description |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `status` (default) | Show enabled state, current model, rotation, login slots, cooldowns, invalidations, pending resume. |
|
|
69
|
+
| `rediscover` | Force a re-scan of `auth.json` and rebuild the rotation now. |
|
|
70
|
+
| `add [anthropic\|codex]` | Print the next free login slot id to use with `/login`. |
|
|
71
|
+
| `next` | Manually switch to the next available fallback. |
|
|
72
|
+
| `reset` | Clear all cooldowns, invalidations and any pending auto-resume. |
|
|
73
|
+
| `reload` | Reload config from disk and re-discover accounts. |
|
|
74
|
+
| `enable` / `disable` | Turn failover on/off for the current Pi process. |
|
|
75
|
+
|
|
76
|
+
## How rotation membership works
|
|
77
|
+
|
|
78
|
+
- **Joins the rotation** when an account has a present, non-expired credential in `auth.json` (after `/login`).
|
|
79
|
+
- **Leaves the rotation** when the credential is logged out / removed, its access token is expired with no refresh token, or it returns an authorization error (HTTP 401, `invalid_token`, `revoked`, …) during use. Such accounts are marked *invalidated (need re-login)* and skipped until you log in again.
|
|
80
|
+
- **Quota / rate-limit** does not invalidate an account — it puts it on a temporary cooldown and the account returns once the cooldown expires.
|
|
81
|
+
|
|
82
|
+
Rotation refresh is triggered by changes to `auth.json` (detected on session/turn start) or on demand with `/multi-account rediscover`.
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
A default config is created at `~/.pi/agent/provider-failover.json` on first run. Useful keys:
|
|
87
|
+
|
|
88
|
+
| Key | Default | Description |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| `enabled` | `true` | Master switch. |
|
|
91
|
+
| `autoContinue` | `true` | Queue a continuation prompt after a switch. |
|
|
92
|
+
| `autoDiscover` | `true` | Auto-discover accounts from `auth.json`. |
|
|
93
|
+
| `includeQwen` | `true` | Include Qwen / Alibaba accounts. |
|
|
94
|
+
| `providerOrder` | `["anthropic","openai-codex","qwen"]` | Preferred family order in the rotation. |
|
|
95
|
+
| `cooldownMs` | 6 h | Default cooldown when no reset metadata is provided. |
|
|
96
|
+
| `maxAutoContinuesPerPrompt` | `8` | Cap on auto-resume hops per task. |
|
|
97
|
+
| `continuationPrompt` | (built-in) | Template; supports `{from}`, `{to}`, `{reason}`. |
|
|
98
|
+
|
|
99
|
+
State (cooldowns, invalidations, recent switches) is persisted to `~/.pi/agent/provider-failover-state.json`.
|
|
100
|
+
|
|
101
|
+
## Privacy & security
|
|
102
|
+
|
|
103
|
+
`pi-multi-account` **reads** `auth.json` but never writes to it and never stores credentials in plaintext. Account/token values are only ever reduced to a short irreversible SHA-256 fingerprint, used solely to detect re-login and deduplicate the same real account logged into multiple slots. The extension makes no network calls of its own — token exchange happens exclusively through Pi's official OAuth providers. Config and state files are written with `0600` permissions.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
[MIT](./LICENSE)
|