@melodyoftears/opencode-qwen-authQwen OAuth authentication plugin for OpenCode - Access Qwen AI models (Coder, Vision) with your qwen.ai account
9
89
19 in 7 days
30.9
Multi-signal model
5 months ago
2026-03-01
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@melodyoftears/opencode-qwen-auth@1.3.7"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@melodyoftears/opencode-qwen-auth@1.3.7"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D @melodyoftears/opencode-qwen-authopencode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
Authenticate OpenCode CLI with your qwen.ai account using OAuth Device Flow. This plugin enables you to use Qwen AI models (coder-model and vision-model) with free daily quota - no API key or credit card required.
Features
- OAuth Device Flow (RFC 8628) - Secure browser-based authentication
- PKCE support (RFC 7636) - Enhanced security for public clients
- Automatic polling - Detects authorization completion without manual input
- Auto-refresh tokens - Renewed automatically before expiration
- Compatible with qwen-code - Reuses credentials from
~/.qwen/oauth_creds.json - Free tier - 2,000 requests per day via OAuth
Prerequisites
- OpenCode CLI installed
- A qwen.ai account (free to create)
Installation
1. Install the plugin
cd ~/.opencode && npm install @melodyoftears/opencode-qwen-auth
2. Enable the plugin
Edit ~/.opencode/opencode.jsonc:
{
"plugin": ["@melodyoftears/opencode-qwen-auth"]
}
Usage
1. Login
opencode auth login
2. Select Provider
Choose "Other" and type qwen-code
3. Authenticate
Select "Qwen Code (qwen.ai OAuth)"
- A browser window opens automatically for authorization
- The plugin polls and detects when you complete authorization
- No need to copy/paste codes or press Enter
Available Models
| Model | ID | Input | Output | Context | Max Output |
|---|---|---|---|---|---|
| Qwen Coder (Qwen 3.5 Plus) | coder-model |
text | text | 1M tokens | 65,536 tokens |
| Qwen VL Plus (Vision) | vision-model |
text, image | text | 128K tokens | 8,192 tokens |
Using a specific model
opencode --provider qwen-code --model coder-model
opencode --provider qwen-code --model vision-model
How It Works
- Device Flow: Opens your browser to
chat.qwen.aifor authentication - Automatic Polling: Detects authorization completion automatically
- Token Storage: Saves credentials to
~/.qwen/oauth_creds.json - Auto-refresh: Renews tokens 30 seconds before expiration
Usage Limits
| Plan | Rate Limit | Daily Limit |
|---|---|---|
| Free (OAuth) | 60 req/min | 2,000 req/day |
Limits reset at midnight UTC.
Troubleshooting
Token expired
The plugin automatically renews tokens. If issues persist:
# Remove old credentials
rm ~/.qwen/oauth_creds.json
# Re-authenticate
opencode auth login
Provider not showing in auth login
The qwen-code provider is added via plugin. In the opencode auth login command:
- Select "Other"
- Type
qwen-code
Rate limit exceeded (429 errors)
- Wait until midnight UTC for quota reset
- Switch to another Qwen account and login again if quota is exhausted
Development
# Clone the repository
git clone https://github.com/1579364808/opencode-qwen-auth.git
cd opencode-qwencode-auth
# Install dependencies
bun install
# Build
bun run build
# Type check
bun run typecheck
Local testing
Edit ~/.opencode/package.json:
{
"dependencies": {
"@melodyoftears/opencode-qwen-auth": "file:///absolute/path/to/opencode-qwencode-auth"
}
}
Then reinstall:
cd ~/.opencode && npm install
Project Structure
src/
├── constants.ts # OAuth endpoints, models config
├── types.ts # TypeScript interfaces
├── index.ts # Main plugin entry point
├── cli.ts # CLI helper for manual auth
├── qwen/
│ └── oauth.ts # OAuth Device Flow + PKCE
├── plugin/
│ ├── auth.ts # Credentials management
│ └── utils.ts # Helper utilities
└── errors.ts # Error handling
Related Projects
Links
Support
If this project helps you, you can buy me a coffee:
License
MIT