opencode-multi-openai-auth
v1.0.0
Published
OpenAI OAuth multi-account plugin for Opencode - login to multiple OpenAI accounts and auto-rotate on rate limits
Downloads
100
Maintainers
Readme
OpenAI Multi-Account OAuth Plugin for OpenCode
Enable OpenCode to authenticate against OpenAI via OAuth with multi-account support. Automatically rotates between accounts when rate-limited to maximize your usage.
What You Get
- OpenAI OAuth Authentication — Use your OpenAI ChatGPT account credentials
- Multi-account support — Add multiple OpenAI accounts, auto-rotates when rate-limited
- Smart account selection — Multiple strategies: sticky, round-robin, or hybrid
- Rate limit handling — Automatic backoff and recovery
- Health-based routing — Prioritize accounts with better performance history
- GPT-5.x Support — Works with GPT-5.2, GPT-5.2 Codex, GPT-5.1 Codex Max and more
[!CAUTION] Using this plugin may violate OpenAI's Terms of Service. By using this plugin, you acknowledge:
- This is an unofficial tool not endorsed by OpenAI
- Your account may be suspended or rate-limited
- You assume all risks associated with using this plugin
Recommendation: Use responsibly and respect OpenAI's usage policies.
Installation
Option A: Let an LLM do it
Paste this into any LLM agent (Claude Code, OpenCode, Cursor, etc.):
Install the opencode-multi-openai-auth plugin and configure OpenAI models by following: https://raw.githubusercontent.com/MoYeRanqianzhi/opencode-multi-openai-auth/main/README.mdOption B: Manual setup
Add the plugin to
~/.config/opencode/opencode.json:{ "plugin": ["opencode-multi-openai-auth@latest"] }Add OpenAI provider and models — copy the full configuration below
Login with your OpenAI account:
opencode auth loginSelect "OpenAI OAuth (Multi-Account)" when prompted.
Use it:
opencode run "Hello" --model=openai/gpt-5.2
Step-by-Step Instructions
Edit the OpenCode configuration file at
~/.config/opencode/opencode.jsonNote: This path works on all platforms. On Windows,
~resolves to your user home directory (e.g.,C:\Users\YourName).Add the plugin to the
pluginarrayAdd the model definitions from the Full models configuration section
Set
providerto"openai"and choose a model
Verification
opencode run "Hello" --model=openai/gpt-5.2 --variant=mediumModels
Model Reference
| Model | Variants | Notes |
|-------|----------|-------|
| gpt-5.2 | none, low, medium, high, xhigh | GPT-5.2 with reasoning |
| gpt-5.2-codex | low, medium, high, xhigh | GPT-5.2 Codex optimized for coding |
| gpt-5.1-codex-max | low, medium, high, xhigh | GPT-5.1 Codex Max for complex tasks |
Using variants:
opencode run "Hello" --model=openai/gpt-5.2-codex --variant=xhighAdd this to your ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-multi-openai-auth@latest"],
"provider": {
"openai": {
"name": "OpenAI",
"options": {
"reasoningEffort": "medium",
"reasoningSummary": "auto",
"textVerbosity": "medium",
"include": ["reasoning.encrypted_content"],
"store": false
},
"models": {
"gpt-5.2": {
"name": "GPT 5.2 (OAuth)",
"limit": { "context": 272000, "output": 128000 },
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"variants": {
"none": {
"reasoningEffort": "none",
"reasoningSummary": "auto",
"textVerbosity": "medium"
},
"low": {
"reasoningEffort": "low",
"reasoningSummary": "auto",
"textVerbosity": "medium"
},
"medium": {
"reasoningEffort": "medium",
"reasoningSummary": "auto",
"textVerbosity": "medium"
},
"high": {
"reasoningEffort": "high",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
},
"xhigh": {
"reasoningEffort": "xhigh",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
}
}
},
"gpt-5.2-codex": {
"name": "GPT 5.2 Codex (OAuth)",
"limit": { "context": 272000, "output": 128000 },
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"variants": {
"low": {
"reasoningEffort": "low",
"reasoningSummary": "auto",
"textVerbosity": "medium"
},
"medium": {
"reasoningEffort": "medium",
"reasoningSummary": "auto",
"textVerbosity": "medium"
},
"high": {
"reasoningEffort": "high",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
},
"xhigh": {
"reasoningEffort": "xhigh",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
}
}
},
"gpt-5.1-codex-max": {
"name": "GPT 5.1 Codex Max (OAuth)",
"limit": { "context": 272000, "output": 128000 },
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"variants": {
"low": {
"reasoningEffort": "low",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
},
"medium": {
"reasoningEffort": "medium",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
},
"high": {
"reasoningEffort": "high",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
},
"xhigh": {
"reasoningEffort": "xhigh",
"reasoningSummary": "detailed",
"textVerbosity": "medium"
}
}
}
}
}
}
}Multi-Account Setup
Add multiple OpenAI accounts for higher combined quotas. The plugin automatically rotates between accounts when one is rate-limited.
opencode auth login # Run again to add more accountsHow It Works
- Each account's rate limit status is tracked independently
- When one account hits a rate limit, the plugin automatically switches to the next available account
- Accounts recover after their rate limit window expires
- Health scores track account reliability for optimal routing
Account Selection Strategies
| Strategy | Description | Best For |
|----------|-------------|----------|
| sticky | Stay on current account until rate-limited | Single account usage |
| round-robin | Rotate through accounts on each request | Even distribution |
| hybrid | Health + token bucket based selection | Multiple accounts (default) |
Configuration
Create ~/.config/opencode/openai-multi-auth.json for optional settings:
{
"account_selection_strategy": "hybrid",
"switch_on_first_rate_limit": true,
"max_rate_limit_wait_seconds": 300,
"quiet_mode": false,
"pid_offset_enabled": false
}Configuration Options
| Option | Default | Description |
|--------|---------|-------------|
| account_selection_strategy | "hybrid" | How to select accounts: sticky, round-robin, hybrid |
| switch_on_first_rate_limit | true | Switch to next account immediately on rate limit |
| max_rate_limit_wait_seconds | 300 | Maximum seconds to wait for rate limit recovery |
| quiet_mode | false | Hide toast notifications about account switching |
| pid_offset_enabled | false | Offset account selection by process ID (for parallel agents) |
Health Score Configuration
Fine-tune the health-based account selection:
{
"health_score": {
"initial": 70,
"success_reward": 1,
"rate_limit_penalty": -10,
"failure_penalty": -20,
"recovery_rate_per_hour": 2,
"min_usable": 50,
"max_score": 100
}
}Token Bucket Configuration
Control request rate limiting per account:
{
"token_bucket": {
"max_tokens": 50,
"regeneration_rate_per_minute": 6,
"initial_tokens": 50
}
}Configuration Paths
| File | Path |
|------|------|
| Main config | ~/.config/opencode/opencode.json |
| Accounts | ~/.config/opencode/openai-accounts.json |
| Plugin config | ~/.config/opencode/openai-multi-auth.json |
Windows users:
~resolves to your user home directory (e.g.,C:\Users\YourName). On Windows, the config directory is%APPDATA%\opencode\.
Troubleshooting
Quick Reset: Most issues can be resolved by deleting
~/.config/opencode/openai-accounts.jsonand runningopencode auth loginagain.
Multi-Account Auth Issues
If you encounter authentication issues with multiple accounts:
- Delete the accounts file:
rm ~/.config/opencode/openai-accounts.json - Re-authenticate:
opencode auth login
"All Accounts Rate-Limited"
- Wait for rate limit window to expire (usually 60 seconds)
- Add more accounts to increase throughput
- Check if
max_rate_limit_wait_secondsis set too low
OAuth Callback Issues
macOS / Linux:
lsof -i :51120
kill -9 <PID>
opencode auth loginWindows (PowerShell):
netstat -ano | findstr :51120
taskkill /PID <PID> /F
opencode auth loginIf the browser doesn't open automatically:
- Copy the OAuth URL from the terminal
- Paste it into your browser manually
- Complete the login process
Using with oh-my-opencode
When using with oh-my-opencode, you can configure agents to use OpenAI models:
// ~/.config/opencode/oh-my-opencode.json
{
"agents": {
"oracle": { "model": "openai/gpt-5.2" },
"explore": { "model": "openai/gpt-5.2-codex" }
}
}Tip: When spawning parallel subagents, enable
pid_offset_enabled: truein plugin config to distribute sessions across accounts.
Environment Variables
OPENCODE_OPENAI_DEBUG=1 opencode # Enable debug logging
OPENCODE_OPENAI_DEBUG=2 opencode # Verbose loggingGitHub Actions Auto-Publish
This project uses GitHub Actions for automatic npm publishing:
- CI Workflow (
ci.yml): Runs on every push and PR, tests on Node.js 18/20/22 - Publish Workflow (
npm-publish.yml): Publishes to npm on version tags or manual trigger
Setup for Your Fork
- Get an NPM access token from npmjs.com
- Add it as a GitHub secret named
NPM_TOKEN - Push a version tag to trigger publish:
git tag v1.0.0 && git push --tags
Development
git clone https://github.com/MoYeRanqianzhi/opencode-multi-openai-auth.git
cd opencode-multi-openai-auth
npm install # Install dependencies
npm run build # Build TypeScript
npm test # Run tests (46 tests)
npm run typecheck # Type checkAPI Reference
Exported Functions
import { createOpenAIMultiAuthPlugin, AccountManager } from 'opencode-multi-openai-auth';
// Create the plugin
const plugin = createOpenAIMultiAuthPlugin();
// Or with custom provider ID
const plugin = createOpenAIMultiAuthPlugin('custom-openai');AccountManager
The AccountManager class handles multi-account state:
const manager = await AccountManager.loadFromDisk(authDetails);
const count = manager.getAccountCount();
const current = manager.getCurrentAccount();Credits
- Inspired by opencode-antigravity-auth
- Uses OpenAI's OAuth implementation from opencode
License
MIT License. See LICENSE for details.
Intended Use
- Personal / internal development only
- Respect OpenAI's quotas and usage policies
- Not for production services or bypassing intended limits
Warning
By using this plugin, you acknowledge:
- Terms of Service risk — This approach may violate ToS of OpenAI
- Account risk — OpenAI may suspend or rate-limit accounts
- No guarantees — APIs may change without notice
- Assumption of risk — You assume all legal, financial, and technical risks
Disclaimer
- Not affiliated with OpenAI. This is an independent open-source project.
- "OpenAI", "ChatGPT", and "GPT" are trademarks of OpenAI, Inc.
