File size: 2,516 Bytes
d810ed8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# OpenAI Authentication

Qwen Code CLI supports OpenAI authentication for users who want to use OpenAI models instead of Google's Gemini models.

## Authentication Methods

### 1. Interactive Authentication (Recommended)

When you first run the CLI and select OpenAI as your authentication method, you'll be prompted to enter:

- **API Key**: Your OpenAI API key from [https://platform.openai.com/api-keys](https://platform.openai.com/api-keys)
- **Base URL**: The base URL for OpenAI API (defaults to `https://api.openai.com/v1`)
- **Model**: The OpenAI model to use (defaults to `gpt-4o`)

The CLI will guide you through each field:

1. Enter your API key and press Enter
2. Review/modify the base URL and press Enter
3. Review/modify the model name and press Enter

**Note**: You can paste your API key directly - the CLI supports paste functionality and will display the full key for verification.

### 2. Command Line Arguments

You can also provide the OpenAI credentials via command line arguments:

```bash
# Basic usage with API key
qwen-code --openai-api-key "your-api-key-here"

# With custom base URL
qwen-code --openai-api-key "your-api-key-here" --openai-base-url "https://your-custom-endpoint.com/v1"

# With custom model
qwen-code --openai-api-key "your-api-key-here" --model "gpt-4-turbo"
```

### 3. Environment Variables

Set the following environment variables in your shell or `.env` file:

```bash
export OPENAI_API_KEY="your-api-key-here"
export OPENAI_BASE_URL="https://api.openai.com/v1"  # Optional, defaults to this value
export OPENAI_MODEL="gpt-4o"  # Optional, defaults to gpt-4o
```

## Supported Models

The CLI supports all OpenAI models that are available through the OpenAI API, including:

- `gpt-4o` (default)
- `gpt-4o-mini`
- `gpt-4-turbo`
- `gpt-4`
- `gpt-3.5-turbo`
- And other available models

## Custom Endpoints

You can use custom endpoints by setting the `OPENAI_BASE_URL` environment variable or using the `--openai-base-url` command line argument. This is useful for:

- Using Azure OpenAI
- Using other OpenAI-compatible APIs
- Using local OpenAI-compatible servers

## Switching Authentication Methods

To switch between authentication methods, use the `/auth` command in the CLI interface.

## Security Notes

- API keys are stored in memory during the session
- For persistent storage, use environment variables or `.env` files
- Never commit API keys to version control
- The CLI displays API keys in plain text for verification - ensure your terminal is secure