Codex CLI
Use OpenAI’s Codex CLI with NanoGPT to access GPT-5.2, Claude Opus 4.5, Gemini 3 Flash Preview, and 400+ AI models through a single API key.NanoGPT provides an OpenAI API-compatible endpoint that works seamlessly with Codex CLI. This allows you to:
- Use Codex CLI with your NanoGPT credits
- Access OpenAI models (GPT-5.2 and more) without a separate OpenAI account
- Route to 400+ other models including Claude Opus 4.5, Gemini 3 Flash Preview, and GLM 4.7
Step 1: Install Codex CLI
- Recommended Installation Method
- Cursor Guided Installation Method
Prerequisites: Node.js 22 or newer
Note: If you encounter permission issues during installation, try using
sudo (macOS/Linux) or running the command prompt as an administrator (Windows) to re-execute the installation command.Step 2: Configure NanoGPT
Get API Key
- Go to NanoGPT API
- Create an account or log in
- Copy your API key
Configure Codex
Set up Codex using one of the following methods:
- One-Click Setup (Mac/Linux)
- Manual Configuration (All Platforms)
- Environment Variables Only (Quick)
Run this command in your terminal:The script will:
- Prompt for your API key
- Create
~/.codex/config.tomlwith NanoGPT configuration - Add
NANOGPT_API_KEYto your shell profile
- Browser login (recommended) - it will open a verification URL, wait for approval, and then save your key in
~/.codex/config.toml. - Paste API key - manual fallback if you prefer.
Step 3: Start Using Codex
Once configured, start Codex in your terminal:FAQ
What Models Can I Use?
NanoGPT supports 400+ models. Popular choices for Codex:| Use Case | Recommended Model | Config |
|---|---|---|
| Best overall | openai/gpt-5.2 | model = "openai/gpt-5.2" |
| Best Claude | anthropic/claude-opus-4.5 | model = "anthropic/claude-opus-4.5" |
| Fast/cheap | google/gemini-3-flash-preview | model = "google/gemini-3-flash-preview" |
| Long context | google/gemini-3-pro-preview | model = "google/gemini-3-pro-preview" |
| Open model | zai-org/glm-4.7 | model = "zai-org/glm-4.7" |
How Do I Change Models?
Option 1: Edit~/.codex/config.toml:
Configuration Not Working?
-
Check your API key: Ensure
NANOGPT_API_KEYis set -
Verify config file: Check
~/.codex/config.tomlexists and has valid TOML syntax - Open a new terminal: Environment variable changes require a new shell session
-
Reset configuration: Delete
~/.codex/config.tomland run the setup script again
How Is This Different From Using OpenAI Directly?
| Feature | OpenAI Direct | NanoGPT |
|---|---|---|
| Pricing | Monthly subscription or API credits | Pay-as-you-go, no minimums |
| Models | OpenAI only | OpenAI + Claude + 400 other models |
| Billing | Separate OpenAI account | Single NanoGPT balance |
| Rate limits | OpenAI limits | NanoGPT limits |
Can I Use Both Claude Code and Codex?
Yes. Both can be configured to use NanoGPT simultaneously:- Claude Code: Uses
~/.claude/settings.jsonwith Anthropic API format - Codex CLI: Uses
~/.codex/config.tomlwith OpenAI API format
Need Help?
- Check your balance at nano-gpt.com/balance
- View API usage at nano-gpt.com/usage
- Create or manage API keys at nano-gpt.com/api
- Contact support via the chat widget on nano-gpt.com