Skip to main content

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
Windows: Use default installation settings
macOS: Usually pre-installed
2

Install Node.js

Download from Node.js websiteRequires 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
  2. Create a new token
  3. Copy the key

2. Set Environment Variables

Edit ~/.zshrc or ~/.bashrc:
# LaoZhang API Configuration
export OPENAI_API_KEY="sk-your-laozhang-api-key"
export OPENAI_BASE_URL="https://api.laozhang.ai/v1"
Apply changes:
source ~/.zshrc

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

CommandFunction
codexStart interactive mode
codex "question"Ask directly
codex --model gpt-5Specify model
codex --helpShow help

Model Selection

Available models through LaoZhang API:
ModelModel IDFeaturesRecommended For
GPT-5gpt-5Latest & strongestComplex tasks
GPT-4.1gpt-4.1Fast & capableDaily development
GPT-4.1 Minigpt-4.1-miniLightweightSimple tasks
o4-minio4-miniEnhanced reasoningAlgorithm 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

Check configuration:
  1. Environment variables are set correctly
  2. API key is valid
  3. Network connection is stable
curl https://api.laozhang.ai/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Ensure you’re using a LaoZhang API key:
  1. Visit LaoZhang API Console
  2. Check if key is valid
  3. Verify account balance
Some models may be temporarily unavailable:
codex --model gpt-4.1 "your question"
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 for details

Tool Comparison

ToolTypeAdvantagesBest For
Codex CLICLIGPT-5 support, lightweightTerminal users
Claude CodeCLIStrong Agent modeComplex refactoring
CursorIDEFriendly UIDaily development
ClineVS CodeFull AgentVS Code users

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 for support.