Skip to content

OpenAI Codex CLI ​ ​

Official OpenAI command-line AI programming tool, supports code generation, file editing, command execution, and more.

Installation ​ ​

Mac / Linux ​ ​

bash

npm install -g @openai/codex

Windows ​ ​

cmd

npm install -g @openai/codex

Requires Node.js 18+

Configuration ​ ​

Mac / Linux ​ ​

Add the following to ~/.bash_profile or ~/.zshrc:

bash

echo 'export OPENAI_API_KEY="sk-xxx"' >> ~/.bash_profile
echo 'export OPENAI_BASE_URL="https://www.fast-api.org/v1"' >> ~/.bash_profile
source ~/.bash_profile

Windows ​ ​

cmd

setx OPENAI_API_KEY "sk-xxx"
setx OPENAI_BASE_URL "https://www.fast-api.org/v1"

Replace sk-xxx with the API Key you obtained from Fast-API.

Usage Example ​ ​

bash

# Start Codex
codex

# Directly provide a task
codex "Create a Python HTTP server"

After starting, describe your task in the interactive terminal. Codex will automatically generate code and execute actions.

FAQ ​ ​

Prompt "invalid api key" ​ ​

Confirm that the OPENAI_API_KEY environment variable is correctly set. Try again after restarting your terminal.

Connection failed or timed out ​ ​

Check if OPENAI_BASE_URL is set to https://www.fast-api.org/v1 (make sure it contains /v1).

Command not found ​ ​

Confirm that the global installation was successful: npm list -g @openai/codex. If issues persist, try reinstalling.

Notes ​ ​

  • Base URL must include /v1: https://www.fast-api.org/v1
  • Restart your terminal after modifying environment variables
  • Codex executes system commands—review its actions for security