Skip to content

Commit afa4efe

Browse files
committed
docs: add CHANGELOG, correct quota (1,000/day), fix repo URLs in README
- User-focused READMEs with comprehensive documentation - Comprehensive technical CHANGELOG following Keep a Changelog format - Correct quota documentation (1,000 req/day, not 2,000) - Fix repository references to point to original repo (gustavodiasdev) - Update badges and clone URLs following fork best practices - Documentation in both English (README.md) and Portuguese (README.pt-BR.md) - Restore critical error handling in src/index.ts and src/qwen/oauth.ts
1 parent 84e83d2 commit afa4efe

4 files changed

Lines changed: 126 additions & 260 deletions

File tree

README.md

Lines changed: 56 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -8,189 +8,119 @@
88
<img src="assets/screenshot.png" alt="OpenCode with Qwen Code" width="800">
99
</p>
1010

11-
**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!
11+
**Authenticate OpenCode CLI with your qwen.ai account.** This plugin enables you to use the `coder-model` with **1,000 free requests per day** - no API key or credit card required!
1212

13-
[🇧🇷 Leia em Português](./README.pt-BR.md)
13+
[🇧🇷 Leia em Português](./README.pt-BR.md) | [📜 Changelog](./CHANGELOG.md)
1414

1515
## ✨ Features
1616

