Skip to main content

Overview

The /auth command opens the authentication configuration dialog where you can set up or modify your API credentials and OAuth settings.

Usage

In Interactive Mode

qwen
> /auth

Alternative Names

The following aliases are available:
  • /auth
  • /login

What It Does

The /auth command:
  1. Opens an interactive dialog for authentication setup
  2. Allows you to choose between different authentication methods
  3. Guides you through the setup process
  4. Validates credentials before saving
  5. Stores authentication tokens securely

Authentication Methods

Qwen Code supports multiple authentication providers:

OpenAI

Authenticate with OpenAI API:
  1. Run /auth
  2. Select “OpenAI”
  3. Enter your API key
  4. Test the connection

Anthropic

Authenticate with Anthropic (Claude):
  1. Run /auth
  2. Select “Anthropic”
  3. Enter your API key
  4. Test the connection

Qwen (Dashscope)

Authenticate with Qwen models:
  1. Run /auth
  2. Select “Dashscope”
  3. Enter your API key from Alibaba Cloud
  4. Test the connection

OAuth

For providers supporting OAuth:
  1. Run /auth
  2. Select OAuth provider
  3. Complete browser-based authentication
  4. Return to the CLI

Command-Line Authentication

You can also configure authentication via command-line flags:

OpenAI API Key

qwen --openai-api-key "sk-..."

Custom Base URL

qwen --openai-base-url "https://api.custom.com/v1"

Authentication Type

qwen --auth-type openai
Available auth types:
  • openai
  • anthropic
  • dashscope
  • google-genai
  • azure-openai

Environment Variables

Authentication can be configured through environment variables:
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export DASHSCOPE_API_KEY="sk-..."
Then run:
qwen

Configuration Files

Authentication settings are stored in:
~/.qwen/settings.json
Example configuration:
{
  "security": {
    "auth": {
      "type": "openai",
      "apiKey": "sk-..."
    }
  }
}
Never commit API keys to version control. Use environment variables or the secure credential store.

Switching Authentication

To switch between different authentication methods:
  1. Run /auth
  2. Select a different provider
  3. Configure the new credentials
  4. The change takes effect immediately

Troubleshooting

Invalid API Key

If you see authentication errors:
  1. Verify your API key is correct
  2. Check if the key has the necessary permissions
  3. Ensure you’re using the right authentication type
  4. Try regenerating your API key

Connection Issues

If authentication fails:
# Test with debug mode
qwen --debug
> /auth
Check:
  • Network connectivity
  • Firewall settings
  • Proxy configuration
  • API service status

Proxy Configuration

If you’re behind a proxy:
qwen --proxy "http://proxy.example.com:8080"
Or set the environment variable:
export HTTPS_PROXY="http://proxy.example.com:8080"

Security Best Practices

Store API keys in environment variables instead of hardcoding them:
export OPENAI_API_KEY="sk-..."
qwen
Periodically regenerate your API keys and update your configuration:
  1. Generate new API key from provider
  2. Run /auth to update
  3. Revoke old API key
For team projects, use project-specific API keys with limited permissions:
// .qwen/settings.json
{
  "security": {
    "auth": {
      "type": "openai",
      "apiKey": "${QWEN_PROJECT_KEY}"
    }
  }
}
For enterprise deployments, use external authentication services:
{
  "security": {
    "auth": {
      "useExternal": true,
      "endpoint": "https://auth.company.com"
    }
  }
}

See Also

Authentication Guide

Complete authentication setup guide

Configuration

Settings and configuration options

Security

Security best practices

Environment Setup

Initial setup and quickstart