Goal of this guide: install OpenAI Codex CLI on macOS and connect it to your own MYAI168 API, using gpt-6.1-sol.
Codex speaks the OpenAI format, so it connects to the MYAI168 "OpenAI-compatible endpoint" with gpt-6.1-sol.
Endpoint https://www.myai168.com/en/api/openai/v1
Model gpt-6.1-sol
Have your MYAI168 API key ready (with cc-switch, cc-switch writes it into the Codex settings; with the manual setup it is supplied through the MYAI168_API_KEY environment variable — see "2-B"). Node.js is only needed for the npm install method — the officially preferred standalone installer does not need Node.
Officially preferred: the standalone installer (no Node.js needed; official docs https://learn.chatgpt.com/docs/codex/cli):
curl -fsSL https://chatgpt.com/codex/install.sh | sh
codex --version
Alternative: npm (requires Node.js):
npm install -g @openai/codex
source ~/.zshrc
codex --version
For installing cc-switch and a tour of its interface, see the cc-switch macOS page.
MYAI168; API Key = your key; API Request URL https://www.myai168.com/en/api/openai/v1; Model Name gpt-6.1-sol (the custom template may default to another model — change it to this).cc-switch (v3.20.1 and later) writes the endpoint, the model and the key to ~/.codex/config.toml — the key goes in the experimental_bearer_token field of the provider table, so no environment variable is needed. ~/.codex/auth.json is reserved for the official ChatGPT account login and never holds the MYAI168 key.
Note: by default, switching to a third-party provider such as MYAI168 makes cc-switch delete ~/.codex/auth.json (the official ChatGPT login). If you also sign in to Codex with a ChatGPT account, first turn on "Keep official login for direct switches" in the cc-switch settings. If Codex starts with a warning that disable_response_storage is ignored, it comes from an old line in the cc-switch custom template and does not affect usage.
Check the result (base_url should be the URL above and model should be gpt-6.1-sol; the output contains your key, so do not screenshot or share it):
cat ~/.codex/config.toml
If you are not using cc-switch (or cc-switch did not write the file), use the manual method. Copy the entire block below, paste it, and press Enter (the first line must start with cat >):
mkdir -p ~/.codex
cat > ~/.codex/config.toml << 'EOF'
model = "gpt-6.1-sol"
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:
cat ~/.codex/config.toml
Then store the key in an environment variable (Codex reads the variable named in env_key; replace your-key with your real key):
echo 'export MYAI168_API_KEY="your-key"' >> ~/.zshrc
source ~/.zshrc
echo "[$MYAI168_API_KEY]"
The last line should print your key (not an empty []).
Key point: env_key takes the environment variable NAME, MYAI168_API_KEY, not the key string itself.
cd into a test folder before starting (not your home directory):
mkdir -p ~/cc-test
cd ~/cc-test
codex
On first run it asks whether to trust the folder → 1. Yes.
Verify: once inside codex, ask a question that requires actual computation:
What is 123456 times 789? Reply with the number only.
If it answers 97406784 and the status bar shows gpt-6.1-sol, the connection works.
(Do not verify with "who are you" — model self-identification is unreliable; whether the API usage on the Developer API Key page goes up is authoritative.)
source ~/.zshrc or reopen the terminal; for npm installs that still fail, find the global folder with npm prefix -g and add its bin directory to PATH.model in config.toml is gpt-6.1-sol (list accepted models with GET https://www.myai168.com/en/api/openai/v1/models).model back to gpt-6.1-sol or pick another GPT-6 / GPT-5.6 model; the gpt-5.5 and gpt-5.4 families produce this message with the current Codex release.base_url is exactly https://www.myai168.com/en/api/openai/v1 (do not append /responses and do not drop /v1). This site's endpoint supports the Responses API that Codex uses directly, so cc-switch local routing is not needed.echo "[$MYAI168_API_KEY]" to check it has a value (if empty, export it again as in "2-B" and run source ~/.zshrc)./model inside a conversation; or change the model line in config.toml. One-off temporary switch: codex -c model='"model-name"'Update Codex (standalone-installer installs: rerun the official install command; npm installs: use install @latest, not npm update -g):
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# npm installs: npm install -g @openai/codex@latest
With cc-switch: update the API Key on the card and click "Enable" again. Manual setup: update the export MYAI168_API_KEY line in ~/.zshrc, then run source ~/.zshrc to apply.
~/.codex/config.toml
Everything below is optional and goes in ~/.codex/config.toml. If you manage Codex with cc-switch, note that re-enabling or switching a provider rewrites this file and can overwrite your additions; when you need the advanced settings to stick, manage the file by hand as in step 2-B.
With Codex, use the GPT-6 family — gpt-6.1-sol (the default in this guide), gpt-6-sol, gpt-6-luna, gpt-6-astra — or the GPT-5.6 family (IDs are in the model list mentioned under "4. Quick Troubleshooting"). Switch with /model inside a conversation or change model in the config file. The gpt-5.5 and gpt-5.4 families return HTTP 400 with the current Codex release, so do not pick them.
Higher effort gives more careful answers at the cost of more output and usage. Add one line to the config file, or adjust it with /model in a conversation; the allowed values depend on the model, commonly low / medium / high:
model_reasoning_effort = "medium"
Type /permissions in a conversation to choose how much Codex may do on its own, or set it in the config file:
approval_policy = "on-request"
sandbox_mode = "workspace-write"
Values of sandbox_mode: read-only, workspace-write (may change files inside the working directory) and danger-full-access (no limits — do not use it on machines that matter).
codex exec "Check this project for unused functions"
codex exec --json "List the TODOs in this project"
codex exec -o result.txt "Summarise the recent changes"
codex exec exits when the task is done; --json prints JSON events line by line and -o writes the final answer to a file; add --skip-git-repo-check when you are not inside a Git repository.
codex resume
codex resume --last
Without arguments it lists the conversations of the current folder; --last continues the most recent one.
Type /init in a conversation inside your project and Codex creates AGENTS.md. Put build and test commands, coding style and caveats there; every later conversation picks it up automatically.
Save another set of settings as ~/.codex/fast.config.toml (the fast in the file name is the profile name) and start Codex with --profile fast to layer it over the base config:
model = "gpt-6-luna"
model_reasoning_effort = "low"
codex --profile fast
High-effort answers can take a long time to start streaming. If you see the connection being dropped and retried, add one line inside the existing [model_providers.myai168] block to extend the wait beyond the default 5 minutes (milliseconds):
stream_idle_timeout_ms = 600000
To let Codex CLI use this site's AI modules as tools, see the "Codex CLI" section of the MYAI168 MCP CLI page.