> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/QwenLM/qwen-code/llms.txt
> Use this file to discover all available pages before exploring further.

# /auth Command

> Configure authentication settings for Qwen Code

## 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

```bash theme={null}
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

```bash theme={null}
qwen --openai-api-key "sk-..."
```

### Custom Base URL

```bash theme={null}
qwen --openai-base-url "https://api.custom.com/v1"
```

### Authentication Type

```bash theme={null}
qwen --auth-type openai
```

Available auth types:

* `openai`
* `anthropic`
* `dashscope`
* `google-genai`
* `azure-openai`

## Environment Variables

Authentication can be configured through environment variables:

```bash theme={null}
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export DASHSCOPE_API_KEY="sk-..."
```

Then run:

```bash theme={null}
qwen
```

## Configuration Files

Authentication settings are stored in:

```
~/.qwen/settings.json
```

Example configuration:

```json theme={null}
{
  "security": {
    "auth": {
      "type": "openai",
      "apiKey": "sk-..."
    }
  }
}
```

<Warning>
  Never commit API keys to version control. Use environment variables or the secure credential store.
</Warning>

## 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:

```bash theme={null}
# 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:

```bash theme={null}
qwen --proxy "http://proxy.example.com:8080"
```

Or set the environment variable:

```bash theme={null}
export HTTPS_PROXY="http://proxy.example.com:8080"
```

## Security Best Practices

<AccordionGroup>
  <Accordion title="Use Environment Variables">
    Store API keys in environment variables instead of hardcoding them:

    ```bash theme={null}
    export OPENAI_API_KEY="sk-..."
    qwen
    ```
  </Accordion>

  <Accordion title="Rotate Keys Regularly">
    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
  </Accordion>

  <Accordion title="Use Project-Specific Keys">
    For team projects, use project-specific API keys with limited permissions:

    ```json theme={null}
    // .qwen/settings.json
    {
      "security": {
        "auth": {
          "type": "openai",
          "apiKey": "${QWEN_PROJECT_KEY}"
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="External Authentication">
    For enterprise deployments, use external authentication services:

    ```json theme={null}
    {
      "security": {
        "auth": {
          "useExternal": true,
          "endpoint": "https://auth.company.com"
        }
      }
    }
    ```
  </Accordion>
</AccordionGroup>

## See Also

<CardGroup cols={2}>
  <Card title="Authentication Guide" icon="key" href="/authentication">
    Complete authentication setup guide
  </Card>

  <Card title="Configuration" icon="gear" href="/configuration/settings">
    Settings and configuration options
  </Card>

  <Card title="Security" icon="shield" href="/advanced/security">
    Security best practices
  </Card>

  <Card title="Environment Setup" icon="terminal" href="/quickstart">
    Initial setup and quickstart
  </Card>
</CardGroup>
