Goal of this guide: install OpenAI Codex CLI on a Linux desktop (Ubuntu / Debian as the example) 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
First check whether node --version and npm --version print version numbers. If not, install (Ubuntu / Debian):
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
Or use nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc
nvm install --lts
echo $SHELL
/bash → use ~/.bashrc/zsh → use ~/.zshrcWherever this guide says "shell config file" below, substitute yours.
Officially preferred: the standalone installer (no Node.js needed — you can skip the Node install in "0.5"; official docs https://learn.chatgpt.com/docs/codex/cli):
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Alternative: npm (requires Node.js). Do not use sudo (it causes permission problems); if you hit an npm permission error, point the npm global directory to your own home directory before installing:
npm install -g @openai/codex
Check:
codex --version
For installing cc-switch and a tour of its interface, see the cc-switch Linux 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), write it manually with a heredoc (paste the whole block and press Enter):
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
Then store the key in an environment variable (Codex reads the variable named in env_key; write it into your shell config file — use ~/.zshrc instead of ~/.bashrc for zsh; replace your-key with your real key):
echo 'export MYAI168_API_KEY="your-key"' >> ~/.bashrc
source ~/.bashrc
echo "[$MYAI168_API_KEY]"
The last line should print your key (not an empty []).
cd into a test folder before starting (not your home directory):
mkdir -p ~/cc-test
cd ~/cc-test
codex
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 ~/.bashrc (or 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).code_interpreter, file_search or image_generation). All tools Codex uses by default are supported; update Codex to the latest release and remove any such tools you added.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 source the file)./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 ~/.bashrc (or ~/.zshrc), then source it 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, the GPT-6 family is recommended — gpt-6.1-sol (the default in this guide), gpt-6-sol, gpt-6-luna, gpt-6-astra — or the GPT-5.6 family; the gpt-5.5 and gpt-5.4 families also work (IDs are in the model list mentioned under "4. Quick Troubleshooting"). Switch with /model inside a conversation or change model in the config file.
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.