All Products
Search
Document Center

Alibaba Cloud Model Studio:Qwen Code

Last Updated:Jan 05, 2026

Qwen Code is a command-line AI workflow tool optimized for Qwen3-Coder. It boosts development efficiency through advanced code comprehension, task automation, and intelligent assistance features.

Procedure

Preparations

  • Get an API key: Get an API key before you start.

  • Check the Node.js version: Qwen Code requires Node.js version 20 or later. Run node -v to check the version. If the version is earlier than 20, you must reinstall it.

Install and configure Qwen Code

  1. Install Qwen Code

    Run one of the following commands in your terminal to install Qwen Code.

    Install using npm (Recommended)

    npm install -g @qwen-code/qwen-code@latest

    Install from source

    git clone https://github.com/QwenLM/qwen-code.git
    cd qwen-code
    npm install
    npm install -g .
  2. Start and configure Qwen Code

    1. Start Qwen Code

      Enter qwen in your terminal to start Qwen Code.

    2. Select an authentication method

      This example uses the OpenAI-compatible authentication provided by Model Studio. Select OpenAI and press Enter.

      image.png

      Enter the following information on the page:

      Item

      Description

      配置-intl-zh

      API Key

      Your Model Studio API key.

      Base URL

      • Singapore: https://dashscope-intl.aliyuncs.com/compatible-mode/v1

      • Virginia: https://dashscope-us.aliyuncs.com/compatible-mode/v1

      • Beijing: https://dashscope.aliyuncs.com/compatible-mode/v1

      Model

      The name of the model. Qwen Code is specifically optimized for the Qwen3-Coder series and is compatible with models that provide an OpenAI compatible API, such as Qwen-Max, Qwen-Plus, Qwen-Flash, and DeepSeek. We recommend models with strong coding capabilities, such as:

      • qwen3-coder-plus

      • qwen3-coder-480b-a35b-instruct

      • qwen3-coder-flash

      • qwen3-coder-30b-a3b-instruct

      To avoid entering this information every time you start Qwen Code, export environment variables as described below.

      Export environment variables

      Use global environment variables or a .env file. If both are configured, global environment variables take precedence over the .env file.

      .env file

      Create a .env file in the project root directory and add the following content. These environment variables apply only to the current project.

      # Replace YOUR_DASHSCOPE_API_KEY with your Model Studio API key
      OPENAI_API_KEY="YOUR_DASHSCOPE_API_KEY"
      # The following is the URL for the Singapore region. Different regions use separate base_url
      OPENAI_BASE_URL="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
      # This example uses the qwen3-coder-plus model. You can replace it with another model as needed.
      OPENAI_MODEL="qwen3-coder-plus"

      Global environment variables

      Set your Model Studio API key, base URL, and model as global environment variables. These variables apply to all projects and terminal sessions.

      macOS

      1. Run the following command in the terminal to check your default shell type.

        echo $SHELL
      2. Set the environment variables based on your shell type.

        Zsh

        # Replace YOUR_DASHSCOPE_API_KEY with your Model Studio API key
        # The following is the URL for the Singapore region. Different regions use separate base_url
        # This example uses the qwen3-coder-plus model. You can replace it with another model as needed.
        echo 'export OPENAI_API_KEY="YOUR_DASHSCOPE_API_KEY"' >> ~/.zshrc
        echo 'export OPENAI_BASE_URL="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"' >> ~/.zshrc
        echo 'export OPENAI_MODEL="qwen3-coder-plus"' >> ~/.zshrc

        Bash

        # Replace YOUR_DASHSCOPE_API_KEY with your Model Studio API key
        # The following is the URL for the Singapore region. Different regions use separate base_url
        # This example uses the qwen3-coder-plus model. You can replace it with another model as needed.
        echo 'export OPENAI_API_KEY="YOUR_DASHSCOPE_API_KEY"' >> ~/.bash_profile
        echo 'export OPENAI_BASE_URL="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"' >> ~/.bash_profile
        echo 'export OPENAI_MODEL="qwen3-coder-plus"' >> ~/.bash_profile
      3. Run the following command in the terminal to apply the environment variables.

        Zsh

        source ~/.zshrc

        Bash

        source ~/.bash_profile

      Windows

      CMD

      1. Run the following commands in CMD to set the environment variables.

        # Replace YOUR_DASHSCOPE_API_KEY with your Model Studio API key
        # The following is the URL for the Singapore region. Different regions use separate base_url
        # This example uses the qwen3-coder-plus model. You can replace it with another model as needed.
        setx OPENAI_API_KEY "YOUR_DASHSCOPE_API_KEY"
        setx OPENAI_BASE_URL "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
        setx OPENAI_MODEL "qwen3-coder-plus"
      2. Open a new CMD window and run the following commands to check if the environment variables are set correctly.

        echo %OPENAI_API_KEY%
        echo %OPENAI_BASE_URL%
        echo %OPENAI_MODEL%

      PowerShell

      1. Run the following commands in PowerShell to set the environment variables.

        # Replace YOUR_DASHSCOPE_API_KEY with your Model Studio API key
        # The following is the URL for the Singapore region. Different regions use separate base_url
        # This example uses the qwen3-coder-plus model. You can replace it with another model as needed.
        [Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "YOUR_DASHSCOPE_API_KEY", [EnvironmentVariableTarget]::User)
        [Environment]::SetEnvironmentVariable("OPENAI_BASE_URL", "https://dashscope-intl.aliyuncs.com/compatible-mode/v1", [EnvironmentVariableTarget]::User)
        [Environment]::SetEnvironmentVariable("OPENAI_MODEL", "qwen3-coder-plus", [EnvironmentVariableTarget]::User)
      2. Open a new PowerShell window and run the following commands to check if the environment variables are set correctly.

        echo $env:OPENAI_API_KEY
        echo $env:OPENAI_BASE_URL
        echo $env:OPENAI_MODEL

