Skip to content

fix: map Qwen Code portal resource_url to correct Dashscope API endpoints#12092

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/qwen-code-portal-url-mapping
Draft

fix: map Qwen Code portal resource_url to correct Dashscope API endpoints#12092
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/qwen-code-portal-url-mapping

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 bot commented Apr 10, 2026

Related GitHub Issue

Closes: #12061

Description

This PR attempts to address Issue #12061 where the Qwen Code provider fails with "400 bad request" for users with newer Qwen Code CLI versions (v0.14.2+).

Root Cause: The Qwen Code CLI v0.14.2+ now sets resource_url in ~/.qwen/oauth_creds.json to portal domains like portal.qwen.ai (international) or chat.qwen.ai (China). The handler was using this value directly as the API base URL, resulting in requests going to https://portal.qwen.ai/v1 instead of the correct Dashscope API endpoint. Additionally, the OAuth token refresh endpoint was hardcoded to chat.qwen.ai, which fails for international portal users.

Fix:

  • Added a QWEN_PORTAL_CONFIG mapping that maps known portal domains to their corresponding Dashscope API base URLs and OAuth token endpoints:
    • portal.qwen.ai -> dashscope-intl.aliyuncs.com (international) with OAuth via portal.qwen.ai
    • chat.qwen.ai -> dashscope.aliyuncs.com (China) with OAuth via chat.qwen.ai
  • The getBaseUrl method now checks if resource_url matches a known portal domain before using it as-is
  • Added getOAuthTokenEndpoint method to derive the correct token endpoint from the credentials resource_url
  • If resource_url is already a full dashscope URL (backward compatibility), it is used directly

Test Procedure

  • Added 8 new tests in qwen-code-portal-mapping.spec.ts covering:
    • portal.qwen.ai maps to dashscope-intl API endpoint
    • chat.qwen.ai maps to dashscope China API endpoint
    • Missing resource_url falls back to default dashscope URL
    • Existing dashscope URLs in resource_url are preserved
    • portal.qwen.ai with https:// prefix is handled correctly
    • OAuth token endpoint correctly derived for each portal domain
  • All existing qwen-code-native-tools.spec.ts tests continue to pass
  • Run: cd src && npx vitest run api/providers/__tests__/qwen-code-portal-mapping.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

Feedback and guidance are welcome. The portal-to-API mapping is based on the observed pattern from Qwen Code CLI v0.14.2 credentials. If additional portal domains emerge, they can be added to the QWEN_PORTAL_CONFIG mapping.

Interactively review PR in Roo Code Cloud

…ints

The Qwen Code CLI v0.14.2+ sets resource_url to portal domains like
"portal.qwen.ai" instead of Dashscope API URLs. The handler was using
this value directly as the API base URL, causing 400 errors.

Changes:
- Add QWEN_PORTAL_CONFIG mapping for known portal domains to their
  corresponding Dashscope API and OAuth token endpoints
- portal.qwen.ai -> dashscope-intl.aliyuncs.com (international)
- chat.qwen.ai -> dashscope.aliyuncs.com (China)
- Derive OAuth token endpoint from resource_url instead of hardcoding
  chat.qwen.ai, so international users hit the correct token server
- Add comprehensive tests for URL mapping behavior

Closes #12061
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Connection Failure: Outdated Connection Parameters for Qwen Code SDK

1 participant