Authenticate OpenCode CLI with your qwen.ai account. This plugin enables you to use Qwen models (Coder, Max, Plus and more) with 2,000 free requests per day - no API key or credit card required!
- 🔐 OAuth Device Flow - Secure browser-based authentication (RFC 8628)
- ⚡ Automatic Polling - No need to press Enter after authorizing
- 🆓 2,000 req/day free - Generous free tier with no credit card
- 🧠 1M context window - Models with 1 million token context
- 🔄 Auto-refresh - Tokens renewed automatically before expiration
- 🔗 qwen-code compatible - Reuses credentials from
~/.qwen/oauth_creds.json - 🌐 Multi-endpoint support - Automatically routes to portal.qwen.ai or DashScope based on your token
The plugin now automatically detects and uses the correct API endpoint based on the resource_url returned by the OAuth server:
| resource_url | API Endpoint | Region |
|---|---|---|
portal.qwen.ai |
https://portal.qwen.ai/v1 |
International |
dashscope |
https://dashscope.aliyuncs.com/compatible-mode/v1 |
China |
dashscope-intl |
https://dashscope-intl.aliyuncs.com/compatible-mode/v1 |
International |
This means the plugin works correctly regardless of which region your Qwen account is associated with.
When using DashScope endpoints, the plugin automatically injects the required headers:
X-DashScope-CacheControl: enableX-DashScope-UserAgent: opencode-qwencode-auth/1.4.0X-DashScope-AuthType: qwen-oauth
Fixed a critical bug where the loader was returning baseUrl instead of baseURL (capital letters), which caused ERR_INVALID_URL errors.
- OpenCode CLI installed
- A qwen.ai account (free to create)
From npm (recommended):
cd ~/.config/opencode && npm install opencode-qwencode-authOr with bun:
cd ~/.config/opencode && bun add opencode-qwencode-authFrom GitHub (latest unreleased changes):
cd ~/.config/opencode && npm install ishan-parihar/opencode-qwencode-auth
# or with bun
cd ~/.config/opencode && bun add ishan-parihar/opencode-qwencode-authEdit ~/.config/opencode/opencode.json:
{
"plugin": ["opencode-qwencode-auth"]
}opencode auth loginChoose "Other" and type qwen-code
Select "Qwen Code (qwen.ai OAuth)"
- A browser window will open for you to authorize
- The plugin automatically detects when you complete authorization
- No need to copy/paste codes or press Enter!
Tip
In the OpenCode TUI (graphical interface), the Qwen Code provider appears automatically in the provider list.
| Model | Context | Max Output | Best For |
|---|---|---|---|
qwen3-coder-plus |
1M tokens | 64K tokens | Complex coding tasks |
qwen3-coder-flash |
1M tokens | 64K tokens | Fast coding responses |
| Model | Context | Max Output | Description |
|---|---|---|---|
coder-model |
1M tokens | 64K tokens | Auto-routed coding model |
vision-model |
128K tokens | 32K tokens | Vision-language model (qwen3-vl-plus) |
opencode --provider qwen-code --model qwen3-coder-plus
opencode --provider qwen-code --model vision-model┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ OpenCode CLI │────▶│ qwen.ai OAuth │────▶│ Qwen Models │
│ │◀────│ (Device Flow) │◀────│ API │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- Device Flow (RFC 8628): Opens your browser to
chat.qwen.aifor authentication - Automatic Polling: Detects authorization completion automatically
- Token Storage: Saves credentials to
~/.qwen/oauth_creds.json - Dynamic URL Resolution: Uses
resource_urlfrom token to determine API endpoint - Auto-refresh: Renews tokens 60 seconds before expiration
The plugin supports multiple API endpoints:
| Endpoint | URL | Headers | Region |
|---|---|---|---|
| Portal | https://portal.qwen.ai/v1 |
Standard Bearer | International |
| DashScope | https://dashscope.aliyuncs.com/compatible-mode/v1 |
DashScope-specific | China |
| DashScope Intl | https://dashscope-intl.aliyuncs.com/compatible-mode/v1 |
DashScope-specific | International |
The correct endpoint is automatically selected based on your OAuth token's resource_url field.
| Plan | Rate Limit | Daily Limit |
|---|---|---|
| Free (OAuth) | 60 req/min | 2,000 req/day |
Note
Limits reset at midnight UTC. For higher limits, consider using an API key from DashScope.
This was a bug in versions before 1.4.0. Update to the latest version:
cd ~/.config/opencode && npm update opencode-qwencode-authThis happens when the wrong API endpoint is used. The v1.4.0 update fixes this by automatically detecting the correct endpoint from your token's resource_url.
The plugin automatically renews tokens. If issues persist:
# Remove old credentials
rm ~/.qwen/oauth_creds.json
# Re-authenticate
opencode auth loginThe qwen-code provider is added via plugin. In the opencode auth login command:
- Select "Other"
- Type
qwen-code
- Wait until midnight UTC for quota reset
- Try using
qwen3-coder-flashfor faster, lighter requests - Consider DashScope API for higher limits
Enable debug logging to see technical details:
export OPENCODE_QWEN_DEBUG=1
opencode# Clone the repository
git clone https://github.com/gustavodiasdev/opencode-qwencode-auth.git
cd opencode-qwencode-auth
# Install dependencies
bun install
# Type check
bun run typecheckEdit ~/.config/opencode/package.json:
{
"dependencies": {
"opencode-qwencode-auth": "file:///absolute/path/to/opencode-qwencode-auth"
}
}Then reinstall:
cd ~/.config/opencode && npm installsrc/
├── constants.ts # OAuth endpoints, API URLs, models config
├── types.ts # TypeScript interfaces
├── index.ts # Main plugin entry point
├── qwen/
│ └── oauth.ts # OAuth Device Flow + PKCE
└── plugin/
└── auth.ts # Credentials management + URL resolution
- qwen-code - Official Qwen coding CLI
- OpenCode - AI-powered CLI for development
- opencode-gemini-auth - Similar plugin for Google Gemini
MIT
Made with ❤️ for the OpenCode community
