The Codex Command Line Interface (CLI) is a tool developed by OpenAI to interact with the Codex models via terminal commands. It enables developers to run code generation, debugging, and documentation tasks programmatically. To use the Codex CLI, especially its net command for network-related operations, you must have Node.js installed and an OpenAI API key. This guide walks you through installing the CLI, authenticating, and running the net command successfully.
What You'll Need
- Node.js version 16 or higher (check with
node --version) - NPM (comes with Node.js; verify with
npm --version) - An OpenAI API key (create one at platform.openai.com)
- A terminal application (Terminal on macOS/Linux, PowerShell or Command Prompt on Windows)
- Stable internet connection for API calls
Step-by-Step
- Install the Codex CLI globally: Run the command
npm install -g @openai/codex-cliin your terminal. This installs the latest stable version of the CLI. Wait until you see a success message likeadded X packages in Ys. - Verify installation: Type
codex --versionand press Enter. You should see a version number (e.g.,0.4.2). If you seecommand not found, your PATH may not include NPM’s global bin directory—skip to the Troubleshooting section for help. - Set your OpenAI API key: Run
codex configure. The CLI will prompt you to enter your API key. Paste it (no output will appear as you type for security) and press Enter. Confirm the key is saved by checking the~/.codex/config.jsonfile (macOS/Linux) or%USERPROFILE%\.codex\config.json(Windows). It should contain a line like"apiKey": "sk-...". - Run a basic test command: Try
codex --helpto list available commands. Then runcodex net --helpto see options for the network module. You should see subcommands likeping,probe, orresolve. - Test the
netcommand: Executecodex net ping openai.com. This sends a network diagnostic request to OpenAI’s server using the Codex backend. A successful response shows latency in milliseconds and confirms reachability (e.g.,Ping to openai.com: 42ms). - Use
net resolvefor DNS lookup: Runcodex net resolve api.openai.com. The CLI returns the IP addresses associated with the domain (e.g.,104.244.42.1). This helps verify DNS resolution through Codex’s infrastructure. - Run
net probefor latency testing: Executecodex net probe api.openai.com --count 3. This sends three ICMP-like probes and reports average, min, and max round-trip times. Note: The exact behavior depends on the backend’s current implementation—checkcodex net probe --helpfor supported flags.
Common Mistakes
Many users skip verifying the API key format or accidentally include extra characters. OpenAI keys always start with sk- and are ~51 characters long. Including spaces, quotes, or line breaks in the config file will cause authentication errors. Another frequent error is using Node.js version 14 or earlier, which lacks support for modern JavaScript features required by the CLI. Also, some terminals (especially older Windows Command Prompt versions) may not display colored output or long command lines correctly—use PowerShell or Windows Terminal instead.
Tips
Save your API key in an environment variable (OPENAI_API_KEY) instead of using codex configure if you prefer not to store it on disk. The CLI will use this variable automatically. For repeated use, create a shell alias like alias codex-net='codex net ping' to reduce typing. When troubleshooting, always run commands with --verbose (e.g., codex net ping example.com --verbose) to see raw request/response logs. This helps identify if the issue is network-related or due to API rate limits.
Troubleshooting
If codex is not recognized, first check npm config get prefix and ensure that directory is in your system’s PATH. On macOS/Linux, add export PATH="$(npm config get prefix)/bin:$PATH" to your .bashrc or .zshrc. On Windows, add the path via System Properties > Environment Variables. If you see 401 Unauthorized, double-check your API key in the OpenAI dashboard—revoked or expired keys cause this. Also, ensure your system clock is correct, as NTP time sync issues can break token validation. If codex net ping hangs or times out, verify your firewall or antivirus isn’t blocking outbound HTTPS (port 443) connections. Try using a different network (e.g., mobile hotspot) to isolate the issue. If the CLI crashes with ENOTFOUND or DNS errors, the target domain may be unreachable through Codex’s internal network—retry with api.openai.com instead, as it’s consistently accessible.
Frequently Asked Questions
Does the Codex CLI work offline?
No. The CLI requires an active internet connection to reach OpenAI’s servers for both authentication and command execution, including the net module.
Is the net command free to use?
The Codex CLI itself is free to install, but using the net command consumes API credits from your OpenAI account. Check your usage at platform.openai.com/usage to monitor costs.
Can I use codex net with private IP addresses like 192.168.1.1?
No. The net commands route through OpenAI’s infrastructure, which does not have access to your local network. Only public IP addresses or domain names will work.
What happens if I exceed my API rate limit?
The CLI returns a 429 Too Many Requests error. Wait for the Retry-After period (usually 60 seconds) before trying again. Reduce command frequency or upgrade your OpenAI plan for higher limits.
Does codex net resolve support IPv6?
Yes. The command returns both A (IPv4) and AAAA (IPv6) records if the domain has them. If only IPv4 is available, it lists just the IPv4 address.
Can I run codex net on a headless server without a GUI?
Yes. The CLI is fully terminal-based and designed for headless environments like cloud VMs or Docker containers. No graphical interface is required.