Skip to main content

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.
Get started with NanoGPT for pay-as-you-go pricing with no monthly fees. Add credits and start coding immediately.
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

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

1

Get API Key

  • Go to NanoGPT API
  • Create an account or log in
  • Copy your API key
2

Configure Codex

Set up Codex using one of the following methods:
Run this command in your terminal:
curl -O "https://nano-gpt.com/install/codex_nanogpt.sh" && bash ./codex_nanogpt.sh
The script will:
  1. Prompt for your API key
  2. Create ~/.codex/config.toml with NanoGPT configuration
  3. Add NANOGPT_API_KEY to your shell profile
The installer now supports browser-based login. When the script starts, choose:
  1. Browser login (recommended) - it will open a verification URL, wait for approval, and then save your key in ~/.codex/config.toml.
  2. Paste API key - manual fallback if you prefer.
If a browser does not open automatically, copy the printed URL into your browser and approve the request.For more details on the browser login flow, see CLI login.

Step 3: Start Using Codex

Once configured, start Codex in your terminal:
codex
Or specify a model directly:
codex --model openai/gpt-5.2

FAQ

What Models Can I Use?

NanoGPT supports 400+ models. Popular choices for Codex:
Use CaseRecommended ModelConfig
Best overallopenai/gpt-5.2model = "openai/gpt-5.2"
Best Claudeanthropic/claude-opus-4.5model = "anthropic/claude-opus-4.5"
Fast/cheapgoogle/gemini-3-flash-previewmodel = "google/gemini-3-flash-preview"
Long contextgoogle/gemini-3-pro-previewmodel = "google/gemini-3-pro-preview"
Open modelzai-org/glm-4.7model = "zai-org/glm-4.7"
View all available models at nano-gpt.com/models/text.

How Do I Change Models?

Option 1: Edit ~/.codex/config.toml:
model = "openai/gpt-5.2"
Option 2: Use CLI flag:
codex --model openai/gpt-5.2

Configuration Not Working?

  1. Check your API key: Ensure NANOGPT_API_KEY is set
    echo $NANOGPT_API_KEY
    
  2. Verify config file: Check ~/.codex/config.toml exists and has valid TOML syntax
  3. Open a new terminal: Environment variable changes require a new shell session
  4. Reset configuration: Delete ~/.codex/config.toml and run the setup script again

How Is This Different From Using OpenAI Directly?

FeatureOpenAI DirectNanoGPT
PricingMonthly subscription or API creditsPay-as-you-go, no minimums
ModelsOpenAI onlyOpenAI + Claude + 400 other models
BillingSeparate OpenAI accountSingle NanoGPT balance
Rate limitsOpenAI limitsNanoGPT limits

Can I Use Both Claude Code and Codex?

Yes. Both can be configured to use NanoGPT simultaneously:
  • Claude Code: Uses ~/.claude/settings.json with Anthropic API format
  • Codex CLI: Uses ~/.codex/config.toml with OpenAI API format
Both tools share the same NanoGPT credit balance.

Need Help?