fix: map Qwen Code portal resource_url to correct Dashscope API endpoints#12092
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: map Qwen Code portal resource_url to correct Dashscope API endpoints#12092roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_urlin~/.qwen/oauth_creds.jsonto portal domains likeportal.qwen.ai(international) orchat.qwen.ai(China). The handler was using this value directly as the API base URL, resulting in requests going tohttps://portal.qwen.ai/v1instead of the correct Dashscope API endpoint. Additionally, the OAuth token refresh endpoint was hardcoded tochat.qwen.ai, which fails for international portal users.Fix:
QWEN_PORTAL_CONFIGmapping 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 viaportal.qwen.aichat.qwen.ai->dashscope.aliyuncs.com(China) with OAuth viachat.qwen.aigetBaseUrlmethod now checks ifresource_urlmatches a known portal domain before using it as-isgetOAuthTokenEndpointmethod to derive the correct token endpoint from the credentialsresource_urlresource_urlis already a full dashscope URL (backward compatibility), it is used directlyTest Procedure
qwen-code-portal-mapping.spec.tscovering:portal.qwen.aimaps to dashscope-intl API endpointchat.qwen.aimaps to dashscope China API endpointresource_urlfalls back to default dashscope URLresource_urlare preservedportal.qwen.aiwithhttps://prefix is handled correctlyqwen-code-native-tools.spec.tstests continue to passcd src && npx vitest run api/providers/__tests__/qwen-code-portal-mapping.spec.tsPre-Submission Checklist
Documentation Updates
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_CONFIGmapping.Interactively review PR in Roo Code Cloud