https://api.laozhang.ai/v1 and the Responses wire API, and keep the key in an environment variable.
Install Codex CLI
Install it globally with npm (Node.js required):Configure LaoZhang API
1
Set the key as an environment variable
Add the key to your shell profile so every new terminal can read it:Use
~/.bashrc for bash. In Windows PowerShell, run setx LAOZHANG_API_KEY "YOUR_LAOZHANG_API_KEY" and open a new terminal.2
Edit config.toml
Open or create
~/.codex/config.toml and add:model_providermust match the name in[model_providers.laozhang].- Don’t reuse the name of a Codex built-in provider, such as
openaiorollama. The full list is in the Codex configuration docs. env_keytakes the name of the environment variable, not the key itself.
3
Send a test request
From any directory, run:If it prints
connected, the setup works. Run codex in a project directory to start an interactive session.Use it in the Codex app and IDE extensions
The Codex desktop app, IDE extensions such as the one for VS Code, and the CLI all read the same~/.codex/config.toml. An app or extension launched from the Dock or Start menu may not see variables set in your terminal. In that case, sign in with your key instead, which stores it in Codex’s own credentials:
- This uses Codex’s built-in OpenAI provider, so you don’t need the
[model_providers.laozhang]table ormodel_providerfrom above. Pick one setup or the other. - The CLI, IDE extensions, and the desktop app share these credentials. In an IDE extension you can also choose Use API Key and paste the key there.
- Run
codex login statusto see which sign-in method is active.
Choose a model
Codex CLI calls models through the Responses API, so GPT-6 models can call tools without any reasoning-effort change.
To switch for one session, add
-m, for example codex -m gpt-6-astra. For model IDs Codex doesn’t recognize, such as gpt-5.4-mini, it warns Model metadata ... not found. The model still works, but Codex falls back to default values for details like context length. Prices are in the model catalog.
Cut costs with the Codex Discount group
For personal projects and everyday coding, you can give Codex its own key from theCodex Discount group. The six models below are billed at 30% of the catalog price, for input, output and cache reads alike.
1
Create a Codex Discount key
In Tokens, create a key in the
Codex Discount group with the Usage-first billing mode.2
Store it in its own environment variable
If other tools still use a
default key, leave LAOZHANG_API_KEY alone and add a second variable:3
Point config.toml at that variable
Change If you use the login setup for the Codex app or IDE extensions, run
env_key to the new variable and set model to one of the six models:printenv LAOZHANG_CODEX_KEY | codex login --with-api-key instead.- Billing follows the usage the route reports. Reasoning tokens count as output, so the same task usually reports more output tokens than the official API, and cache hits can be lower. The real cost is therefore not simply 30%. Check each request’s usage and charge in call logs.
max_output_tokensis not enforced, so you can’t use it to cap a single response.- Both Responses and Chat Completions work. Codex uses Responses, so it works as is. Since 2026-11-18, Chat Completions requests and Responses requests without
instructionsno longer count extra input tokens; a plain “hi” counts as 1 input token. - Only the six models above are included.
gpt-6-luna,gpt-5.6-luna,gpt-5.4-miniand other models need adefaultkey.
FAQ
I get a 503 “Current group codex_saver has no available channels”
The request used aCodex Discount key with a model outside the group, such as gpt-6-luna. Set model to one of the six models in the table above, or switch to a default key.
I get a 401 or a missing environment variable error
Codex reads the key only from the variable named inenv_key. In the same terminal you run Codex from, run test -n "$LAOZHANG_API_KEY" && echo set to confirm the variable is set. After editing your shell profile, open a new terminal. In the desktop app or an IDE extension, use the sign-in setup instead.
I get a 404 or “stream disconnected”
Make surebase_url is https://api.laozhang.ai/v1, without a trailing / or /responses. If it still fails, check call logs to see whether the request arrived, and see Invalid API key or 404.