@iamtoricool/opencool-qwen-auth
v0.2.0
Published
Qwen AI OAuth Authentication Plugin for opencode - Access Qwen models via chat.qwen.ai subscription
Downloads
1,327
Maintainers
Readme
OpenCool Qwen Auth Plugin
Qwen AI OAuth Authentication Plugin for opencode - Access Qwen models via your chat.qwen.ai subscription.
Overview
This plugin enables opencode to use Qwen AI's models (Qwen3 Max, Qwen3 Coder, etc.) via OAuth authentication with Qwen's chat platform. Instead of using API keys, you can authenticate using your existing Qwen Chat subscription.
Supported Models
- qwen3-max - Most capable Qwen3 model for complex tasks
- qwen3-coder-plus - Optimized for code generation and programming
- qwen3-vl-plus - Vision language model for image understanding
- qwen3-235b-a22b - Large mixture-of-experts model
Installation
npm install @iamtoricool/opencool-qwen-authConfiguration
Add to your ~/.opencode/opencode.json:
{
"plugin": ["@iamtoricool/opencool-qwen-auth"],
"provider": {
"qwen": {
"options": {}
}
},
"model": "qwen/qwen3-max",
"models": {
"qwen3-max": {
"id": "qwen3-max",
"name": "Qwen3 Max",
"variants": {
"latest": "qwen3-max"
}
}
}
}Authentication
Run the login command:
opencode providers login qwenThis will:
- Open your browser to Qwen's OAuth authorization page
- Start a local callback server on port 1455
- Exchange the authorization code for access/refresh tokens
- Store tokens securely for future use
Features
- OAuth 2.0 with PKCE - Secure authentication flow
- Token Refresh - Automatic token refresh when expired
- Model Configuration - Per-model options support
- Streaming Support - Full SSE streaming for real-time responses
- Fallback Options - Manual URL paste if browser auto-open fails
Architecture
The plugin follows the opencode plugin architecture:
index.ts # Main plugin entry point
lib/
types.ts # TypeScript type definitions
constants.ts # OAuth endpoints, client IDs, models
config.ts # Configuration loading
logger.ts # Request logging
auth/
auth.ts # PKCE, token exchange, JWT decode
server.ts # Local OAuth callback server
browser.ts # Platform-specific browser opening
request/
fetch-helpers.ts # 7-step fetch orchestration
request-transformer.ts # Model normalization, body transforms
response-handler.ts # SSE parsing
config/
opencode-modern.json # Model definitions
test/ # Comprehensive test suiteDevelopment
# Install dependencies
npm install
# Run type check
npm run typecheck
# Run tests
npm test
# Run tests with watch mode
npm run test:watchOAuth Configuration
The plugin uses Qwen's OAuth endpoints:
- Authorization URL:
https://auth.qwen.ai/oauth/authorize - Token URL:
https://auth.qwen.ai/oauth/token - API Base:
https://chat.qwen.ai/backend-api - Redirect URI:
http://localhost:1455/auth/callback - Scopes:
openid profile email offline_access
License
MIT
Contributing
Contributions are welcome! Please ensure tests pass before submitting PRs.
