Skip to content

feat: dynamic API endpoint resolution and DashScope headers support (v1.4.0)#7

Open
ishan-parihar wants to merge 2 commits intogustavodiasdev:mainfrom
ishan-parihar:main
Open

feat: dynamic API endpoint resolution and DashScope headers support (v1.4.0)#7
ishan-parihar wants to merge 2 commits intogustavodiasdev:mainfrom
ishan-parihar:main

Conversation

@ishan-parihar
Copy link

Summary

This PR adds dynamic API endpoint resolution and DashScope headers support to fix compatibility issues with different Qwen OAuth token regions.

Changes

New Features

  • Dynamic API Endpoint Resolution: Automatically detects and uses the correct API endpoint based on resource_url from the OAuth token

    • portal.qwen.aihttps://portal.qwen.ai/v1
    • dashscopehttps://dashscope.aliyuncs.com/compatible-mode/v1
    • dashscope-intlhttps://dashscope-intl.aliyuncs.com/compatible-mode/v1
  • DashScope Headers Support: Automatically injects required headers when using DashScope endpoints:

    • X-DashScope-CacheControl: enable
    • X-DashScope-UserAgent
    • X-DashScope-AuthType: qwen-oauth

Bug Fixes

  • Fixed ERR_INVALID_URL error: The loader now returns baseURL (capital letters) instead of baseUrl, which OpenCode expects
  • Fixed "Incorrect API key provided" error: Users with portal.qwen.ai tokens were being routed to DashScope URL, causing authentication failures

Technical Details

  • Added loadCredentials() function to read resource_url from credentials file
  • Added resolveBaseUrl() function for URL resolution logic
  • Added chat.headers hook for injecting DashScope-specific headers
  • Removed hardcoded baseURL from config hook (now set dynamically by loader)

Testing

Tested with:

  • portal.qwen.ai token (international users)
  • DashScope token (Chinese region)

Files Changed

  • src/constants.ts - Added DashScope headers constant and multiple base URLs
  • src/plugin/auth.ts - Added loadCredentials() and resolveBaseUrl() functions
  • src/index.ts - Dynamic URL resolution, headers hook, fixed loader return format
  • package.json - Version bump to 1.4.0
  • README.md - Updated documentation with new features

Ishan Parihar added 2 commits February 28, 2026 03:30
…v1.4.0)

- Add resolveBaseUrl() to dynamically select API endpoint based on resource_url
- Support portal.qwen.ai, dashscope, and dashscope-intl endpoints
- Add DashScope-specific headers (X-DashScope-CacheControl, X-DashScope-UserAgent, X-DashScope-AuthType)
- Fix loader return format (baseURL instead of baseUrl) to fix ERR_INVALID_URL error
- Add loadCredentials() to read resource_url from credentials file
- Add chat.headers hook for injecting DashScope headers
- Update README with multi-endpoint documentation
- Bump version to 1.4.0

Fixes:
- ERR_INVALID_URL: "undefined/chat/completions" cannot be parsed as a URL
- "Incorrect API key provided" when using portal.qwen.ai tokens with DashScope URL
@ishan-parihar ishan-parihar marked this pull request as draft February 27, 2026 22:16
@ishan-parihar ishan-parihar marked this pull request as ready for review February 27, 2026 22:17
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.

1 participant