Codex CLI Installation and Configuration Guide

Complete guide to installing and configuring Codex CLI with AI Code Editor

10 min read

What is Codex CLI?

Codex CLI is OpenAI's official command-line interface for AI-powered code generation and assistance. It provides developers with powerful AI capabilities directly in their terminal, enabling faster development workflows and intelligent code completion.

With AI Code Editor integration, you can use Codex CLI with our optimized API endpoints, enjoying stable service and competitive pricing.

Prerequisites

System Requirements

  • Node.js version 18.0.0 or higher
  • npm or pnpm package manager
  • macOS, Linux, or Windows operating system
  • Terminal with UTF-8 support

AI Code Editor Account

You need an AI Code Editor account with an active API key. If you don't have one yet:

  1. Visit aicodeditor.com/dashboard
  2. Sign up or log in to your account
  3. Navigate to API Keys section
  4. Generate a new API key (format: cr_xxxxxxxxxx)

Installation

Step 1: Install Codex CLI

Install the Codex CLI globally using npm:

npm install -g @openai/codex@latest

Or using pnpm:

pnpm add -g @openai/codex@latest

Step 2: Verify Installation

Verify that Codex CLI has been installed successfully:

codex --version

You should see the version number of Codex CLI if the installation was successful.

Configuration

Step 1: Configure Codex Settings

Create or edit the configuration file at ~/.codex/config.toml:

model_provider = "aicodeditor"
model = "gpt-5-codex"
model_reasoning_effort = "high"
disable_response_storage = true
preferred_auth_method = "apikey"

[model_providers.aicodeditor]
name = "aicodeditor"
base_url = "https://codex.aicodeditor.com/v1"
wire_api = "responses"

Configuration Explanation:

  • model_provider: Set to "aicodeditor" to use AI Code Editor's API
  • model: Specifies the AI model to use
  • model_reasoning_effort: Set to "high" for best results
  • disable_response_storage: Ensures privacy by not storing responses
  • preferred_auth_method: Use API key authentication
  • base_url: AI Code Editor's Codex API endpoint

Step 2: Configure API Authentication

Create or edit the authentication file at ~/.codex/auth.json:

{
    "OPENAI_API_KEY": "cr_xxxxxxxxxx"
}

Important: Replace cr_xxxxxxxxxx with your actual API key from AI Code Editor. This should be the same API key you use for Claude Code.

Step 3: Set File Permissions (Unix/Linux/macOS)

Ensure your authentication file has appropriate permissions:

chmod 600 ~/.codex/auth.json

Basic Usage

Starting Codex CLI

To start Codex CLI in your project directory:

cd /path/to/your/project codex

Common Commands

CommandDescription
codexStart Codex CLI in interactive mode
codex --helpDisplay help information
codex --versionShow version information
codex --configOpen configuration editor

Example Usage

Here's a simple example of using Codex CLI to generate code:

# Start Codex CLI
$ codex
# Ask Codex to generate a function
> Create a Python function to calculate fibonacci numbers
# Codex will generate the code for you

Troubleshooting

Common Issues and Solutions

1. Authentication Failed

Error: "Authentication failed" or "Invalid API key"

Solution:

  • Verify your API key is correct in ~/.codex/auth.json
  • Ensure the API key starts with cr_
  • Check that your API key is active in the AI Code Editor dashboard

2. Configuration File Not Found

Error: "Config file not found"

Solution:

  • Create the ~/.codex directory if it doesn't exist
  • Ensure both config.toml and auth.json files are present
  • Check file permissions are correct

3. Connection Timeout

Error: "Request timeout" or "Connection failed"

Solution:

  • Check your internet connection
  • Verify the base_url in config.toml is correct
  • If behind a proxy, configure proxy settings

Getting Help

If you encounter issues not covered here:

Start Using Codex CLI with AI Code Editor

Experience the power of AI-assisted coding with Codex CLI and our optimized API service