Skip to content

fetch failed on DashScope-intl endpoint: undici dispatcher in DashScopeContentGenerator.buildClient() incompatible with dashscope-intl.aliyuncs.com #4035

@atipico

Description

@atipico

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

  1. Set DASHSCOPE_BASE_URL=https://dashscope-intl.aliyuncs.com/compatible-mode/v1
  2. Configure ~/.qwen/settings.json with selectedType: openai and valid apiKey
  3. Run: echo "hi" | qwen --model qwen-plus
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions