Skip to content

Plugin de autenticação OAuth para OpenCode CLI - Use modelos Qwen3-Coder com sua conta qwen.ai (2.000 req/dia grátis)

License

Notifications You must be signed in to change notification settings

gustavodiasdev/opencode-qwencode-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Qwen Code OAuth Plugin for OpenCode

npm version License GitHub stars

OpenCode with Qwen Code

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!

🇧🇷 Leia em Português

✨ Features

  • 🔐 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

📋 Prerequisites

🚀 Installation

1. Install the plugin

cd ~/.opencode && npm install opencode-qwencode-auth

2. Enable the plugin

Edit ~/.opencode/opencode.jsonc:

{
  "plugin": ["opencode-qwencode-auth"]
}

🔑 Usage

1. Login

opencode auth login

2. Select Provider

Choose "Other" and type qwen-code

3. Authenticate

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.

🎯 Available Models

Coding Models

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

General Purpose Models

Model Context Max Output Reasoning Best For
qwen3-max 256K tokens 64K tokens No Flagship model, complex reasoning and tool use
qwen-plus-latest 128K tokens 16K tokens Yes Balanced quality-speed with thinking mode
qwen3-235b-a22b 128K tokens 32K tokens Yes Largest open-weight MoE with thinking mode
qwen-flash 1M tokens 8K tokens No Ultra-fast, low-cost simple tasks

Using a specific model

opencode --provider qwen-code --model qwen3-coder-plus
opencode --provider qwen-code --model qwen3-max
opencode --provider qwen-code --model qwen-plus-latest

⚙️ How It Works

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│   OpenCode CLI  │────▶│  qwen.ai OAuth   │────▶│  Qwen Models    │
│                 │◀────│  (Device Flow)   │◀────│  API            │
└─────────────────┘     └──────────────────┘     └─────────────────┘
  1. Device Flow (RFC 8628): Opens your browser to chat.qwen.ai for authentication
  2. Automatic Polling: Detects authorization completion automatically
  3. Token Storage: Saves credentials to ~/.qwen/oauth_creds.json
  4. Auto-refresh: Renews tokens 30 seconds before expiration

📊 Usage Limits

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.

🔧 Troubleshooting

Token expired

The plugin automatically renews tokens. If issues persist:

# Remove old credentials
rm ~/.qwen/oauth_creds.json

# Re-authenticate
opencode auth login

Provider not showing in auth login

The qwen-code provider is added via plugin. In the opencode auth login command:

  1. Select "Other"
  2. Type qwen-code

Rate limit exceeded (429 errors)

  • Wait until midnight UTC for quota reset
  • Try using qwen3-coder-flash for faster, lighter requests
  • Consider DashScope API for higher limits

🛠️ Development

# 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 typecheck

Local testing

Edit ~/.opencode/package.json:

{
  "dependencies": {
    "opencode-qwencode-auth": "file:///absolute/path/to/opencode-qwencode-auth"
  }
}

Then reinstall:

cd ~/.opencode && npm install

📁 Project Structure

src/
├── constants.ts        # OAuth endpoints, models config
├── types.ts            # TypeScript interfaces
├── index.ts            # Main plugin entry point
├── qwen/
│   └── oauth.ts        # OAuth Device Flow + PKCE
└── plugin/
    ├── auth.ts         # Credentials management
    └── utils.ts        # Helper utilities

🔗 Related Projects

📄 License

MIT


Made with ❤️ for the OpenCode community

About

Plugin de autenticação OAuth para OpenCode CLI - Use modelos Qwen3-Coder com sua conta qwen.ai (2.000 req/dia grátis)

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •