Skip to content

Codex

Codex is a terminal AI coding assistant developed by OpenAI. You can connect it to Alibaba Cloud Model Studio via Token Plan (Team Edition), Coding Plan, or pay-as-you-go billing.

Install Codex

  1. Install or update Node.js (v18.0 or later).

  2. Run the following command in a terminal to install Codex.

    HELPCODEESCAPE-bash
    npm install -g @openai/codex

    Run the following command to verify the installation.

    HELPCODEESCAPE-bash
    codex --version

Configure Access Credentials

To connect, edit the configuration file ~/.codex/config.toml and configure the environment variable OPENAI_API_KEY. Replace the corresponding values based on your selected billing plan. Alibaba Cloud Model Studio offers three billing plans:

Token Plan (Team Edition)

For model, select a supported model. Set the OPENAI_API_KEY environment variable to the Token Plan (Team Edition) dedicated API Key.

Responses API (qwen3.6-plus)

qwen3.6-plus supports the Responses API, allowing you to use the latest version of Codex.

HELPCODEESCAPE-plaintext
model_provider = "Model_Studio_Token_Plan"
model = "qwen3.6-plus"
[model_providers.Model_Studio_Token_Plan]
name = "Model_Studio_Token_Plan"
base_url = "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

Chat/Completions API (other models)

Other models must be connected via the Chat/Completions API, which requires installing an older version of Codex, such as 0.80.0:

HELPCODEESCAPE-bash
npm install -g @openai/codex@0.80.0
HELPCODEESCAPE-plaintext
model_provider = "Model_Studio_Token_Plan"
model = "glm-5"
[model_providers.Model_Studio_Token_Plan]
name = "Model_Studio_Token_Plan"
base_url = "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
env_key = "OPENAI_API_KEY"
wire_api = "chat"

Configure Environment Variables

Set the OPENAI_API_KEY environment variable to the Token Plan (Team Edition) dedicated API Key.

macOS

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

    HELPCODEESCAPE-bash
    echo $SHELL
  2. Set the environment variable based on your shell type:

    Zsh


    HELPCODEESCAPE-bash
    # Replace YOUR_API_KEY with the Token Plan (Team Edition) API Key
    echo 'export OPENAI_API_KEY="YOUR_API_KEY"' >> ~/.zshrc

    Bash


    HELPCODEESCAPE-bash
    # Replace YOUR_API_KEY with the Token Plan (Team Edition) API Key
    echo 'export OPENAI_API_KEY="YOUR_API_KEY"' >> ~/.bash_profile
  3. Run the following command to apply the environment variable.

    Zsh


    HELPCODEESCAPE-bash
    source ~/.zshrc

    Bash


    HELPCODEESCAPE-bash
    source ~/.bash_profile

Windows

CMD

  1. Run the following command in CMD to set the environment variable.

    HELPCODEESCAPE-powershell
    REM Replace YOUR_API_KEY with the Token Plan (Team Edition) API Key
    setx OPENAI_API_KEY "YOUR_API_KEY"
  2. Open a new CMD window and run the following command to verify that the environment variable is set.

    HELPCODEESCAPE-powershell
    echo %OPENAI_API_KEY%

PowerShell

  1. Run the following command in PowerShell to set the environment variable.

    HELPCODEESCAPE-powershell
    # Replace YOUR_API_KEY with the Token Plan (Team Edition) API Key
    [Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "YOUR_API_KEY", [EnvironmentVariableTarget]::User)
  2. Open a new PowerShell window and run the following command to verify that the environment variable is set.

    HELPCODEESCAPE-powershell
    echo $env:OPENAI_API_KEY

Coding Plan

For model, select a supported model. Set the OPENAI_API_KEY environment variable to the Coding Plan dedicated API Key.

Chat/Completions API

Coding Plan only supports the Chat/Completions API, which requires installing an older version of Codex, such as 0.80.0:

HELPCODEESCAPE-bash
npm install -g @openai/codex@0.80.0
HELPCODEESCAPE-plaintext
model_provider = "Model_Studio_Coding_Plan"
model = "qwen3.6-plus"
[model_providers.Model_Studio_Coding_Plan]
name = "Model_Studio_Coding_Plan"
base_url = "https://coding-intl.dashscope.aliyuncs.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "chat"

Configure Environment Variables

Set the OPENAI_API_KEY environment variable to the Coding Plan dedicated API Key.

macOS

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

    HELPCODEESCAPE-bash
    echo $SHELL
  2. Set the environment variable based on your shell type:

    Zsh


    HELPCODEESCAPE-bash
    # Replace YOUR_API_KEY with the Coding Plan API Key
    echo 'export OPENAI_API_KEY="YOUR_API_KEY"' >> ~/.zshrc

    Bash


    HELPCODEESCAPE-bash
    # Replace YOUR_API_KEY with the Coding Plan API Key
    echo 'export OPENAI_API_KEY="YOUR_API_KEY"' >> ~/.bash_profile
  3. Run the following command to apply the environment variable.

    Zsh


    HELPCODEESCAPE-bash
    source ~/.zshrc

    Bash


    HELPCODEESCAPE-bash
    source ~/.bash_profile

Windows

