Codex CLI

Installation Overview (macOS)

OpenAI Codex CLI Installation and Custom API Setup Guide — macOS

Goal of this guide: install OpenAI Codex CLI on macOS and connect it to your own MYAI168 API, using gpt-5.5.

Key point

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.

Before you begin: prerequisites and security notes

Prerequisites: Node.js and API Key

  • Codex is installed via npm and needs Node.js (18+ recommended; if you already installed Node 24, you are fine).
  • Endpoint and model:
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 [].

Important security notes

  • Codex can read, edit, and execute files in its working directory. In practice, cd into a specific project folder before launching it; do not open it in your home directory (~).
  • Treat your API Key like a password — never leak it. If it is exposed, immediately revoke it in the MYAI168 console and issue a new one.
1. Install Codex CLI
npm install -g @openai/codex

After installing, make the command available and confirm:

source ~/.zshrc
codex --version
2. Configure config.toml to connect to MYAI168

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.

Field descriptions

  • 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".
3. Launch and verify

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.

4. Everyday use

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.

5. Troubleshooting quick reference

Replies look like the official model / the status bar shows default

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".

Testing with "who are you", it claims to be another model

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.

permission denied, cannot write to config.toml

A file permission / ownership issue. Fix ownership first, then rebuild:

sudo chown -R $(whoami) ~/.codex

Then rerun the cat > block in section 2.

Pasting the cat > block says no such file or directory

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 >.

no_pricing_info / no pricing info

That model is not registered on this MYAI168 endpoint. Switch to a model the endpoint supports.

401 / unauthorized

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.

Confirm the key variable has a value

echo "[$MYAI168_API_KEY]" — printing [string] is normal, [] means empty (not set).

6. Maintenance and security

Update Codex:

npm update -g @openai/codex

Replace the API Key (when leaked or for periodic rotation)

  1. Revoke the old key in the MYAI168 console and generate a new one.
  2. Update export MYAI168_API_KEY="new-key" in ~/.zshrc.
  3. Run source ~/.zshrc to apply (Codex reads this variable, so it updates accordingly).
  4. If the same key is used in other tools, remember to update their config files too.

Config file location

~/.codex/config.toml

Official docs

  • https://developers.openai.com/codex/config-advanced
  • https://developers.openai.com/codex/config-reference

Other FAQ pages

  • FAQ
  • Account
  • Features
  • Privacy
  • OpenAI ChatGPT API
  • Anthropic Claude API
  • Google Gemini API
  • Google News API
  • OpenRouter API
  • API Pricing
  • OpenCode
  • OpenClaw
  • Hermes Agent
  • Claude Code CLI
  • MYAI168 MCP CLI
  • MYAI168 MCP Web & App