Alpha software. This plugin is early-stage and may have rough edges. Bug reports and feedback are welcome — please open an issue.
OpenCode plugin that authenticates with Qwen via OAuth — use your free Qwen Code account instead of a paid API key.
Caution: This plugin relies on the same OAuth flow as the official Qwen Code CLI. Alibaba could restrict third-party access at any time. Use at your own discretion.
- A free account at qwen.ai (the same one used by the
qwenCLI) - No API key required
The Qwen Code account provides a generous free quota for the qwen3-coder-plus model. Exact limits may vary by account.
- Add the plugin to your
opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-qwen-auth"],
"provider": {
"qwen": {
"npm": "@ai-sdk/openai-compatible",
"name": "Qwen",
"options": {
"apiKey": "oauth"
},
"models": {
"qwen3-coder-plus": {
"name": "Qwen3 Coder Plus",
"tool_call": true,
"limit": { "context": 1000000, "output": 65536 }
}
}
}
}
}- Log in:
opencode auth loginSelect Qwen as the provider, then Login with Qwen account. Your browser will open automatically — approve the request and you're done.
- Select the model in OpenCode:
qwen / qwen3-coder-plus
The plugin implements the same device code + PKCE OAuth flow used by the official qwen CLI. On each API request it:
- Injects the Bearer token (auto-refreshed before expiry)
- Sets the
X-DashScope-AuthType: qwen-oauthheader required by the backend - Resolves the base URL dynamically from the
resource_urlfield in the token response - Injects a system message if the request lacks one (required to access Qwen Code quota — see
REVERSE_ENGINEERING.md) - Retries token refresh with exponential backoff on transient failures
- Coordinates refresh token rotation across multiple concurrent opencode sessions via a sidecar file (
~/.local/share/opencode/qwen-refresh.json)
OpenCode does not auto-update plugins. To get the latest version:
rm -rf ~/.cache/opencode/node_modules/opencode-qwen-auth
opencodeYour session has expired. Log in again:
opencode auth loginSelect Qwen → Login with Qwen account.
This usually means the system message injection is not working. Ensure you are using the latest version of the plugin (see Updating).
The URL is always shown in the terminal as a fallback — copy and paste it into your browser manually.
This is a known cross-process token rotation issue. Closing and reopening the affected window usually resolves it. If it persists, re-authenticate as above.
Does this work without a paid Qwen account? Yes. A free account at qwen.ai is all you need.
Is my API key or password stored anywhere?
No. The plugin uses OAuth — only short-lived access tokens and refresh tokens are stored by OpenCode in ~/.local/share/opencode/auth.json. Your password never touches this plugin.
Which models are supported?
qwen3-coder-plus is the recommended model and is confirmed to work. Other model IDs may return errors — see REVERSE_ENGINEERING.md for details.
Will this break if Alibaba updates the Qwen CLI?
Possibly. The plugin reverse-engineers the OAuth flow used by the official qwen CLI. If Alibaba changes the flow or revokes third-party client IDs, the plugin will stop working until updated.
Can I use this alongside a DashScope API key? Yes. The plugin also exposes an "Enter DashScope API Key manually" option in the auth flow.
Run the diagnostic script and include the output in your bug report:
curl -fsSL https://raw.githubusercontent.com/bad-noodles/opencode-qwen-auth/main/diagnose.sh | shThen open an issue. See CONTRIBUTING.md for more details.
git clone https://github.com/bad-noodles/opencode-qwen-auth.gitThen point your config at the local path:
{
"plugin": ["file:///absolute/path/to/opencode-qwen-auth"]
}