Goal of this guide: install OpenAI Codex CLI on macOS and connect it to your own MYAI168 API, using gpt-5.5.
Codex uses the OpenAI format, so what you connect to is MYAI168's "OpenAI-compatible endpoint". The key reuses the MYAI168_API_KEY you previously exported to the shell — no need to set it again.
Endpoint https://www.myai168.com/en/api/openai/v1
Model gpt-5.5
Key: assume MYAI168_API_KEY is already exported in ~/.zshrc (added earlier when setting up other tools). How to confirm:
echo "[$MYAI168_API_KEY]"
It should print [your key string], not an empty [].
npm install -g @openai/codex
After installing, make the command available and confirm:
source ~/.zshrc
codex --version
Create the settings folder and config file. Copy the whole block below, paste it, and press Enter once (note: the first line must start with cat >):
mkdir -p ~/.codex
cat > ~/.codex/config.toml << 'EOF'
model = "gpt-5.5"
model_provider = "myai168"
[model_providers.myai168]
name = "MYAI168"
base_url = "https://www.myai168.com/en/api/openai/v1"
env_key = "MYAI168_API_KEY"
wire_api = "responses"
EOF
Confirm the content is correct:
cat ~/.codex/config.toml
Critical check: the env_key line must be MYAI168_API_KEY (the "name" of the environment variable), not the key string itself. This is the easiest field to get wrong, so be sure to verify it.
model: the model id to use.model_provider: points to the id of the custom provider below.base_url: the API root path, ending in /v1, with no trailing slash.env_key: the "environment variable name" Codex reads at runtime and sends as the Bearer token.wire_api: Codex currently uses "responses".Enter a project / test folder before launching (not your home directory):
mkdir -p ~/cc-test
cd ~/cc-test
codex
On first run it asks whether to trust this folder → choose 1. Yes, continue.
Verify: type a question that "requires actual computation or action" to test, for example:
What is 123456 times 789? Reply with the number only.
If it computes the correct answer (97406784), the connection succeeded and the model is working.
Note: do not verify with "who are you / what model are you" —— a model's answer about its own identity is unreliable and often reports its training-time identity (e.g. claiming to be some other model), which does not reflect the actual model connected or whether the connection works. To determine the real identity, rely on the API call records in the MYAI168 console.
Once set up, just enter your project folder and type codex as usual:
cd ~/your-project-folder
codex
Temporarily switch model (one-off, without changing the config file):
codex -c model='"model-name"'
Permanent switch: edit the model line in ~/.codex/config.toml.
Usually the config was not applied correctly. The most common cause: env_key was filled with the key string instead of the variable name. Change it to env_key = "MYAI168_API_KEY".
This is normal — a model's self-perception is unreliable. Verify with a computation problem or an actual action like creating a file, and cross-check with the MYAI168 console call records.
A file permission / ownership issue. Fix ownership first, then rebuild:
sudo chown -R $(whoami) ~/.codex
Then rerun the cat > block in section 2.
The cat > on the first line was dropped during pasting, so it executed the file path directly. Paste again and make sure the first line starts with cat >.
That model is not registered on this MYAI168 endpoint. Switch to a model the endpoint supports.
The key was not read, or Codex is validating the key prefix. First confirm echo "[$MYAI168_API_KEY]" has a value; if necessary, add one line in the provider block: requires_openai_auth = false.
echo "[$MYAI168_API_KEY]" — printing [string] is normal, [] means empty (not set).
Update Codex:
npm update -g @openai/codex
~/.codex/config.toml