> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yelinai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Codex CLI Setup Guide

> Configure OpenAI Codex CLI with LaoZhang API for stable access to GPT-5 coding capabilities

## Overview

OpenAI Codex CLI is OpenAI’s official command-line programming assistant. By configuring LaoZhang API, you can:

## 🚀 Stable Service

Direct access, no proxy needed

## 💰 Flexible Billing

Pay-per-use or per-request

## ⚡ GPT-5 Support

Access latest GPT-5 models

## 🔧 Simple Setup

Complete configuration in minutes

## Prerequisites

### Required Software

1

Install Git

Download from [Git website](https://git-scm.com/downloads)

**Windows**: Use default installation settings\
**macOS**: Usually pre-installed

2

Install Node.js

Download from [Node.js website](https://nodejs.org/en/download)Requires Node.js 22 or higher

3

Verify Installation

Open terminal and verify:

```
git --version
node --version
npm --version
```

## Install Codex CLI

### Option 1: npm Install

```
npm install -g @openai/codex
```

### Option 2: Source Install

```
git clone https://github.com/openai/codex.git
cd codex
npm install
npm link
```

## Configure LaoZhang API

### 1. Get API Key

1. Visit [LaoZhang API Console](https://api.yelinai.com/token)
2. Create a new token
3. Copy the key

### 2. Set Environment Variables

* macOS/Linux
* Windows

Edit `~/.zshrc` or `~/.bashrc`:

```
# LaoZhang API Configuration
export OPENAI_API_KEY="sk-your-laozhang-api-key"
export OPENAI_BASE_URL="https://api.yelinai.com/v1"
```

Apply changes:

```
source ~/.zshrc
```

Edit PowerShell profile:

```
notepad $PROFILE

# Add these lines
$env:OPENAI_API_KEY = "sk-your-laozhang-api-key"
$env:OPENAI_BASE_URL = "https://api.yelinai.com/v1"
```

Restart PowerShell or run:

```
. $PROFILE
```

### 3. Verify Configuration

```
echo $OPENAI_API_KEY
echo $OPENAI_BASE_URL

# Start Codex
codex
```

## Usage Guide

### Basic Usage

```
cd ~/my-project
codex

# Or ask directly
codex "Create an Express server"
```

### Interactive Mode

```
> Please optimize this function's performance
> Add unit tests to the project
> Explain this code's logic
```

### Common Commands

| Command               | Function               |
| --------------------- | ---------------------- |
| `codex`               | Start interactive mode |
| `codex "question"`    | Ask directly           |
| `codex --model gpt-5` | Specify model          |
| `codex --help`        | Show help              |

## Model Selection

Available models through LaoZhang API:

| Model            | Model ID       | Features           | Recommended For    |
| ---------------- | -------------- | ------------------ | ------------------ |
| **GPT-5**        | `gpt-5`        | Latest & strongest | Complex tasks      |
| **GPT-4.1**      | `gpt-4.1`      | Fast & capable     | Daily development  |
| **GPT-4.1 Mini** | `gpt-4.1-mini` | Lightweight        | Simple tasks       |
| **o4-mini**      | `o4-mini`      | Enhanced reasoning | Algorithm problems |

### Switch Models

```
codex --model gpt-5 "Optimize this code"
codex --model o4-mini "Solve this algorithm problem"
```

## Supported Features

* ✅ Code generation and completion
* ✅ Bug fixing and debugging
* ✅ Code refactoring
* ✅ Documentation generation
* ✅ Test case writing
* ✅ Code explanation
* ✅ Multi-language support

### Supported Languages

Python, JavaScript/TypeScript, Java, C++, C#, Go, Rust, Swift, Kotlin, Ruby, PHP, HTML/CSS, SQL, Shell Scripts, and all major programming languages.

## Troubleshooting

Connection Timeout or Failed

Check configuration:

1. Environment variables are set correctly
2. API key is valid
3. Network connection is stable

```
curl https://api.yelinai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"
```

Invalid API Key

Ensure you’re using a LaoZhang API key:

1. Visit [LaoZhang API Console](https://api.yelinai.com/token)
2. Check if key is valid
3. Verify account balance

Model Unavailable

Some models may be temporarily unavailable:

```
codex --model gpt-4.1 "your question"
```

How to Update Codex

```
npm update -g @openai/codex
```

## Best Practices

### Effective Prompts

```
✅ Good prompts:
"Create a Python function that parses JSON and returns data sorted by date"
"Refactor this class using singleton pattern"
"Add error handling and retry mechanism to this API"

❌ Avoid vague:
"Write code"
"Fix bug"
```

### Performance Tips

1. **Be specific**: Clear descriptions reduce round trips
2. **Provide context**: Tell AI about tech stack and constraints
3. **Break down tasks**: Split complex tasks into smaller steps
4. **Batch related tasks**: Describe related tasks together

### Cost Control

* Billed by token usage
* Use `gpt-4.1-mini` for simple tasks
* Check [Pricing page](/en/pricing) for details

## Tool Comparison

| Tool            | Type    | Advantages                 | Best For            |
| --------------- | ------- | -------------------------- | ------------------- |
| **Codex CLI**   | CLI     | GPT-5 support, lightweight | Terminal users      |
| **Claude Code** | CLI     | Strong Agent mode          | Complex refactoring |
| **Cursor**      | IDE     | Friendly UI                | Daily development   |
| **Cline**       | VS Code | Full Agent                 | VS Code users       |

## Related Resources

## OpenAI Codex

Learn about Codex technology

## API Console

Manage API keys and usage

## Claude Code

Claude programming assistant

## Model Comparison

View all coding model comparisons

Need help? Visit [LaoZhang API](https://api.yelinai.com) for support.
