Setup guide - Documented by Qwen
Use Qwen in Codex CLI
Model Studio documents Codex CLI setup through a custom model_provider in ~/.codex/config.toml pointing at the OpenAI-compatible endpoint (/compatible-mode/v1), with OPENAI_API_KEY as env_key. Models that support the Responses API work with the latest Codex; Chat/Completions-only models (and the whole Coding Plan) need Codex 0.80.0 with wire_api = "chat".
Last verified 8 steps2 official sources
Steps
- Step 1.
Install Codex (Node.js v18.0 or later) and verify.
Terminalnpm install -g @openai/codex codex --version - Step 2.
Set OPENAI_API_KEY to your Model Studio API key (macOS zsh example; use ~/.bash_profile for bash).
Terminalecho 'export OPENAI_API_KEY="YOUR_API_KEY"' >> ~/.zshrc source ~/.zshrc - Step 3.
Pay-as-you-go, Responses API (for models such as qwen3.7-max): edit ~/.codex/config.toml. Region base URLs: Beijing
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1, Singaporehttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1, US (Virginia)https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1.TOMLmodel_provider = "Model_Studio" model = "qwen3.7-max" [model_providers.Model_Studio] name = "Model_Studio" base_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1" env_key = "OPENAI_API_KEY" wire_api = "responses" - Step 4.
Optional model switching: create ~/.codex/model-catalog.local.json with the model metadata from the Alibaba page, then point config.toml at it. Switch with codex -m (for example codex -m qwen3.8-max) or /model in the TUI.
TOMLmodel_catalog_json = "~/.codex/model-catalog.local.json" - Step 5.
Pay-as-you-go, Chat/Completions-only models: install Codex 0.80.0 and use wire_api = "chat".
TOMLnpm install -g @openai/codex@0.80.0 model_provider = "Model_Studio" model = "qwen3.6-plus" [model_providers.Model_Studio] name = "Model_Studio" base_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1" env_key = "OPENAI_API_KEY" wire_api = "chat" - Step 6.
Coding Plan (Chat/Completions only, older Codex such as 0.80.0): set OPENAI_API_KEY to the Coding Plan key.
TOMLmodel_provider = "Model_Studio_Coding_Plan" model = "qwen3.7-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" - Step 7.
Token Plan Personal Edition, Responses API (latest Codex).
TOMLmodel_provider = "Model_Studio_Token_Plan_Personal" model = "auto" [model_providers.Model_Studio_Token_Plan_Personal] name = "Model_Studio_Token_Plan_Personal" base_url = "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1" env_key = "OPENAI_API_KEY" wire_api = "responses" - Step 8.
Verify: open a new terminal and start Codex. If the chat interface launches, the configuration is correct.
Terminalcodex
Caveats
- Newer Codex versions reject wire_api = "chat" with
wire_api = "chat" is no longer supportedorunknown configuration field wire_api; the Coding Plan therefore requires pinning an older Codex such as 0.80.0. - The pay-as-you-go model catalog on the Alibaba page lists qwen3.8-max, qwen3.7-max, deepseek-v4-pro and glm-5.2 for the Responses API path.
unexpected status 401 Unauthorizedusually means a key from a different plan or region;unexpected status 404 Not Foundmeans base_url or wire_api is wrong.- Third-party switchers such as CC-Switch may report "domestic models not supported" because their health-check probe is rejected with 400; Alibaba says this does not affect actual Codex use.
- Replace {WorkspaceId} with your Workspace ID; keys are region-specific.
More setup guides
Same tool, other providers
Related reading
- Run Qwen3.8-Flash-Next on a Gaming PC With StrataRun Qwen3.8-Flash-Next locally with Strata on a 12 GB GPU: hardware needs, speeds by quant, the license catch, and when the hosted API is the better call.
- Terminal-Universe Turns Agent Traces Into Training EnvironmentsTerminal-Universe, Qwen's paper on rebuilding terminal-agent trajectories into reusable environments, and why agent teams should keep replayable workspaces.
- Qwen3.8-27B vs Opus 4.6 Max: Local Agentic Coding BenchmarksQwen3.8-27B is a 27B dense Apache-2.0 model that beats Opus 4.6 Max on SWE-bench Pro (61.7 vs 53.4). Benchmarks, hardware, cost and when to run it.
- Qwen 3.8 Max Ships: 2.4T MoE, 1M Context, $2/$6 per MTok, Open Weights Next WeekQwen 3.8 Max is a 2.4T-parameter MoE with 95B active, a 1M context window and $2/$6 per million tokens on QwenCloud, with open weights promised next week.
- Qwen-UI-Agent Points at the Next GUI Agent RuntimeQwen-UI-Agent, Alibaba's GUI agent report, reads best as a product spec: mobile, desktop, browser, CLI and DeepSearch combined in one stateful agent runtime.
- $500 RL Fine-Tune of a 9B Open Model Beat GPT-5.6 Sol and Claude Opus 4.8 on Catalog ReviewA $500 GRPO fine-tune of Qwen 3.5 9B beat GPT-5.6 Sol and Opus 4.8 on catalog review, hitting 97% accuracy at a fraction of the cost per listing.
FAQ
How do I use Qwen in Codex CLI?
Model Studio documents Codex CLI setup through a custom model_provider in ~/.codex/config.toml pointing at the OpenAI-compatible endpoint (/compatible-mode/v1), with OPENAI_API_KEY as env_key. Models that support the Responses API work with the latest Codex; Chat/Completions-only models (and the whole Coding Plan) need Codex 0.80.0 with wire_api = "chat".
Which Qwen model ids work in Codex CLI?
The official docs read for this guide list qwen3.7-max, qwen3.8-max, qwen3.6-plus, qwen3.7-plus, qwen3.8-flash, qwen3.6-flash and auto. Requests go to https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1.
Is this an official Qwen and Codex CLI setup?
Qwen documents this setup in its own docs. It was last checked against 2 official pages on October 17, 2026.
Sources
Last verified against 2 official pages.
- alibabacloud.comhttps://www.alibabacloud.com/help/en/model-studio/codex
- alibabacloud.comhttps://www.alibabacloud.com/help/en/model-studio/coding-plan
Newsletter
New models, set up the day they ship
One email per week. New model releases, the coding tools that support them and how to wire them up.