Introduction & Setup
Learn how to set up OpenAI Codex from scratch — install Node.js, generate your API key, configure environment variables, and install the Codex CLI tool.
What is OpenAI Codex?
OpenAI Codex is an AI-powered coding agent that can understand natural language instructions and translate them into working code. Unlike simple autocomplete tools, Codex acts as a full development partner — it can read your codebase, plan changes, write code, run terminal commands, and even review pull requests.
In this series, you'll learn everything from basic setup to advanced workflows like cloud delegation and parallel task execution.
Prerequisites
- Node.js — Version 18 or later (LTS recommended)
- npm — Comes bundled with Node.js
- An OpenAI account — You'll need an API key
- A terminal — Terminal.app (Mac), PowerShell (Windows), or any Linux terminal
Step 1 — Install Node.js
Download the latest LTS version of Node.js from the official website. The installer includes both Node.js and npm.
# Verify Node.js is installed
node --version
# Verify npm is installed
npm --version
You should see version numbers for both commands. If not, restart your terminal and try again.
Step 2 — Get Your API Key
- Go to platform.openai.com and sign in
- Navigate to API Keys in the dashboard sidebar
- Click "Create new secret key"
- Give it a descriptive name like
codex-cli - Copy the key immediately — you won't be able to see it again
⚠️ Important: Never share your API key or commit it to version control. Treat it like a password.
Step 3 — Configure Your Environment
Set your API key as an environment variable so the Codex CLI can authenticate automatically.
Mac / Linux
# Set the API key for the current session
export OPENAI_API_KEY="sk-your-api-key-here"
# To make it permanent, add to your shell profile
echo 'export OPENAI_API_KEY="sk-your-api-key-here"' >> ~/.zshrc
source ~/.zshrc
Windows (PowerShell)
# Set for current session
$env:OPENAI_API_KEY = "sk-your-api-key-here"
# Set permanently (system-wide)
[System.Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "sk-your-api-key-here", "User")
Step 4 — Install the Codex CLI
Install the Codex command-line tool globally using npm:
npm install -g @openai/codex
This gives you access to the codex command from anywhere in your terminal.
Step 5 — Verify the Installation
Run the authentication check to confirm everything is configured correctly:
codex auth
If successful, you'll see a confirmation message with your account details. You're now ready to start using Codex!
What's Next
In the next episode, we'll explore running cloud tasks — how to offload heavy work to secure remote containers so your local machine stays fast and responsive.