Environment
- qwen-code version: 0.15.10
- Node.js version: v26.1.0
- OS: Linux (Arch/CachyOS)
- Auth type:
openai (Standard API Key)
- Endpoint:
https://dashscope-intl.aliyuncs.com/compatible-mode/v1 (Singapore/International)
Bug Description
Every prompt fails with [API Error: Connection error. (cause: fetch failed)] when using the DashScope International endpoint (dashscope-intl.aliyuncs.com), even though:
curl to the same endpoint works (HTTP 200)
- Native Node.js
fetch() works
undici in isolation works
- The API key and base URL are correctly resolved inside the CLI (confirmed via debug patch)
Steps to Reproduce
- Set
DASHSCOPE_BASE_URL=https://dashscope-intl.aliyuncs.com/compatible-mode/v1
- Configure
~/.qwen/settings.json with selectedType: openai and valid apiKey
- Run:
echo "hi" | qwen --model qwen-plus
- Result:
[API Error: Connection error. (cause: fetch failed)]
Root Cause
DashScopeContentGenerator.buildClient() passes a custom undici Agent dispatcher to the OpenAI SDK via runtimeOptions:
const runtimeOptions = buildRuntimeFetchOptions("openai", this.cliConfig.getProxy());
// runtimeOptions = { fetchOptions: { dispatcher: new undici.Agent({ headersTimeout: 0, bodyTimeout: 0, keepAliveTimeout: 60000 }) } }
return new OpenAI({
apiKey,
baseURL: baseUrl,
...runtimeOptions || {} // <-- this dispatcher causes fetch to fail
});
This undici Agent fails silently when connecting to dashscope-intl.aliyuncs.com (Singapore region), while the same request succeeds with native fetch().
Confirmed via debug patch:
DEBUG baseURL: https://dashscope-intl.aliyuncs.com/compatible-mode/v1
runtimeOptions: {"fetchOptions":{"dispatcher":{"_events":{},"_eventsCount":0}}}
→ Connection error. (cause: fetch failed)
The issue is specific to the combination of:
- undici
Agent with headersTimeout: 0 / bodyTimeout: 0
- OpenAI SDK using that dispatcher
dashscope-intl.aliyuncs.com endpoint
Workaround
Remove the undici dispatcher from DashScopeContentGenerator.buildClient() in cli.js:
// Before (broken):
const runtimeOptions = buildRuntimeFetchOptions("openai", this.cliConfig.getProxy());
return new OpenAI({ apiKey, baseURL: baseUrl, timeout, maxRetries, defaultHeaders, ...runtimeOptions || {} });
// After (works):
return new OpenAI({ apiKey, baseURL: baseUrl, timeout, maxRetries, defaultHeaders });
This forces the OpenAI SDK to use Node.js native fetch instead of the undici dispatcher, and the connection succeeds.
Additional Notes
- The same issue affects versions 0.13.0, 0.14.5, and 0.15.10 (all tested)
- The China endpoint (
dashscope.aliyuncs.com) may not be affected (not tested)
QWEN_CODE_DISABLE_PRECONNECT=1 helps avoid a secondary error in the preconnect step but does not fix the main issue
- The undici
Agent works fine in isolation with the same endpoint — the failure seems to occur specifically when passed to the OpenAI SDK bundled in the CLI
Environment
openai(Standard API Key)https://dashscope-intl.aliyuncs.com/compatible-mode/v1(Singapore/International)Bug Description
Every prompt fails with
[API Error: Connection error. (cause: fetch failed)]when using the DashScope International endpoint (dashscope-intl.aliyuncs.com), even though:curlto the same endpoint works (HTTP 200)fetch()worksundiciin isolation worksSteps to Reproduce
DASHSCOPE_BASE_URL=https://dashscope-intl.aliyuncs.com/compatible-mode/v1~/.qwen/settings.jsonwithselectedType: openaiand validapiKeyecho "hi" | qwen --model qwen-plus[API Error: Connection error. (cause: fetch failed)]Root Cause
DashScopeContentGenerator.buildClient()passes a custom undiciAgentdispatcher to the OpenAI SDK viaruntimeOptions:This undici
Agentfails silently when connecting todashscope-intl.aliyuncs.com(Singapore region), while the same request succeeds with nativefetch().Confirmed via debug patch:
The issue is specific to the combination of:
AgentwithheadersTimeout: 0/bodyTimeout: 0dashscope-intl.aliyuncs.comendpointWorkaround
Remove the undici dispatcher from
DashScopeContentGenerator.buildClient()incli.js:This forces the OpenAI SDK to use Node.js native fetch instead of the undici dispatcher, and the connection succeeds.
Additional Notes
dashscope.aliyuncs.com) may not be affected (not tested)QWEN_CODE_DISABLE_PRECONNECT=1helps avoid a secondary error in the preconnect step but does not fix the main issueAgentworks fine in isolation with the same endpoint — the failure seems to occur specifically when passed to the OpenAI SDK bundled in the CLI