Ask Qwen Code

In the dialog box, enter "How to implement a Binary Search Tree in Python?" Qwen Code then creates a plan and requests permission to perform operations, such as creating, writing to, and executing files.

image

The result is shown in the following figure:

20251126192625

View token usage

Enter /stats model to view the token usage and the number of API calls since Qwen Code was started.

image.png

Free quota

Claim a free quota in one of the following two ways:

  • Method 1: Model Studio's new user free quota

    Model Studio provides a free quota of 1 million tokens for each model, such as Qwen3-Coder (only in the Singapore region). When you access the service using the OpenAI authentication method, the free quota for the model is used first. To check the remaining quota, go to the Models page and click the model card. To avoid extra charges, turn on the Free Quota Only feature.

    用完即停

  • Method 2: Qwen Code daily free quota

    Authenticate with Qwen Chat to receive 2,000 free API calls daily. After you start Qwen Code, enter /auth, select the Qwen Oauth authentication method, and log on to your Qwen Chat account on the redirected page or scan the QR code to authenticate.

    Note:

    • To continue using the service after the 2,000 API calls are used, switch to the OpenAI authentication method using the /auth command.

    • If you are using Qwen Chat for the first time, register an account.

    • You cannot switch models with this authentication method. To maintain service quality, the model may be downgraded.

Advanced operations

For more information about the advanced features of Qwen Code or other coder models of the Qwen series, see the Qwen Code documentation and Model Studio's Coding capabilities (Qwen-Coder).

FAQ

Q: Why does Qwen Code consume tokens quickly?

A: Qwen Code may call the API multiple times, which can consume many tokens. Use the following methods to control token consumption:

  • Streamline the working directory

    Start Qwen Code in a specific project directory. Having too many files in the startup directory, such as the root directory, can increase token consumption.

  • Set a token limit

    Create a .qwen/settings.json file in the project root directory and restart Qwen Code. Use sessionTokenLimit to control the token usage for a single API call:

    {
      "sessionTokenLimit": 32000
    }
    Qwen Code may call the API multiple times, which can cause the token consumption for a single question to exceed the sessionTokenLimit value.
  • Use compression/purge commands

    Enter the following commands to reduce token consumption:

    • /compress

      Compresses the conversation history to continue the dialogue within the token limit.

    • /clear

      Purges all conversation history and starts a new session.

Q: How to switch models?

A: The method depends on whether you have set environment variables:

  • If you have not configured environment variables

    1. Enter /quit to exit Qwen Code.

    2. Enter qwen to start Qwen Code, select the OpenAI authentication method, and then enter the API key, base URL, and target model name.

  • If you have configured environment variables

    1. Change the OPENAI_MODEL environment variable to the target model and apply the change. For more information, see Export environment variables.

    2. Enter /quit to exit Qwen Code, and then enter qwen to restart it.

Q: Why do I get a 401 Incorrect API key provided error?

A: This error may be caused by an incorrect API configuration. Compare the API key in the error message with your settings to ensure they match. Global environment variable configurations take precedence over environment file configurations. To use the configuration from the environment file, ensure that the relevant global environment variables are not set or clear them temporarily.

For more information, see Qwen Code troubleshooting guide.