Install and Configure Codex
Codex Introduction
Section titled “Codex Introduction”Codex is a local AI programming assistant provided by OpenAI that offers intelligent code completion, code explanation, and error fixing capabilities in your local environment. As a local AI coding tool within the OpenAI ecosystem, Codex supports two authentication methods: ChatGPT account and API Key.
Use Cases
Section titled “Use Cases”- OpenAI Ecosystem Integration: If you’re already using ChatGPT or other OpenAI services, Codex integrates seamlessly
- Simple Authentication Preference: Supports direct login with ChatGPT account, no separate API Key configuration needed
- International Network Environment: Best experience in network environments with direct access to OpenAI services
- Hagicode Multi-Model Support: As one of Hagicode’s executor options, supports multi-model switching
Installation
Section titled “Installation”NPM Installation
Section titled “NPM Installation”You can easily install Codex via NPM. Make sure you have Node.js installed.
npm install -g @openai/codexAfter installation, verify the installation with:
codex --versionAuthentication
Section titled “Authentication”Codex supports two authentication methods: ChatGPT account login (recommended) or API Key.
Using ChatGPT Account
Section titled “Using ChatGPT Account”This is the simplest method, requiring no separate API Key configuration.
codex loginAfter running this command, Codex will open a browser to guide you through the ChatGPT account login process.
Using API Key
Section titled “Using API Key”If you prefer to use API Key for authentication, follow these steps.
- Visit OpenAI API Keys page
- Create a new API Key
- Set environment variable:
export OPENAI_API_KEY="your-api-key-here"Or add the following to your Shell configuration file (like ~/.bashrc or ~/.zshrc):
echo 'export OPENAI_API_KEY="your-api-key-here"' >> ~/.bashrcsource ~/.bashrcBasic Usage
Section titled “Basic Usage”First Run
Section titled “First Run”After completing installation and authentication configuration, you can start using Codex:
codexOn first run, Codex will guide you through initial configuration, including:
- Selecting default model
- Configuring proxy settings (if needed)
- Setting preference options
Common Commands
Section titled “Common Commands”Here are the common commands for Codex:
# Start Codex interactive modecodex
# View Codex version informationcodex --version
# View help informationcodex --help
# Login with ChatGPT accountcodex login
# Logoutcodex logout
# View current configurationcodex config
# Run a one-time querycodex ask "How to implement a quicksort algorithm?"Important Notes
Section titled “Important Notes”Network Requirements
Section titled “Network Requirements”Codex needs to access OpenAI services, so there are certain network environment requirements:
- International Network: Use directly without additional configuration
- Domestic Network: Requires proxy configuration or network optimization services
If you’re using Codex in a domestic network environment, it’s recommended to:
- Configure system-level proxy
- Set HTTP/HTTPS proxy environment variables:
export HTTP_PROXY="http://proxy.example.com:8080"export HTTPS_PROXY="http://proxy.example.com:8080"- Or set proxy in Codex configuration file
Pricing Plans
Section titled “Pricing Plans”Codex uses OpenAI’s API services with the following billing methods:
- ChatGPT Plus Subscription: If you have a ChatGPT Plus subscription, you can use Codex without additional payment
- API Pay-as-you-go: When using API Key, billing is based on actual usage. For specific rates, please refer to the OpenAI Pricing page
💡 Tip: For more detailed information, please visit the Codex Official Documentation.