1- # opencode-qwen-auth
1+ # 🤖 Qwen Code OAuth Plugin for OpenCode
22
3- OAuth authentication plugin for [ OpenCode CLI] ( https://opencode.ai ) that enables Qwen3-Coder models through your [ qwen.ai] ( https://chat.qwen.ai ) account with ** 2,000 free requests per day** .
3+ ![ License] ( https://img.shields.io/github/license/gustavodiasdev/opencode-qwen-auth )
4+ ![ GitHub stars] ( https://img.shields.io/github/stars/gustavodiasdev/opencode-qwen-auth )
45
5- [ Leia em Português ] ( ./README.pt-BR.md )
6+ ** Authenticate OpenCode CLI with your qwen.ai account. ** This plugin enables you to use Qwen3-Coder models with ** 2,000 free requests per day ** - no API key or credit card required!
67
7- ## Features
8+ [ 🇧🇷 Leia em Português ] ( ./README.pt-BR.md )
89
9- - ** OAuth Device Flow** - Secure browser-based authentication (RFC 8628)
10- - ** Automatic Polling** - Automatically detects when you authorize in the browser
11- - ** 2,000 req/day free** - No credit card required
12- - ** 1M context window** - Models with 1 million token context windows
13- - ** Auto-refresh** - Automatically renews tokens when they expire
14- - ** qwen-code compatible** - Reuses existing credentials from ` ~/.qwen/oauth_creds.json `
10+ ## ✨ Features
1511
16- ## Installation
12+ - 🔐 ** OAuth Device Flow** - Secure browser-based authentication (RFC 8628)
13+ - ⚡ ** Automatic Polling** - No need to press Enter after authorizing
14+ - 🆓 ** 2,000 req/day free** - Generous free tier with no credit card
15+ - 🧠 ** 1M context window** - Models with 1 million token context
16+ - 🔄 ** Auto-refresh** - Tokens renewed automatically before expiration
17+ - 🔗 ** qwen-code compatible** - Reuses credentials from ` ~/.qwen/oauth_creds.json `
18+
19+ ## 📋 Prerequisites
20+
21+ - [ OpenCode CLI] ( https://opencode.ai ) installed
22+ - A [ qwen.ai] ( https://chat.qwen.ai ) account (free to create)
23+
24+ ## 🚀 Installation
1725
1826### 1. Add the plugin to OpenCode
1927
@@ -41,49 +49,93 @@ Edit `~/.opencode/opencode.jsonc`:
4149cd ~ /.opencode && npm install
4250```
4351
44- ### 3. Authenticate
52+ ## 🔑 Usage
4553
46- Start OpenCode and select the ** Qwen Code ** provider:
54+ ### 1. Login
4755
4856``` bash
49- opencode
57+ opencode auth login
5058```
5159
52- Or via command line (select "Other" and type ` qwen-code ` ):
60+ ### 2. Select Provider
5361
54- ``` bash
55- opencode auth login
56- ```
62+ Choose ** "Other" ** and type ` qwen-code `
63+
64+ ### 3. Authenticate
5765
58- Choose ** "Qwen Code (qwen.ai OAuth)"** and authorize in your browser.
66+ Select ** "Qwen Code (qwen.ai OAuth)"**
5967
60- ### 4. Use Qwen models
68+ - A browser window will open for you to authorize
69+ - The plugin automatically detects when you complete authorization
70+ - No need to copy/paste codes or press Enter!
71+
72+ > [ !TIP]
73+ > In the OpenCode TUI (graphical interface), the ** Qwen Code** provider appears automatically in the provider list.
74+
75+ ## 🎯 Available Models
76+
77+ | Model | Context | Max Output | Best For |
78+ | -------| ---------| ------------| ----------|
79+ | ` qwen3-coder-plus ` | 1M tokens | 64K tokens | Complex coding tasks |
80+ | ` qwen3-coder-flash ` | 1M tokens | 64K tokens | Fast responses |
81+
82+ ### Using a specific model
6183
6284``` bash
6385opencode --provider qwen-code --model qwen3-coder-plus
6486```
6587
66- ## Available Models
67-
68- | Model | Context | Output | Description |
69- | -------| ---------| --------| -------------|
70- | ` qwen3-coder-plus ` | 1M tokens | 64K tokens | Most capable coding model |
71- | ` qwen3-coder-flash ` | 1M tokens | 64K tokens | Faster responses |
88+ ## ⚙️ How It Works
7289
73- ## How It Works
90+ ```
91+ ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
92+ │ OpenCode CLI │────▶│ qwen.ai OAuth │────▶│ Qwen3-Coder │
93+ │ │◀────│ (Device Flow) │◀────│ API │
94+ └─────────────────┘ └──────────────────┘ └─────────────────┘
95+ ```
7496
75- 1 . ** Device Flow (RFC 8628)** : When logging in, the plugin opens your browser to ` chat.qwen.ai `
76- 2 . ** Automatic Polling** : The plugin automatically detects when you authorize (no need to press Enter)
77- 3 . ** Storage** : Credentials are saved to ` ~/.qwen/oauth_creds.json ` (compatible with qwen-code)
78- 4 . ** Auto-refresh** : Tokens are automatically renewed 30 seconds before expiration
97+ 1 . ** Device Flow (RFC 8628)** : Opens your browser to ` chat.qwen.ai ` for authentication
98+ 2 . ** Automatic Polling** : Detects authorization completion automatically
99+ 3 . ** Token Storage** : Saves credentials to ` ~/.qwen/oauth_creds.json `
100+ 4 . ** Auto-refresh** : Renews tokens 30 seconds before expiration
79101
80- ## Usage Limits
102+ ## 📊 Usage Limits
81103
82104| Plan | Rate Limit | Daily Limit |
83105| ------| ------------| -------------|
84106| Free (OAuth) | 60 req/min | 2,000 req/day |
85107
86- ## Local Development
108+ > [ !NOTE]
109+ > Limits reset at midnight UTC. For higher limits, consider using an API key from [ DashScope] ( https://dashscope.aliyun.com ) .
110+
111+ ## 🔧 Troubleshooting
112+
113+ ### Token expired
114+
115+ The plugin automatically renews tokens. If issues persist:
116+
117+ ``` bash
118+ # Remove old credentials
119+ rm ~ /.qwen/oauth_creds.json
120+
121+ # Re-authenticate
122+ opencode auth login
123+ ```
124+
125+ ### Provider not showing in ` auth login `
126+
127+ The ` qwen-code ` provider is added via plugin. In the ` opencode auth login ` command:
128+
129+ 1 . Select ** "Other"**
130+ 2 . Type ` qwen-code `
131+
132+ ### Rate limit exceeded (429 errors)
133+
134+ - Wait until midnight UTC for quota reset
135+ - Try using ` qwen3-coder-flash ` for faster, lighter requests
136+ - Consider [ DashScope API] ( https://dashscope.aliyun.com ) for higher limits
137+
138+ ## 🛠️ Development
87139
88140``` bash
89141# Clone the repository
@@ -95,69 +147,52 @@ bun install
95147
96148# Type check
97149bun run typecheck
150+ ```
98151
99- # Local link in OpenCode
100- # Edit ~/.opencode/package.json:
152+ ### Local testing
153+
154+ Edit ` ~/.opencode/package.json ` :
155+
156+ ``` json
101157{
102158 "dependencies" : {
103- " opencode-qwen-auth" : " file:/absolute/path/to/opencode-qwen-auth"
159+ "opencode-qwen-auth" : " file:/// absolute/path/to/opencode-qwen-auth"
104160 }
105161}
162+ ```
106163
107- # Reinstall
164+ Then reinstall:
165+
166+ ``` bash
108167cd ~ /.opencode && npm install
109168```
110169
111- ## Project Structure
170+ ## 📁 Project Structure
112171
113172```
114173src/
115- ├── constants.ts # Constants ( OAuth endpoints, models)
174+ ├── constants.ts # OAuth endpoints, models config
116175├── types.ts # TypeScript interfaces
117- ├── index.ts # Main plugin
118- ├── cli.ts # Standalone CLI (optional)
176+ ├── index.ts # Main plugin entry point
119177├── qwen/
120- │ └── oauth.ts # OAuth Device Flow + PKCE logic
178+ │ └── oauth.ts # OAuth Device Flow + PKCE
121179└── plugin/
122180 ├── auth.ts # Credentials management
123- ├── client.ts # Qwen API client
124- └── utils.ts # Utilities
181+ └── utils.ts # Helper utilities
125182```
126183
127- ## Troubleshooting
128-
129- ### Token expired
130-
131- The plugin automatically renews tokens. If issues persist:
132-
133- ``` bash
134- # Remove old credentials
135- rm ~ /.qwen/oauth_creds.json
136-
137- # Re-authenticate
138- opencode auth login
139- ```
140-
141- ### Provider not showing in ` auth login `
142-
143- The ` qwen-code ` provider is added via plugin. In the ` opencode auth login ` command:
144- 1 . Select ** "Other"**
145- 2 . Type ` qwen-code `
146-
147- In the TUI (OpenCode graphical interface), the provider appears automatically.
148-
149- ### Rate limit exceeded
150-
151- If you hit the daily limit (2,000 requests):
152- - Wait until midnight UTC for quota reset
153- - Consider using an API Key from [ DashScope] ( https://dashscope.aliyun.com ) for higher limits
154-
155- ## Related Projects
184+ ## 🔗 Related Projects
156185
157186- [ qwen-code] ( https://github.com/QwenLM/qwen-code ) - Official Qwen coding CLI
158- - [ OpenCode] ( https://opencode.ai ) - AI CLI for development
187+ - [ OpenCode] ( https://opencode.ai ) - AI-powered CLI for development
159188- [ opencode-gemini-auth] ( https://github.com/jenslys/opencode-gemini-auth ) - Similar plugin for Google Gemini
160189
161- ## License
190+ ## 📄 License
162191
163192MIT
193+
194+ ---
195+
196+ <p align =" center " >
197+ Made with ❤️ for the OpenCode community
198+ </p >
0 commit comments