@melodyoftears/opencode-qwen-authQwen OAuth authentication plugin for OpenCode - Access Qwen AI models (Coder, Vision) with your qwen.ai account
9
89
近 7 天 19
30.9
生态多维模型
5 个月前
2026-03-01
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@melodyoftears/opencode-qwen-auth@1.3.7"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@melodyoftears/opencode-qwen-auth@1.3.7"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @melodyoftears/opencode-qwen-authopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
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