Introduction
Codex CLI is OpenAI’s open-source terminal coding agent that can read and write files, run commands, fix bugs, and complete full coding tasks directly in the command line. By connecting through APIMart, you can freely use multiple models — including GPT and Claude — in Codex CLI, with more flexible and competitive pricing.Prerequisites
Before you begin, make sure you have:- Installed Node.js Download and install from the Node.js website (latest LTS, v20 or newer recommended) to install Codex CLI via npm
-
Obtained an APIMart API Key
Log in to the APIMart Console to get your API key (starts with
sk-)
Tip: If you don’t have an APIMart account yet, please register at APIMart first and obtain your API key.
Step 1: Install Codex CLI
Choose any of the following methods to install:- npm (Recommended)
- Homebrew (macOS)
Install globally with npm — works on all operating systems:
If you run into permission issues, prepend
sudo (macOS / Linux).Verify the installation
After installing, run the following command to confirm:Step 2: Configure the APIMart API
Codex CLI manages model providers via configuration files under the~/.codex/ directory. All we need to do is add a custom provider pointing to APIMart.
2.1 Locate the config directory
- macOS / Linux:
~/.codex/ - Windows:
C:\Users\<username>\.codex\
If the directory does not exist, run
codex once in your terminal then press Ctrl + C to exit — it will be created automatically.2.2 Configure the API key
In the config directory, create or edit theauth.json file and fill in your APIMart key:
2.3 Configure the model provider
In the config directory, create or edit theconfig.toml file and add the APIMart provider:
After saving both files, restart Codex CLI for the changes to take effect.
Step 3: Get Started
Verify the configuration
In any project directory, run the following command to confirm everything is wired up:401 / 403 errors, refer to the FAQ section below.
Interactive mode
Runcodex directly to enter the interactive UI — ideal for full coding tasks:
Approval modes
On first run, Codex will ask you to pick an approval level:
We recommend starting with Auto mode. Type
/approvals in the interactive UI to change it anytime.
Switch models
In the interactive UI, type/model to switch quickly, or change the model field in config.toml and restart.
Supported Models
For Codex CLI, the following GPT-5 series models are recommended:Common Commands
Frequently used commands and shortcuts in Codex CLI:FAQ
Q1: A ChatGPT sign-in screen appears after launch?
If you see “Sign in with ChatGPT” or similar after launch, the configuration didn’t take effect. Troubleshooting:- Make sure both
config.tomlandauth.jsonare inside~/.codex/ - Check that
model_providerinconfig.tomlis set toapimart - Check that
auth.jsonis valid JSON and the key is filled in completely
Q2: Getting 401 / 403 errors?
Also make sure
base_url is set to https://api.apimart.ai/v1, not the official OpenAI URL.
Q3: Connection failed?
- Check your network connection
- Make sure
base_urlinconfig.tomlis correct - If you’re behind a proxy, ensure it allows access to
api.apimart.ai
Q4: wire_api = "chat" is no longer supported?
Recent Codex CLI versions (0.84.0 and later) have removed the chat protocol. Update wire_api in config.toml to responses:
Q5: Tool calls or runs are failing?
Make surewire_api in config.toml is set to responses. If you still hit compatibility issues, switch to a recommended GPT-5 series model (e.g. gpt-5.5, gpt-5.3-codex) — they pair more reliably with Codex CLI.
Q6: Use environment variables instead of auth.json?
You can also configure the key via an environment variable. Change the provider block inconfig.toml to:
APIMART_API_KEY to your APIMart key. auth.json is no longer required in this setup.
Q7: How do I switch models?
Two ways:- In the interactive UI: Type
/modelto switch - Edit the config: Change the
modelfield inconfig.tomland restart Codex CLI
Q8: How do I check usage and billing?
Log in to the APIMart Console to view API call statistics, token consumption details, and cost trends.Support and Help
If you run into any issues while using Codex CLI:- 📚 APIMart Documentation Center
- 💬 Discord Community
- 🐦 Twitter @APIMart_
- 📧 Technical support: zhihong@apimart.ai
Get Started with APIMart
Sign up for APIMart now, get your API key, and experience a multi-model programming assistant in Codex CLI!