OpenCode plugin for Qwen Code OAuth authentication. Provides free access to Qwen Coder models through the official OAuth flow.
- OAuth Device Flow - Secure authentication via browser
- Multi-Account Support - Use multiple Qwen accounts for higher rate limits
- Smart Rotation - Automatic account rotation with health-based selection
- Rate Limit Handling - Automatic retry with exponential backoff
- Token Refresh - Automatic token refresh before expiration
Add to your OpenCode config (~/.config/opencode/opencode.json):
{
"plugin": ["@dvaji/opencode-qwen-auth"]
}OpenCode will automatically install and load the plugin at startup.
{
"plugin": ["@dvaji/opencode-qwen-auth@git+https://github.com/dvaJi/opencode-qwencode-auth.git"]
}# Clone the repository
git clone https://github.com/dvaJi/opencode-qwencode-auth.git
cd opencode-qwencode-auth
# Install dependencies
bun install- Rate Limit: 60 requests per minute
- Daily Quota: ~2000 requests per day (reset at midnight UTC)
Note: These limits are set by the Qwen OAuth API and may change.
The plugin uses Qwen OAuth (free tier). When you first use it with OpenCode, you'll be prompted to authenticate via browser.
# Authenticate
opencode auth login
# Use the model
opencode --provider qwen-code --model coder-modelIf the automatic flow doesn't work (e.g., in containers), you can use the CLI helper:
bun run src/cli.tsConfiguration is stored in ~/.config/opencode/qwen-auth.json (Linux/macOS) or %APPDATA%/opencode/qwen-auth.json (Windows).
{
"rotation_strategy": "round-robin",
"proactive_refresh": true,
"refresh_window_seconds": 300,
"max_rate_limit_wait_seconds": 300,
"quiet_mode": false,
"pid_offset_enabled": false,
"health_score": {
"initial": 70,
"min_usable": 50,
"success_reward": 1,
"failure_penalty": 20,
"recovery_rate_per_hour": 2
},
"token_bucket": {
"max_tokens": 50,
"regeneration_rate_per_minute": 6
}
}| Strategy | Description |
|---|---|
round-robin |
Simple sequential selection |
sequential |
Use first available, skip rate-limited |
hybrid |
Health score + token bucket + freshness (recommended) |
| Option | Default | Description |
|---|---|---|
rotation_strategy |
round-robin |
Account selection strategy |
proactive_refresh |
true |
Refresh tokens before expiration |
refresh_window_seconds |
300 |
Seconds before expiry to refresh |
max_rate_limit_wait_seconds |
300 |
Max wait time for rate-limited accounts |
quiet_mode |
false |
Disable debug logging |
pid_offset_enabled |
false |
Distribute accounts across processes |
Qwen OAuth has ~2000 requests/day limit. To increase capacity, add multiple accounts:
- Authenticate with the first account through OpenCode
- The credentials are stored in
~/.config/opencode/qwen-accounts.json - Repeat authentication to add more accounts
The plugin will automatically distribute requests across accounts using the configured rotation strategy.
The plugin usually handles refresh automatically. If you see this error immediately:
- Re-authenticate: Run
opencode auth loginagain. - Clear cache: Delete the credentials file and login again:
rm ~/.config/opencode/qwen-accounts.json
opencode auth loginIf you hit the rate limits:
- Rate limit (60/min): Wait a few minutes before trying again
- Daily quota (~2000/day): Wait until midnight UTC for the quota to reset
If something isn't working, you can see detailed logs:
OPENCODE_QWEN_DEBUG=1 opencodebun testsrc/
├── plugin/
│ ├── account.ts # Multi-account management
│ ├── rotation.ts # Health score & token bucket
│ ├── config/ # Configuration loading
│ └── request-queue.ts # Rate limiting
├── qwen/
│ └── oauth.ts # OAuth device flow
├── constants.ts # Configuration constants
├── errors.ts # Error types
└── plugin.ts # Main plugin entry
- Qwen Code - Official OAuth implementation
- foxswat/opencode-qwen-auth - Reference implementation