Use Alibaba Cloud Model Studio models in Codex.
Quick Start
- 1
Open or create the configuration file
- macOS / Linux:
~/.codex/config.toml - Windows:
C:\Users\<username>\.codex\config.toml
- macOS / Linux:
- 2
Configure the model
- Token Plan
- Pay-as-you-go
- Coding Plan
ReplaceOPENAI_API_KEYwith your Token Plan API Key:- Token Plan Personal Edition: Create or view API Key
- Token Plan Team Edition: Assign a seat and get the API Key
- 3
Verify
Run the following command in your project directory:
Chat Completions configuration
Codex 0.94.0 and later support only the Responses API. If you use Codex 0.93.0 or an earlier version, or your model supports only Chat Completions, use the following configuration. For the configuration file path, see Quick Start.
- Token Plan
- Pay-as-you-go
- Coding Plan
OPENAI_API_KEY with your Token Plan API Key:- Token Plan Personal Edition: Create or view API Key
- Token Plan Team Edition: Assign a seat and get the API Key
Use CC Switch
CC Switch is a community open-source desktop GUI that switches between API Keys or billing plans.
Add a provider
- 1In the CC Switch toolbar, select the Codex icon, click + to open Add provider, select the tab for your billing plan, fill in the configuration, and click Add.
- Token Plan
- Pay-as-you-go
- Coding Plan
- Provider name: Bailian-Token Plan
- API Key: Get from console
- Endpoint:
https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
- 2Expand Advanced options and enter a model from the supported models for your plan, such as
qwen3.8-max. - 3Click Enable next to the provider, then reopen the terminal and run
codexfor the configuration to take effect.
Error Codes
If you encounter errors during configuration, refer to the FAQ documentation for your billing plan:
- Token Plan: Personal Edition FAQ · Team Edition FAQ
- Pay-as-you-go: Error codes
- Coding Plan: Coding Plan FAQ
FAQ
How do I use a savings plan with pay-as-you-go?
How do I use a savings plan with pay-as-you-go?
What should I do if a third-party tool reports "domestic models not supported" or "check rejected / Bad request (400)"?
What should I do if a third-party tool reports "domestic models not supported" or "check rejected / Bad request (400)"?
~/.codex/config.toml as described in Quick Start, without relying on the third-party tool's health check. After configuration, follow Verify to start Codex; a normal response means China (mainland) models are working. What should I do if I get a wire_api configuration error?
What should I do if I get a wire_api configuration error?
wire_api = "chat". Depending on the version, you may see one of the following errors:wire_api = "chat" is no longer supportedunknown configuration field wire_api
- Error
wire_api = "chat" is no longer supported: Changewire_apitoresponsesand verifybase_url. - Error
unknown configuration field wire_api: Removewire_apifrom the corresponding provider section in~/.codex/config.toml. - To continue using Chat Completions, install Codex 0.93.0 or an earlier version (such as 0.80.0).
What should I do if I get the error unexpected status 401 Unauthorized?
What should I do if I get the error unexpected status 401 Unauthorized?
- The API Key belongs to another plan (Token Plan, Coding Plan, and Pay-as-you-go keys are not interchangeable).
- The subscription has expired.
- The API Key was copied incorrectly (incomplete, extra spaces, or typo).
- Confirm that you are using the API Key for the selected plan.
- Check the plan management page for subscription expiration.
- Re-copy the API Key and make sure it is complete with no spaces.
- If the error persists, reset the API Key on the plan management page and configure the new key.
What should I do if I get the error unexpected status 404 Not Found?
What should I do if I get the error unexpected status 404 Not Found?
base_url or wire_api in the configuration file is incorrect.Solution: Make sure base_url and wire_api match the configuration for your plan. See Quick Start. What should I do if I get the error "stream disconnected before completion: stream closed before response.completed"?
What should I do if I get the error "stream disconnected before completion: stream closed before response.completed"?
- The conversation thread is too long and context compaction fails.
- The network is unstable and the SSE or WebSocket connection drops.
- The server is overloaded or rate limiting terminates the connection early.
- Start a new conversation thread to avoid excessive context accumulation.
- Check network stability. Disable VPN or proxy and retry.
- Wait and retry. Codex has a built-in retry mechanism that resolves most transient failures.
What should I do if I get a 429 rate limit or quota error?
What should I do if I get a 429 rate limit or quota error?
- Request rate limit (
429 Requests rate limit exceeded): too many requests in a short period. - Quota exhausted (
429 Allocated quota exceededorYour token-plan quota has been exhausted): the monthly Token Plan quota is used up.
- Request rate limit: wait one minute and reduce the request rate.
- Quota exhausted: wait for the next subscription month, purchase a usage package (quota automatically deducts from the package after the monthly quota is used up), or upgrade the plan. The reset time in the error message (such as
The quota will reset at HH:MM:SS UTC) is in UTC; add 8 hours to convert to Singapore time (CST).