1717
- 🔐 **OAuth Device Flow** - Secure browser-based authentication (RFC 8628)
18-
- **Automatic Polling** - No need to press Enter after authorizing
19-
- 🆓 **2,000 req/day free** - Generous free tier with no credit card
20-
- 🧠 **1M context window** - 1 million token context
18+
- 🆓 **1,000 req/day free** - Free quota reset daily at midnight UTC
19+
- **60 req/min** - Rate limit of 60 requests per minute
20+
- 🧠 **1M context window** - Massive context support for large projects
2121
- 🔄 **Auto-refresh** - Tokens renewed automatically before expiration
22+
- ⏱️ **Reliability** - Built-in request throttling and automatic retry for transient errors
2223
- 🔗 **qwen-code compatible** - Reuses credentials from `~/.qwen/oauth_creds.json`
23-
- 🌐 **Dynamic Routing** - Automatic resolution of API base URL based on region
24-
- 🏎️ **KV Cache Support** - Official DashScope headers for high performance
25-
- 🎯 **Rate Limit Fix** - Official headers prevent aggressive rate limiting (Fixes #4)
26-
- 🔍 **Session Tracking** - Unique session/prompt IDs for proper quota recognition
27-
- 🎯 **Aligned with qwen-code** - Exposes same models as official Qwen Code CLI
28-
- ⏱️ **Request Throttling** - 1-2.5s intervals between requests (prevents 60 req/min limit)
29-
- 🔄 **Automatic Retry** - Exponential backoff with jitter for 429/5xx errors (up to 7 attempts)
30-
- 📡 **Retry-After Support** - Respects server's Retry-After header when rate limited
31-
32-
## 🆕 What's New in v1.5.0
33-
34-
### Rate Limiting Fix (Issue #4)
35-
36-
**Problem:** Users were experiencing aggressive rate limiting (2,000 req/day quota exhausted quickly).
37-
38-
**Solution:** Added official Qwen Code headers that properly identify the client:
39-
- `X-DashScope-CacheControl: enable` - Enables KV cache optimization
40-
- `X-DashScope-AuthType: qwen-oauth` - Marks as OAuth authentication
41-
- `X-DashScope-UserAgent` - Identifies as official Qwen Code client
42-
- `X-Metadata` - Session and prompt tracking for quota recognition
43-
44-
**Result:** Full daily quota now available without premature rate limiting.
45-
46-
### Automatic Retry & Throttling (v1.5.0+)
47-
48-
**Request Throttling:**
49-
- Minimum 1 second interval between requests
50-
- Additional 0.5-1.5s random jitter (more human-like)
51-
- Prevents hitting 60 req/min limit
52-
53-
**Automatic Retry:**
54-
- Up to 7 retry attempts for transient errors
55-
- Exponential backoff with +/- 30% jitter
56-
- Respects `Retry-After` header from server
57-
- Retries on 429 (rate limit) and 5xx (server errors)
58-
59-
**Result:** Smoother request flow and automatic recovery from rate limiting.
60-
61-
### Dynamic API Endpoint Resolution
62-
63-
The plugin now automatically detects and uses the correct API endpoint based on the `resource_url` returned by the OAuth server:
64-
65-
| resource_url | API Endpoint | Region |
66-
|-------------|--------------|--------|
67-
| `portal.qwen.ai` | `https://portal.qwen.ai/v1` | International |
68-
| `dashscope` | `https://dashscope.aliyuncs.com/compatible-mode/v1` | China |
69-
| `dashscope-intl` | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1` | International |
70-
71-
This means the plugin works correctly regardless of which region your Qwen account is associated with.
72-
73-
### Aligned with qwen-code-0.12.0
74-
75-
-**coder-model** - Only model exposed (matches official Qwen Code CLI)
76-
-**Vision capabilities** - Supports image input
77-
-**Dynamic modalities** - Input modalities adapt based on model capabilities
78-
79-
## 📋 Prerequisites
80-
81-
- [OpenCode CLI](https://opencode.ai) installed
82-
- A [qwen.ai](https://chat.qwen.ai) account (free to create)
8324

8425
## 🚀 Installation
8526

8627
### 1. Install the plugin
8728

8829
```bash
30+
# Using npm
8931
cd ~/.config/opencode && npm install opencode-qwencode-auth
32+
33+
# Using bun (recommended)
34+
cd ~/.config/opencode && bun add opencode-qwencode-auth
9035
```
9136

9237
### 2. Enable the plugin
9338

94-
Edit `~/.config/opencode/opencode.jsonc`:
39+
Edit `~/.config/opencode/opencode.json`:
9540

9641
```json
9742
{
9843
"plugin": ["opencode-qwencode-auth"]
9944
}
10045
```
10146

47+
## ⚠️ Limits & Quotas
48+
49+
- **Rate Limit:** 60 requests per minute
50+
- **Daily Quota:** 1,000 requests per day (reset at midnight UTC)
51+
- **Web Search:** 200 requests/minute, 1,000/day (separate quota)
52+
53+
> **Note:** These limits are set by the Qwen OAuth API and may change. For professional use with higher quotas, consider using a [DashScope API Key](https://dashscope.aliyun.com).
54+
10255
## 🔑 Usage
10356

10457
### 1. Login
10558

59+
Run the following command to start the OAuth flow:
60+
10661
```bash
10762
opencode auth login
10863
```
10964

11065
### 2. Select Provider
11166

112-
Choose **"Other"** and type `qwen-code`
67+
Choose **"Other"** and type `qwen-code`.
11368

11469
### 3. Authenticate
11570

116-
Select **"Qwen Code (qwen.ai OAuth)"**
117-
118-
- A browser window will open for you to authorize
119-
- The plugin automatically detects when you complete authorization
120-
- No need to copy/paste codes or press Enter!
71+
Select **"Qwen Code (qwen.ai OAuth)"**.
12172

122-
> [!TIP]
123-
> In the OpenCode TUI (graphical interface), the **Qwen Code** provider appears automatically in the provider list.
73+
- A browser window will open for you to authorize.
74+
- The plugin automatically detects when you complete authorization.
75+
- **No need to copy/paste codes or press Enter!**
12476

12577
## 🎯 Available Models
12678

12779
### Coding Model
12880

12981
| Model | Context | Max Output | Features |
13082
|-------|---------|------------|----------|
131-
| `coder-model` | 1M tokens | 64K tokens | Official alias (Auto-routes to Qwen 3.5 Plus - Hybrid & Vision) |
83+
| `coder-model` | 1M tokens | Up to 64K tokens¹ | Official alias (Auto-routes to Qwen 3.5 Plus - Hybrid & Vision) |
13284

133-
> **Note:** This plugin aligns with the official `qwen-code-0.12.0` client, which exposes only the `coder-model` alias. This model automatically routes to the best available Qwen 3.5 Plus with hybrid reasoning and vision capabilities.
85+
> ¹ Actual max output may vary depending on the specific model `coder-model` routes to.
86+
87+
> **Note:** This plugin aligns with the official `qwen-code` client. The `coder-model` alias automatically routes to the best available Qwen 3.5 Plus model with hybrid reasoning and vision capabilities.
13488
13589
### Using the model
13690

13791
```bash
13892
opencode --provider qwen-code --model coder-model
13993
```
14094

141-
## ⚙️ How It Works
142-
143-
```
144-
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
145-
│ OpenCode CLI │────▶│ qwen.ai OAuth │────▶│ Qwen Models │
146-
│ │◀────│ (Device Flow) │◀────│ API │
147-
└─────────────────┘ └──────────────────┘ └─────────────────┘
148-
```
95+
## 🔧 Troubleshooting
14996

150-
1. **Device Flow (RFC 8628)**: Opens your browser to `chat.qwen.ai` for authentication
151-
2. **Automatic Polling**: Detects authorization completion automatically
152-
3. **Token Storage**: Saves credentials to `~/.qwen/oauth_creds.json`
153-
4. **Auto-refresh**: Renews tokens 30 seconds before expiration
97+
### "Invalid access token" or "Token expired"
15498

155-
## 📊 Usage Limits
99+
The plugin usually handles refresh automatically. If you see this error immediately:
156100

157-
| Plan | Rate Limit | Daily Limit |
158-
|------|------------|-------------|
159-
| Free (OAuth) | 60 req/min | 2,000 req/day |
101+
1. **Re-authenticate:** Run `opencode auth login` again.
102+
2. **Clear cache:** Delete the credentials file and login again:
103+
```bash
104+
rm ~/.qwen/oauth_creds.json
105+
opencode auth login
106+
```
160107

161-
> [!NOTE]
162-
> Limits reset at midnight UTC. For higher limits, consider using an API key from [DashScope](https://dashscope.aliyun.com).
108+
### Rate limit exceeded (429 errors)
163109

164-
## 🔧 Troubleshooting
110+
If you hit the 60 req/min or 1,000 req/day limits:
111+
- **Rate limit (60/min):** Wait a few minutes before trying again
112+
- **Daily quota (1,000/day):** Wait until midnight UTC for the quota to reset
113+
- **Web Search (200/min, 1,000/day):** Separate quota for web search tool
114+
- Consider using a [DashScope API Key](https://dashscope.aliyun.com) for professional use with higher quotas
165115

166-
### Token expired
116+
### Enable Debug Logs
167117

168-
The plugin automatically renews tokens. If issues persist:
118+
If something isn't working, you can see detailed logs by setting the debug environment variable:
169119
170120
```bash
171-
# Remove old credentials
172-
rm ~/.qwen/oauth_creds.json
173-
174-
# Re-authenticate
175-
opencode auth login
121+
OPENCODE_QWEN_DEBUG=1 opencode
176122
```
177123
178-
### Provider not showing in `auth login`
179-
180-
The `qwen-code` provider is added via plugin. In the `opencode auth login` command:
181-
182-
1. Select **"Other"**
183-
2. Type `qwen-code`
184-
185-
### Rate limit exceeded (429 errors)
186-
187-
**As of v1.5.0, this should no longer occur!** The plugin now sends official Qwen Code headers that properly identify your client and prevent aggressive rate limiting.
188-
189-
If you still experience rate limiting:
190-
- Ensure you're using v1.5.0 or later: `npm update opencode-qwencode-auth`
191-
- Wait until midnight UTC for quota reset
192-
- Consider [DashScope API](https://dashscope.aliyun.com) for higher limits
193-
194124
## 🛠️ Development
195125
196126
```bash
@@ -201,48 +131,21 @@ cd opencode-qwencode-auth
201131
# Install dependencies
202132
bun install
203133
204-
# Type check
205-
bun run typecheck
134+
# Run tests
135+
bun run tests/debug.ts full
206136
```
207137
208-
### Local testing
209-
210-
Edit `~/.config/opencode/package.json`:
211-
212-
```json
213-
{
214-
"dependencies": {
215-
"opencode-qwencode-auth": "file:///absolute/path/to/opencode-qwencode-auth"
216-
}
217-
}
218-
```
219-
220-
Then reinstall:
221-
222-
```bash
223-
cd ~/.config/opencode && npm install
224-
```
225-
226-
## 📁 Project Structure
138+
### Project Structure
227139
228140
```
229141
src/
230-
├── constants.ts # OAuth endpoints, models config
231-
├── types.ts # TypeScript interfaces
232-
├── index.ts # Main plugin entry point
233-
├── qwen/
234-
│ └── oauth.ts # OAuth Device Flow + PKCE
235-
└── plugin/
236-
├── auth.ts # Credentials management
237-
└── utils.ts # Helper utilities
142+
├── qwen/ # OAuth implementation
143+
├── plugin/ # Token management & caching
144+
├── utils/ # Retry, locking and logging utilities
145+
├── constants.ts # Models and endpoints
146+
└── index.ts # Plugin entry point
238147
```
239148
240-
## 🔗 Related Projects
241-
242-
- [qwen-code](https://github.com/QwenLM/qwen-code) - Official Qwen coding CLI
243-
- [OpenCode](https://opencode.ai) - AI-powered CLI for development
244-
- [opencode-gemini-auth](https://github.com/jenslys/opencode-gemini-auth) - Similar plugin for Google Gemini
245-
246149
## 📄 License
247150
248151
MIT

0 commit comments

Comments
 (0)