Search...
Menu

Qwen Code

Step 1: Set the API Key Environment Variable

Qwen Code requires the API Key to be passed through an environment variable, not directly into the configuration file.

Edit ~/.zprofile and add the following configuration, where ailink_API_KEY is used as a custom environment variable name (you can change it to another name, as long as it is consistent with the envKey in step 2), which will affect the envKey parameter in step 2:

# Qwen Code API Key
export ailink_API_KEY="Your API_KEY"

Execute after saving:

source ~/.zprofile

Step 2: Configure modelProviders

Create or edit ~/.qwen/settings.json and write the following content:

The Base URL and model must be replaced with the actual API Key data requested in the NL system.

The Base URL must end with /v1, otherwise an error will occur.

The envKey parameter is the name of the environment configuration variable from Step 1, not the API key value.

{
  "modelProviders": {
    "openai": [
      {
        "id": "claude-opus-4.5",
        "name": "Claude Opus 4.5",
        "envKey": "ailink_API_KEY",
        "baseUrl": "https://ailink.nativex.com/v1"
      },
      {
        "id": "gemini-2.5-flash",
        "name": "Gemini 2.5 Flash",
        "envKey": "ailink_API_KEY",
        "baseUrl": "https://ailink.nativex.com/v1"
      },
      {
        "id": "gpt-5.3-chat",
        "name": "gpt-5.3-chat",
        "envKey": "ailink_API_KEY",
        "baseUrl": "https://ailink.nativex.com/v1"
      }
    ]
  }
}

Field Description

Field Description
id Unique model identifier (Model ID), used to specify the model in API requests.
name Display name of the model, shown in the model list (/v1/models).
envKey Environment variable name. The API Key is read from the corresponding environment variable at runtime.
baseUrl API Base URL (base endpoint), typically https://ailink.nativex.com/v1, with /v1 appended to the domain.

Step 3: Launch Qwen Code

When you run qwen for the first time, it will open the default Qwen OAuth authentication flow. To use OpenAI-compatible mode instead, start it with the following command:

qwen --auth-type openai

After entering the interactive interface, use the /model command to view and switch between all the models you have configured.

For subsequent launches, simply run:

qwen

to open the tool.

Last modified: 2026-11-17