Skip to main content

Overview

OpenAI Codex is an open-source command-line tool (CLI) that serves as a lightweight coding agent, capable of reading, modifying, and running code in the terminal. It’s built on GPT models and optimized for code generation.

System Requirements

  • OS: macOS, Linux (official support), Windows via WSL
  • Node.js: Version 18+
  • npm: Version 10.x.x or higher

Installation

sudo npm install -g @openai/codex@latest
Verify installation:
codex --version

Configuration

Step 1: Set API Key

Temporary (current session):
export OPENAI_API_KEY="sk-your-lemondata-key"
Permanent configuration: Add to ~/.bashrc, ~/.zshrc, or ~/.bash_profile:
export OPENAI_API_KEY="sk-your-lemondata-key"
Then reload:
source ~/.zshrc  # or source ~/.bashrc

Step 2: Configure config.toml

Edit ~/.codex/config.toml:
model = "gpt-4o"
model_provider = "lemondata"

[model_providers.lemondata]
name = "LemonData"
base_url = "https://api.lemondata.cc/v1"
env_key = "OPENAI_API_KEY"
wire_api = "chat"
If the config file doesn’t exist, run codex once to generate it, then edit the file.

Basic Usage

Start interactive mode:
codex
Direct command:
codex "Fix the bug in main.py line 42"
Specify model:
codex -m gpt-4o "Build a REST API server"

Available Models

ModelBest For
gpt-4oComplex coding tasks, architecture
gpt-4o-miniQuick fixes, simple tasks
claude-sonnet-4-5Code review, documentation
deepseek-r1Algorithm design, reasoning

Interactive Commands

CommandDescription
/helpDisplay help
/exit or Ctrl+CExit
/clearClear conversation
/configView configuration
/model <name>Switch model
/tokensView token usage

Verify Configuration

# Check environment variable
echo $OPENAI_API_KEY

# Test API connection
codex "Hello, Codex!"

# View configuration
cat ~/.codex/config.toml

Common Use Cases

Code review:
git diff | codex "Review these code changes"
Generate commit messages:
git diff --staged | codex "Generate a commit message for these changes"
Fix errors:
codex "Fix the TypeScript errors in src/components/"
Explain code:
cat main.py | codex "Explain what this code does"

Troubleshooting

  • Verify base_url in config.toml is exactly https://api.lemondata.cc/v1
  • Check network connectivity
  • Ensure no proxy interference
  • Verify OPENAI_API_KEY environment variable is set
  • Check that the key starts with sk-
  • Ensure the key is active in LemonData dashboard