Skip to content

Commit e94f77b

Browse files
committed
feat(v1.5.0): fix rate limiting (#4) — QWEN_OFFICIAL_HEADERS, session/prompt tracking, align models
1 parent 65d7eb9 commit e94f77b

7 files changed

Lines changed: 318 additions & 93 deletions

File tree

CHANGELOG.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [1.5.0] - 2026-03-09
11+
12+
### 🚨 Critical Fixes
13+
14+
- **Fixed rate limiting issue (#4)** - Added official Qwen Code headers to prevent aggressive rate limiting
15+
- Added `QWEN_OFFICIAL_HEADERS` constant with required identification headers
16+
- Headers include `X-DashScope-CacheControl`, `X-DashScope-AuthType`, `X-DashScope-UserAgent`
17+
- Requests now recognized as legitimate Qwen Code client
18+
- Full 2,000 requests/day quota now available
19+
20+
- **Added session and prompt tracking** - Prevents false-positive abuse detection
21+
- Unique `sessionId` per plugin lifetime
22+
- Unique `promptId` per request via `crypto.randomUUID()`
23+
- `X-Metadata` header with tracking information
24+
25+
### ✨ New Features
26+
27+
- **Dynamic API endpoint resolution** - Automatic region detection based on OAuth token
28+
- `portal.qwen.ai``https://portal.qwen.ai/v1` (International)
29+
- `dashscope``https://dashscope.aliyuncs.com/compatible-mode/v1` (China)
30+
- `dashscope-intl``https://dashscope-intl.aliyuncs.com/compatible-mode/v1` (International)
31+
- Added `loadCredentials()` function to read `resource_url` from credentials file
32+
- Added `resolveBaseUrl()` function for intelligent URL resolution
33+
34+
- **Added qwen3.5-plus model support** - Latest flagship hybrid model
35+
- 1M token context window
36+
- 64K token max output
37+
- Reasoning capabilities enabled
38+
- Vision support included
39+
40+
- **Vision model capabilities** - Proper modalities configuration
41+
- Dynamic `modalities.input` based on model capabilities
42+
- Vision models now correctly advertise `['text', 'image']` input
43+
- Non-vision models remain `['text']` only
44+
45+
### 🔧 Technical Improvements
46+
47+
- **Enhanced loader hook** - Returns complete configuration with headers
48+
- Headers injected at loader level for all requests
49+
- Metadata object for backend quota recognition
50+
- Session-based tracking for usage patterns
51+
52+
- **Enhanced config hook** - Consistent header configuration
53+
- Headers set in provider options
54+
- Dynamic modalities based on model capabilities
55+
- Better type safety for vision features
56+
57+
- **Improved auth module** - Better credentials management
58+
- Added `loadCredentials()` for reading from file
59+
- Better error handling in credential loading
60+
- Support for multi-region tokens
61+
62+
### 📚 Documentation
63+
64+
- Updated README with new features section
65+
- Added troubleshooting section for rate limiting
66+
- Updated model table with `qwen3.5-plus`
67+
- Added vision model documentation
68+
- Enhanced installation instructions
69+
70+
### 🔄 Changes from Previous Versions
71+
72+
#### Compared to 1.4.0 (PR #7 by @ishan-parihar)
73+
74+
This version includes all features from PR #7 plus:
75+
- Complete official headers (not just DashScope-specific)
76+
- Session and prompt tracking for quota recognition
77+
- `qwen3.5-plus` model support
78+
- Vision capabilities in modalities
79+
- Direct fix for Issue #4 (rate limiting)
80+
81+
---
82+
83+
## [1.4.0] - 2026-02-27
84+
85+
### Added
86+
- Dynamic API endpoint resolution (PR #7)
87+
- DashScope headers support (PR #7)
88+
- `loadCredentials()` and `resolveBaseUrl()` functions (PR #7)
89+
90+
### Fixed
91+
- `ERR_INVALID_URL` error - loader now returns `baseURL` correctly (PR #7)
92+
- "Incorrect API key provided" error for portal.qwen.ai tokens (PR #7)
93+
94+
---
95+
96+
## [1.3.0] - 2026-02-10
97+
98+
### Added
99+
- OAuth Device Flow authentication
100+
- Support for qwen3-coder-plus, qwen3-coder-flash models
101+
- Automatic token refresh
102+
- Compatibility with qwen-code credentials
103+
104+
### Known Issues
105+
- Rate limiting reported by users (Issue #4)
106+
- Missing official headers for quota recognition
107+
108+
---
109+
110+
## [1.2.0] - 2026-01-15
111+
112+
### Added
113+
- Initial release
114+
- Basic OAuth authentication
115+
- Model configuration for Qwen providers

README.md

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,46 @@
1717
- 🔐 **OAuth Device Flow** - Secure browser-based authentication (RFC 8628)
1818
-**Automatic Polling** - No need to press Enter after authorizing
1919
- 🆓 **2,000 req/day free** - Generous free tier with no credit card
20-
- 🧠 **1M context window** - Models with 1 million token context
20+
- 🧠 **1M context window** - 1 million token context
2121
- 🔄 **Auto-refresh** - Tokens renewed automatically before expiration
2222
- 🔗 **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+
29+
## 🆕 What's New in v1.5.0
30+
31+
### Rate Limiting Fix (Issue #4)
32+
33+
**Problem:** Users were experiencing aggressive rate limiting (2,000 req/day quota exhausted quickly).
34+
35+
**Solution:** Added official Qwen Code headers that properly identify the client:
36+
- `X-DashScope-CacheControl: enable` - Enables KV cache optimization
37+
- `X-DashScope-AuthType: qwen-oauth` - Marks as OAuth authentication
38+
- `X-DashScope-UserAgent` - Identifies as official Qwen Code client
39+
- `X-Metadata` - Session and prompt tracking for quota recognition
40+
41+
**Result:** Full daily quota now available without premature rate limiting.
42+
43+
### Dynamic API Endpoint Resolution
44+
45+
The plugin now automatically detects and uses the correct API endpoint based on the `resource_url` returned by the OAuth server:
46+
47+
| resource_url | API Endpoint | Region |
48+
|-------------|--------------|--------|
49+
| `portal.qwen.ai` | `https://portal.qwen.ai/v1` | International |
50+
| `dashscope` | `https://dashscope.aliyuncs.com/compatible-mode/v1` | China |
51+
| `dashscope-intl` | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1` | International |
52+
53+
This means the plugin works correctly regardless of which region your Qwen account is associated with.
54+
55+
### Aligned with qwen-code-0.12.0
56+
57+
-**coder-model** - Only model exposed (matches official Qwen Code CLI)
58+
-**Vision capabilities** - Supports image input
59+
-**Dynamic modalities** - Input modalities adapt based on model capabilities
2360

2461
## 📋 Prerequisites
2562

@@ -31,12 +68,12 @@
3168
### 1. Install the plugin
3269

3370
```bash
34-
cd ~/.opencode && npm install opencode-qwencode-auth
71+
cd ~/.config/opencode && npm install opencode-qwencode-auth
3572
```
3673

3774
### 2. Enable the plugin
3875

39-
Edit `~/.opencode/opencode.jsonc`:
76+
Edit `~/.config/opencode/opencode.jsonc`:
4077

4178
```json
4279
{
@@ -69,28 +106,18 @@ Select **"Qwen Code (qwen.ai OAuth)"**
69106
70107
## 🎯 Available Models
71108

72-
### Coding Models
109+
### Coding Model
73110

74-
| Model | Context | Max Output | Best For |
111+
| Model | Context | Max Output | Features |
75112
|-------|---------|------------|----------|
76-
| `qwen3-coder-plus` | 1M tokens | 64K tokens | Complex coding tasks |
77-
| `qwen3-coder-flash` | 1M tokens | 64K tokens | Fast coding responses |
78-
79-
### General Purpose Models
113+
| `coder-model` | 1M tokens | 64K tokens | Official alias (Auto-routes to Qwen 3.5 Plus - Hybrid & Vision) |
80114

81-
| Model | Context | Max Output | Reasoning | Best For |
82-
|-------|---------|------------|-----------|----------|
83-
| `qwen3-max` | 256K tokens | 64K tokens | No | Flagship model, complex reasoning and tool use |
84-
| `qwen-plus-latest` | 128K tokens | 16K tokens | Yes | Balanced quality-speed with thinking mode |
85-
| `qwen3-235b-a22b` | 128K tokens | 32K tokens | Yes | Largest open-weight MoE with thinking mode |
86-
| `qwen-flash` | 1M tokens | 8K tokens | No | Ultra-fast, low-cost simple tasks |
115+
> **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.
87116
88-
### Using a specific model
117+
### Using the model
89118

90119
```bash
91-
opencode --provider qwen-code --model qwen3-coder-plus
92-
opencode --provider qwen-code --model qwen3-max
93-
opencode --provider qwen-code --model qwen-plus-latest
120+
opencode --provider qwen-code --model coder-model
94121
```
95122

96123
## ⚙️ How It Works
@@ -139,8 +166,11 @@ The `qwen-code` provider is added via plugin. In the `opencode auth login` comma
139166

140167
### Rate limit exceeded (429 errors)
141168

169+
**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.
170+
171+
If you still experience rate limiting:
172+
- Ensure you're using v1.5.0 or later: `npm update opencode-qwencode-auth`
142173
- Wait until midnight UTC for quota reset
143-
- Try using `qwen3-coder-flash` for faster, lighter requests
144174
- Consider [DashScope API](https://dashscope.aliyun.com) for higher limits
145175

146176
## 🛠️ Development
@@ -159,7 +189,7 @@ bun run typecheck
159189

160190
### Local testing
161191

162-
Edit `~/.opencode/package.json`:
192+
Edit `~/.config/opencode/package.json`:
163193

164194
```json
165195
{
@@ -172,7 +202,7 @@ Edit `~/.opencode/package.json`:
172202
Then reinstall:
173203

174204
```bash
175-
cd ~/.opencode && npm install
205+
cd ~/.config/opencode && npm install
176206
```
177207

178208
## 📁 Project Structure

README.pt-BR.md

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

11-
**Autentique o OpenCode CLI com sua conta qwen.ai.** Este plugin permite usar modelos Qwen (Coder, Max, Plus e mais) com **2.000 requisições gratuitas por dia** - sem API key ou cartão de crédito!
11+
**Autentique o OpenCode CLI com sua conta qwen.ai.** Este plugin permite usar o modelo `coder-model` com **2.000 requisições gratuitas por dia** - sem API key ou cartão de crédito!
1212

1313
[🇺🇸 Read in English](./README.md)
1414

@@ -17,9 +17,14 @@
1717
- 🔐 **OAuth Device Flow** - Autenticação segura via navegador (RFC 8628)
1818
-**Polling Automático** - Não precisa pressionar Enter após autorizar
1919
- 🆓 **2.000 req/dia grátis** - Plano gratuito generoso sem cartão
20-
- 🧠 **1M de contexto** - Modelos com 1 milhão de tokens de contexto
20+
- 🧠 **1M de contexto** - 1 milhão de tokens de contexto
2121
- 🔄 **Auto-refresh** - Tokens renovados automaticamente antes de expirar
2222
- 🔗 **Compatível com qwen-code** - Reutiliza credenciais de `~/.qwen/oauth_creds.json`
23+
- 🌐 **Roteamento Dinâmico** - Resolução automática da URL base da API por região
24+
- 🏎️ **Suporte a KV Cache** - Headers oficiais DashScope para alta performance
25+
- 🎯 **Correção de Rate Limit** - Headers oficiais previnem rate limiting agressivo (Fix #4)
26+
- 🔍 **Session Tracking** - IDs únicos de sessão/prompt para reconhecimento de cota
27+
- 🎯 **Alinhado com qwen-code** - Expõe os mesmos modelos do Qwen Code CLI oficial
2328

2429
## 📋 Pré-requisitos
2530

@@ -69,28 +74,18 @@ Selecione **"Qwen Code (qwen.ai OAuth)"**
6974
7075
## 🎯 Modelos Disponíveis
7176

72-
### Modelos de Código
77+
### Modelo de Código
7378

74-
| Modelo | Contexto | Max Output | Melhor Para |
75-
|--------|----------|------------|-------------|
76-
| `qwen3-coder-plus` | 1M tokens | 64K tokens | Tarefas complexas de código |
77-
| `qwen3-coder-flash` | 1M tokens | 64K tokens | Respostas rápidas de código |
79+
| Modelo | Contexto | Max Output | Recursos |
80+
|--------|----------|------------|----------|
81+
| `coder-model` | 1M tokens | 64K tokens | Alias oficial (Auto-rotas para Qwen 3.5 Plus - Hybrid & Vision) |
7882

79-
### Modelos de Propósito Geral
83+
> **Nota:** Este plugin está alinhado com o cliente oficial `qwen-code-0.12.0`, que expõe apenas o alias `coder-model`. Este modelo automaticamente rotaciona para o melhor Qwen 3.5 Plus disponível com raciocínio híbrido e capacidades de visão.
8084
81-
| Modelo | Contexto | Max Output | Reasoning | Melhor Para |
82-
|--------|----------|------------|-----------|-------------|
83-
| `qwen3-max` | 256K tokens | 64K tokens | Não | Modelo flagship, raciocínio complexo e tool use |
84-
| `qwen-plus-latest` | 128K tokens | 16K tokens | Sim | Equilíbrio qualidade-velocidade com thinking mode |
85-
| `qwen3-235b-a22b` | 128K tokens | 32K tokens | Sim | Maior modelo open-weight MoE com thinking mode |
86-
| `qwen-flash` | 1M tokens | 8K tokens | Não | Ultra-rápido, baixo custo para tarefas simples |
87-
88-
### Usando um modelo específico
85+
### Usando o modelo
8986

9087
```bash
91-
opencode --provider qwen-code --model qwen3-coder-plus
92-
opencode --provider qwen-code --model qwen3-max
93-
opencode --provider qwen-code --model qwen-plus-latest
88+
opencode --provider qwen-code --model coder-model
9489
```
9590

9691
## ⚙️ Como Funciona
@@ -140,7 +135,6 @@ O provider `qwen-code` é adicionado via plugin. No comando `opencode auth login
140135
### Rate limit excedido (erros 429)
141136

142137
- Aguarde até meia-noite UTC para reset da cota
143-
- Tente usar `qwen3-coder-flash` para requisições mais leves
144138
- Considere a [API DashScope](https://dashscope.aliyun.com) para limites maiores
145139

146140
## 🛠️ Desenvolvimento

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "opencode-qwencode-auth",
3-
"version": "1.3.0",
4-
"description": "Qwen OAuth authentication plugin for OpenCode - Access Qwen AI models (Coder, Vision) with your qwen.ai account",
3+
"version": "1.5.0",
4+
"description": "Qwen OAuth authentication plugin for OpenCode - Access Qwen AI models (Coder, Vision) with your qwen.ai account - Fixes rate limiting (Issue #4)",
55
"module": "index.ts",
66
"type": "module",
77
"scripts": {
@@ -15,12 +15,15 @@
1515
"qwen-code",
1616
"qwen3-coder",
1717
"qwen3-vl-plus",
18+
"qwen3.5-plus",
1819
"vision-model",
1920
"oauth",
2021
"authentication",
2122
"ai",
2223
"llm",
23-
"opencode-plugins"
24+
"opencode-plugins",
25+
"rate-limit-fix",
26+
"dashscope"
2427
],
2528
"author": "Gustavo Dias <me@gustavodias.dev>",
2629
"license": "MIT",

0 commit comments

Comments
 (0)