Skip to content

Conversation

@nitinprajwal
Copy link

@nitinprajwal nitinprajwal commented Aug 11, 2025

Related GitHub Discussion

Implements: Discussion #6861 - "Support Qwen Code CLI as an API Provider"
Link: #6861

Description

This PR implements support for Qwen Code CLI as an API provider in Roo Code, addressing the community feature request from GitHub Discussion #6861.

Key Implementation Details:

  • OAuth Authentication: Implements OAuth2 flow for Qwen API authentication using cached credentials
  • Provider Integration: Complete integration following existing provider patterns
  • UI Components: Added settings UI for OAuth path configuration
  • Error Handling: Comprehensive error handling with proper user feedback
  • Token Management: Automatic token refresh and validation

Architecture Decisions:

  • Used OpenAI-compatible API format for consistency with existing patterns
  • Added configurable OAuth credentials path for flexibility
  • Followed existing provider schema patterns for seamless integration

Files Modified:

  • src/api/providers/qwen-code.ts - Main provider implementation
  • packages/types/src/providers/qwen-code.ts - Type definitions and model configurations
  • webview-ui/src/components/settings/providers/QwenCode.tsx - Settings UI component
  • packages/types/src/provider-settings.ts - Provider schema integration
  • src/api/index.ts - Provider registration

Test Procedure

Manual Testing Steps:

  1. Setup OAuth Credentials:

    • Obtain Qwen OAuth credentials and place in ~/.qwen/oauth_creds.json
    • Or configure custom path in settings
  2. Provider Configuration:

    • Open Roo Code settings
    • Select "Qwen Code" as API provider
    • Verify OAuth path configuration UI appears
    • Test with both default and custom OAuth paths
  3. Functionality Testing:

    • Create a new conversation
    • Send test prompts to verify streaming responses
    • Test error handling with invalid credentials
    • Verify token refresh functionality
  4. Integration Testing:

    • Test alongside other providers
    • Verify provider switching works correctly
    • Check that model selection UI shows Qwen models

Screenshot

image

Expected Results:

  • Qwen Code provider appears in provider list
  • OAuth authentication works seamlessly
  • Error messages are user-friendly and actionable

Pre-Submission Checklist

  • Discussion Referenced: This PR implements the feature request from GitHub Discussion Support Qwen Code CLI as an API Provider #6861
  • Scope: Changes are focused on Qwen Code provider implementation
  • Self-Review: Performed thorough self-review of all code changes
  • Testing: Manually tested OAuth flow, streaming, and error handling
  • Documentation Impact: Added inline documentation and user-facing settings
  • Contribution Guidelines: Read and followed contributor guidelines

Settings UI:

  • New "Qwen Code" option in provider dropdown
  • OAuth credentials path configuration field
  • Helpful description text and setup instructions

Documentation Updates

  • No additional documentation updates required
  • Inline code documentation provided
  • Settings UI includes helpful descriptions and setup guidance
  • Error messages provide clear instructions for users

Additional Notes

Implementation Highlights:

  • Robust Error Handling: Comprehensive error handling for OAuth failures, network issues, and credential problems
  • Token Management: Automatic token refresh with proper expiry handling
  • Configurable Paths: Support for custom OAuth credential file locations
  • Type Safety: Full TypeScript integration with proper type definitions

Technical Considerations:

  • OAuth credentials are cached locally following Qwen's standard patterns
  • Token refresh happens automatically when tokens are near expiry

Future Enhancements:

  • Could add support for additional Qwen models as they become available
  • Potential for enhanced OAuth flow with browser-based authentication
  • Possible integration with Qwen's upcoming API features

Get in Touch

Discord Username: @nitinprajwal

Feel free to reach out if you have any questions about the implementation, need clarification.


Important

