• Home
  • Search
  • AI Services
  • Models
  • Writing
  • Multimedia Creation
  • Translation & Others
Home›Developer Center›Codex CLI macOS

Codex CLI macOS

API DocumentationAPI Quick StartOpenAI ChatGPT APIAnthropic (Claude) APIGoogle Gemini APIGoogle Search APIGoogle News APIOpenRouter APIAPI Pricing
CLI & Agent Guidescc-switch macOScc-switch Windowscc-switch LinuxOpenCode macOSOpenCode WindowsOpenCode LinuxOpenClaw macOSOpenClaw WindowsOpenClaw LinuxHermes Agent macOSHermes Agent WindowsHermes Agent LinuxClaude Code CLI macOSClaude Code CLI WindowsClaude Code CLI LinuxCodex CLI macOSCodex CLI WindowsCodex CLI Linux
MYAI168 API & MCPMYAI168 Chat API GuideMYAI168 MCP CLIMYAI168 MCP Web & App
No matching questions on this page.Search the whole site
Installation Overview (macOS)

OpenAI Codex CLI Installation and MYAI168 Setup Guide — macOS

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 and Model

Endpoint   https://www.myai168.com/en/api/openai/v1
Model      gpt-6.1-sol

Important Security Notes

  • Codex can read, write, and execute files in the working directory. In real use, cd into a project folder before starting it; do not start it in your home directory.
  • Treat your API key like a password and never share it. If it leaks, delete it on the Developer API Key page and create a new one.
  • Verify with a "math question", not with "who are you" (model self-identification is unreliable); also check that the API usage on the Developer API Key page goes up.

Prerequisites

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.

1. Install

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
2. Configure MYAI168 (Method A: cc-switch, recommended)

For installing cc-switch and a tour of its interface, see the cc-switch macOS page.

  1. Open cc-switch, select "Codex" in the app switcher at the top left, and click "+" (Add Provider) at the top right.
  2. Set Provider Preset to "Custom Configuration".
  3. Fill in: Provider Name 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).
  4. Leave the Upstream Format under Advanced Options as "OpenAI Responses API (Native)"; local routing is not needed because this site's endpoint supports the Responses API directly.
  5. Click "Add", then click "Enable" on the MYAI168 card.

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
2-B. Configure MYAI168 (Method B: manual, fallback)

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.

3. Launch and Verify (macOS)

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

4. Quick Troubleshooting
  • codex command not found → run 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.
  • No pricing info! Please use other models! / model does not exist → the model ID is not on this site's accepted list; make sure model in config.toml is gpt-6.1-sol (list accepted models with GET https://www.myai168.com/en/api/openai/v1/models).
  • HTTP 400 with "Server-side/hosted tools ... are not supported" → the selected model cannot be used with Codex. Set 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.
  • 404 responses → make sure 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.
  • 401 / unauthorized → the key is wrong, or the key has reached its credit limit (API key credit limit reached!). If you used cc-switch, re-enter the API Key on the card and click "Enable" again; for the manual setup, run echo "[$MYAI168_API_KEY]" to check it has a value (if empty, export it again as in "2-B" and run source ~/.zshrc).
  • Status bar shows default / replies look like the official model → the config was not applied. Most common cause: env_key was filled with the key string instead of the variable name.
  • Switch models → use /model inside a conversation; or change the model line in config.toml. One-off temporary switch: codex -c model='"model-name"'
5. Maintenance

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

Rotate the API Key

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.

Config File Location

~/.codex/config.toml

Official Docs

  • https://learn.chatgpt.com/docs/codex/cli
  • https://learn.chatgpt.com/docs/config-file/config-reference
Advanced settings and useful commands

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.

Models you can use

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.

Reasoning effort

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"

Permissions and sandbox

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

Run without the interactive UI (scripts, schedules)

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.

Resume an earlier conversation

codex resume
codex resume --last

Without arguments it lists the conversations of the current folder; --last continues the most recent one.

Project instructions: AGENTS.md

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.

Multiple setups (profiles)

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

Waiting longer for slow responses

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

Connect MYAI168 MCP

To let Codex CLI use this site's AI modules as tools, see the "Codex CLI" section of the MYAI168 MCP CLI page.

‹ Previous page: Claude Code CLI LinuxNext page: Codex CLI Windows ›
↑
Question link copied.

Other FAQ pages

API Documentation

  • API Quick Start
  • OpenAI ChatGPT API
  • Anthropic (Claude) API
  • Google Gemini API
  • Google Search API
  • Google News API
  • OpenRouter API
  • API Pricing

CLI & Agent Guides

  • cc-switch macOS
  • cc-switch Windows
  • cc-switch Linux
  • OpenCode macOS
  • OpenCode Windows
  • OpenCode Linux
  • OpenClaw macOS
  • OpenClaw Windows
  • OpenClaw Linux
  • Hermes Agent macOS
  • Hermes Agent Windows
  • Hermes Agent Linux
  • Claude Code CLI macOS
  • Claude Code CLI Windows
  • Claude Code CLI Linux
  • Codex CLI Windows
  • Codex CLI Linux

MYAI168 API & MCP

  • MYAI168 Chat API Guide
  • MYAI168 MCP CLI
  • MYAI168 MCP Web & App