CMD

  1. Run the following command in CMD to set the environment variable.

    HELPCODEESCAPE-powershell
    REM Replace YOUR_API_KEY with the Coding Plan API Key
    setx OPENAI_API_KEY "YOUR_API_KEY"
  2. Open a new CMD window and run the following command to verify that the environment variable is set.

    HELPCODEESCAPE-powershell
    echo %OPENAI_API_KEY%

PowerShell

  1. Run the following command in PowerShell to set the environment variable.

    HELPCODEESCAPE-powershell
    # Replace YOUR_API_KEY with the Coding Plan API Key
    [Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "YOUR_API_KEY", [EnvironmentVariableTarget]::User)
  2. Open a new PowerShell window and run the following command to verify that the environment variable is set.

    HELPCODEESCAPE-powershell
    echo $env:OPENAI_API_KEY

Pay-as-you-go

Set the OPENAI_API_KEY environment variable to the Model Studio API Key. For available models, see supported models.

Set base_url based on the region. The API Key must correspond to the selected region:

  • China North 2 (Beijing): https://dashscope.aliyuncs.com/compatible-mode/v1

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

Pay-as-you-go supports both the Responses API and Chat/Completions API. Choose the appropriate one based on the model you are using:

Responses API

Applicable to models that support the OpenAI Responses API (such as qwen3.6-plus), allowing you to use the latest version of Codex.

HELPCODEESCAPE-plaintext
model_provider = "Model_Studio"
model = "qwen3.6-plus"
[model_providers.Model_Studio]
name = "Model_Studio"
base_url = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

Chat/Completions API

Applicable to models that only support the Chat/Completions API. Requires installing Codex 0.80.0:

HELPCODEESCAPE-bash
npm install -g @openai/codex@0.80.0
HELPCODEESCAPE-plaintext
model_provider = "Model_Studio"
model = "qwen3.6-plus"
[model_providers.Model_Studio]
name = "Model_Studio"
base_url = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
env_key = "OPENAI_API_KEY"
wire_api = "chat"

Configure Environment Variables

Set the OPENAI_API_KEY environment variable to the Model Studio API Key.

macOS

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

    HELPCODEESCAPE-bash
    echo $SHELL
  2. Set the environment variable based on your shell type:

    Zsh


    HELPCODEESCAPE-bash
    # Replace YOUR_API_KEY with the Model Studio API Key
    echo 'export OPENAI_API_KEY="YOUR_API_KEY"' >> ~/.zshrc

    Bash


    HELPCODEESCAPE-bash
    # Replace YOUR_API_KEY with the Model Studio API Key
    echo 'export OPENAI_API_KEY="YOUR_API_KEY"' >> ~/.bash_profile
  3. Run the following command to apply the environment variable.

    Zsh


    HELPCODEESCAPE-bash
    source ~/.zshrc

    Bash


    HELPCODEESCAPE-bash
    source ~/.bash_profile

Windows

CMD

  1. Run the following command in CMD to set the environment variable.

    HELPCODEESCAPE-powershell
    REM Replace YOUR_API_KEY with the Model Studio API Key
    setx OPENAI_API_KEY "YOUR_API_KEY"
  2. Open a new CMD window and run the following command to verify that the environment variable is set.

    HELPCODEESCAPE-powershell
    echo %OPENAI_API_KEY%

PowerShell

  1. Run the following command in PowerShell to set the environment variable.

    HELPCODEESCAPE-powershell
    # Replace YOUR_API_KEY with the Model Studio API Key
    [Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "YOUR_API_KEY", [EnvironmentVariableTarget]::User)
  2. Open a new PowerShell window and run the following command to verify that the environment variable is set.

    HELPCODEESCAPE-powershell
    echo $env:OPENAI_API_KEY

Verify Configuration

After the configuration is complete, open a new terminal window and run the following command to start Codex:

HELPCODEESCAPE-bash
codex

If the chat interface launches successfully, the configuration is correct.

FAQ

What should I do if I get the error "wire_api = chat is no longer supported"?

Cause : The new version of Codex uses the Responses API and does not support the wire_api = "chat" configuration.

Solution:

  • Token Plan (Team Edition) or pay-as-you-go: Change wire_api to responses and verify that base_url is configured correctly.

  • Coding Plan: Run the following command to downgrade to an older version:

    HELPCODEESCAPE-bash
    npm install -g @openai/codex@0.80.0

What should I do if I get the error unexpected status 401 Unauthorized?

Cause:

  • Using an API Key from a different plan (API Keys for Token Plan (Team Edition), Coding Plan, and pay-as-you-go are not interchangeable)

  • Subscription expired

  • API Key was copied incompletely, contains spaces, or has a typo

Solution:

  • Verify that you are using the dedicated API Key for your selected plan.

  • Go to the management page of your selected plan and check whether the subscription has expired.

  • Re-copy the API Key and make sure it is complete and has no spaces.

  • If the error persists after verifying the above, reset the API Key on the management page of your selected plan. After resetting, use the new API Key for configuration.

What should I do if I get the error unexpected status 404 Not Found?

Cause : The base_url or wire_api in the configuration file is incorrect.

Solution : Verify that base_url and wire_api match the configuration for your selected plan. See the configuration examples for your plan in Configure Access Credentials above.

Mirror of Alibaba Cloud Model Studio docs for reference and RAG. Not affiliated with Alibaba Cloud.