OpenAI Codex CLI
OpenAI Codex CLI — coding agent chạy trong terminal, cho phép thực thi code, chỉnh sửa file và tương tác với hệ thống.
Cài đặt
npm install -g @openai/codexCấu hình
Set API key vào biến môi trường OPENAI_API_KEY:
Linux / macOS:
export OPENAI_API_KEY="sk-billing-xxx"Windows (PowerShell):
setx OPENAI_API_KEY "sk-billing-xxx"Mở file config ~/.codex/config.toml — định nghĩa custom provider nexai trỏ về Responses API của nexai:
model = "gpt-5.1-codex-mini"
model_provider = "nexai"
model_reasoning_effort = "medium"
[model_providers.nexai]
name = "nexai"
base_url = "https://nexai.newdev.net/api/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"wire_api = "responses" dùng endpoint /v1/responses của nexai (tương thích Codex CLI). KHÔNG dùng OPENAI_BASE_URL env var — Codex chỉ đọc base_url từ config khi dùng custom provider.Chạy với model cụ thể
# Dùng GPT-4o (cân bằng)
codex --model gpt-4o "Refactor src/main.py"
# Dùng model code (nhanh, tiết kiệm)
codex --model gpt-5.1-codex-mini "Add docstrings to all functions"
# Full auto mode (không hỏi xác nhận)
codex --approval-mode full-auto "Fix lint errors in src/"Dùng
--approval-mode full-auto để Codex tự động thực hiện không cần xác nhận — tiết kiệm thời gian khi làm tác vụ lặp lại.