Overview
Qwen authentication provides access to Alibaba Cloud’s Qwen code generation and AI models. The CLI Proxy API uses a device-based OAuth flow that doesn’t require a browser on the server.Prerequisites
Before authenticating with Qwen, ensure you have:- A Qwen account with API access
- CLIProxyAPI server installed and configured
- Email address associated with your Qwen account
- A device with a web browser (can be different from the server)
Authentication
Qwen uses a device-based authentication flow similar to OAuth device authorization grant.Start the login process
Run the following command to initiate Qwen authentication:The CLI will display instructions for device-based authentication.
Complete device authorization
Follow the on-screen prompts:
- A URL will be displayed for authorization
- You may be asked to enter a device code or verification code
- Complete the authorization on any device with a browser
- The CLI polls for completion automatically
Provide email address
When prompted, enter your Qwen account email:This email is used to:
- Identify your account credentials
- Name the token file for organization
- Associate tokens with your Qwen account
Qwen authentication requires an email address. If you don’t provide one when prompted, authentication will fail with an “EmailRequiredError”.
Advanced Options
Manual Browser Mode
If you’re on a headless server or prefer manual URL entry:- Display the authorization URL
- Show the device/verification code
- Wait for you to complete authorization manually
- Not attempt to open a browser automatically
Custom OAuth Callback Port
If Qwen’s authentication requires a callback server, specify a custom port:Configuration
Token Storage Location
Authentication tokens are stored in the configured auth directory:- Default location: Set via
-auth-diror in config file - Filename format:
qwen-<email>-<timestamp>.json - Example:
[email protected]
Token Contents
The stored token file contains:- OAuth 2.0 access token
- Refresh token (if provided)
- Account email address
- Token expiration timestamp
- Authentication metadata
Multiple Accounts
You can authenticate with multiple Qwen accounts:- Creates a separate token file
- Is identified by email address
- Is automatically loaded by the server
- Participates in credential rotation
- Increased rate limits through multiple accounts
- Load balancing across credentials
- Automatic failover if one account hits limits
Email Address Requirements
The email address you provide during authentication:- Must match your Qwen account email
- Is required - authentication fails without it
- Is case-insensitive for file naming
- Used for identification in logs and monitoring
Email Validation
If you see an “EmailRequiredError”:Verification
To verify your authentication is working:Troubleshooting
Email required error
Cause: No email address was provided during authentication. Solution:- Run the login command again
- When prompted, enter your Qwen account email
- Complete the device authorization
Invalid email format
Cause: Email address format is invalid. Solution: Ensure you enter a valid email address:- Must contain
@symbol - Must have a domain (e.g.,
.com,.net) - No spaces or special characters except
@,.,+,-,_
Device code expired
Cause: The device/verification code timeout period expired. Solution:- Run
-qwen-loginagain to generate a new code - Complete authorization more quickly
- Check your network connectivity
Authorization pending timeout
Cause: The CLI timed out waiting for you to complete authorization. Solution:- Complete the device authorization on the browser
- Ensure you’re using the correct URL and code
- Check that you’re signed into the correct Qwen account
- Try authentication again
Token not saving
Cause: Permission issues or invalid auth directory. Solution:Browser opened but shouldn’t have
Cause: Default behavior attempts to open browser. Solution: Use the-no-browser flag:
Network connectivity issues
Cause: Cannot reach Qwen’s authentication servers. Solution:- Check your internet connection
- Verify firewall rules allow outbound HTTPS
- Check if Qwen services are operational
- Try from a different network if possible
Wrong account authenticated
Cause: Signed into different Qwen account in browser. Solution:- Sign out of the current Qwen account in your browser
- Run
-qwen-loginagain - Sign in with the correct account when prompted
- Complete authorization
Token Refresh
Qwen tokens are automatically refreshed by the server:- The server monitors token expiration
- Refresh tokens are used to obtain new access tokens
- Refreshed tokens are saved back to the token file
- No manual intervention required
- Check server logs for errors
- Ensure network connectivity
- Re-authenticate if tokens are invalid
Re-authentication
To re-authenticate a Qwen account:-
Delete the existing token file:
-
Run the login command again:
- Enter the same email address when prompted
- Complete device authorization again
Security Best Practices
- Protect token files - Never share or commit to version control
- Use secure permissions - Token files should be
0600(owner read/write only) - Monitor usage - Check logs for unusual authentication activity
- Rotate credentials - Re-authenticate periodically
- Validate email - Ensure email matches your actual Qwen account
- Secure auth directory - Use appropriate directory permissions (
755)
Multiple Devices
The device-based flow allows authentication from different locations:- Run
-qwen-loginon your server - Complete authorization on your laptop/desktop browser
- Tokens are saved on the server
- The authorization device doesn’t need access to the server
- Remote servers accessed via SSH
- Cloud VMs without direct browser access
- Docker containers
- Automated deployment pipelines