Adds Qwen Code support as an API provider with OAuth2 authentication, UI integration, and comprehensive error handling.

  • Behavior:
    • Adds Qwen Code as an API provider with OAuth2 authentication in qwen-code.ts.
    • Implements token management with automatic refresh and validation.
    • Integrates Qwen Code into provider selection and configuration UI in ApiOptions.tsx and QwenCode.tsx.
  • Provider Integration:
    • Registers QwenCodeHandler in index.ts and providers/index.ts.
    • Adds Qwen Code model definitions in providers/qwen-code.ts.
    • Updates provider-settings.ts to include Qwen Code in provider schemas.
  • UI and Settings:
    • Adds Qwen Code settings UI in QwenCode.tsx.
    • Updates settings.json for Qwen Code descriptions and instructions.
    • Modifies constants.ts and useSelectedModel.ts to support Qwen Code models.
  • Validation and Configuration:
    • Updates checkExistApiConfig.ts and validate.ts to handle Qwen Code configuration without API keys.

This description was created by Ellipsis for ebe1f7711fd60fd79089ae93af844f34e7f8b65e. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request UI/UX UI/UX related or focused labels Aug 11, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've reviewed the changes and found several issues that need attention before this can be merged.

Critical Issue: The file qwen-cli.ts appears to be a binary file despite having a .ts extension. Binary files should not be committed to the repository. Please remove this file.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 11, 2025
@nitinprajwal nitinprajwal changed the title Add qwen-code support Add qwen-code support, Free credits Aug 11, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 13, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 13, 2025
@daniel-lxs
Copy link
Member

Hey @nitinprajwal, do you know if this doesn't break any TOS with Qwen? I couldn't find any information about using this OAuth authentication.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Aug 14, 2025
@nitinprajwal
Copy link
Author

Hey @daniel-lxs , thanks for following up, I’ve gone through the Qwen TOS https://chat.qwen.ai/legal-agreement/terms-of-service and it doesn’t seem to violate any rules. Also in the Qwen-code github repo, the gemini cli TOS is still present.

Another reason this doesn’t break the rules is that it works differently unlike Gemini CLI. gemini-cli used a different endpoint https://cloudcode-pa.googleapis.com, whereas Qwen uses the regular URL https://chat.qwen.ai/ (which is also used for chatting with Qwen model), which is generally accessible to all users, so this PR uses this base-url for authentication.

Copy link

@mechanicmuthu mechanicmuthu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done.

@nitinprajwal
Copy link
Author

Thank you @mechanicmuthu

@nitinprajwal
Copy link
Author

Hey @daniel-lxs, can you help me with these check-types (it was passing all the checks before), the issue is adding new provider "qwen-code" to the providerNames array, but the @roo-code/cloud doesn't support the new "qwen-code". This caused TypeScript errors when passing ClineProvider instances.

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Aug 19, 2025
@daniel-lxs
Copy link
Member

I noticed that the qwenCodeOAuthPath configuration field is defined in the UI component and provider settings schema, but it's not actually being used in the implementation.

In webview-ui/src/components/settings/providers/QwenCode.tsx, there's a text field for users to configure a custom OAuth path, but in src/api/providers/qwen-code.ts, the implementation always uses the hardcoded default path ~/.qwen/oauth_creds.json.

Could you either:

  1. Implement the custom path functionality by using this.options.qwenCodeOAuthPath in the getQwenCachedCredentialPath() function, or
  2. Remove the OAuth path configuration from the UI if it's not intended to be configurable?

This would ensure consistency between what users see in the settings and what actually happens in the code.

@nitinprajwal
Copy link
Author

Hi @Sourav9063, I’ve addressed the error that occurred during the build command, The issue "qwen-code" property was missing in the type definition for Record. I’ve updated the type definition in src/provider-settings.ts to include "qwen-code" and verified the build.

}

private getBaseUrl(creds: QwenOAuthCredentials): string {
let baseUrl = creds.resource_url || "https://dashscope.aliyuncs.com/compatible-mode/v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid url?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Aliyun uses a proxy to simulate the OpenAI-compatible API, accessing it directly will result in a 404 error.

However, ${base}/models and ${base}/completions are available.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Aug 21, 2025
@daniel-lxs
Copy link
Member

Thank you @nitinprajwal for your contribution! We are merging this PR #7380, but we appreciate the time and effort you put into this one. I'm looking forward to seeing more PRs from you.

@daniel-lxs daniel-lxs closed this Aug 25, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 25, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Aug 25, 2025
@nitinprajwal
Copy link
Author

Thanks @daniel-lxs for taking the time to review my PR. I’d love to contribute more :)

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

Labels

enhancement New feature or request PR - Changes Requested size:L This PR changes 100-499 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants