Skip to main content
These examples use the direct API host, https://api.nano-gpt.com. It has no IPv6 address, so clients with only IPv6 should use https://nano-gpt.com with the same paths. See API Hosts.

Codex CLI

Use OpenAI’s Codex CLI with NanoGPT to access GPT 6.1 Sol, Claude Opus 5.5, Gemini Flash Latest, and every other NanoGPT text model 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 6.1 Sol and more) without a separate OpenAI account
  • Route to other models including Claude Opus 5.5, Gemini Flash Latest, and GLM Latest

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:
The script will:
  1. Prompt for your API key
  2. Create ~/.codex/config.toml using a model available to your API key on the configured API host
  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 local or self-hosted testing, NANOGPT_BASE_URL keeps login and API traffic on the same origin. To override only the Codex API endpoint, set NANOGPT_API_BASE_URL to the complete versioned base URL, including /api/v1 (for example, https://api.nano-gpt.example/api/v1).For more details on the browser login flow, see CLI login.

Step 3: Start Using Codex

Once configured, start Codex in your terminal:
Or choose the current recommendation for one run:
After one-click setup, plain codex uses the model selected from the direct host’s catalog.

FAQ

What Models Can I Use?

Codex can use any NanoGPT text model. These are our current recommendations. List available models with GET https://api.nano-gpt.com/api/v1/models.

How Do I Change Models?

Option 1: Edit ~/.codex/config.toml:
Option 2: Use CLI flag:

How Does Codex Compact Long Sessions?

With the nanogpt provider from One-Click Setup or Manual Configuration, Codex summarizes long sessions itself, on any model. To use OpenAI’s native compaction on OpenAI models instead, add this to ~/.codex/config.toml:
Use this only with OpenAI models. NanoGPT rejects native compaction on other models and on API keys that require Zero Data Retention, and Codex then stops with an error. One-Click Setup doesn’t add this setting.

Configuration Not Working?

  1. Check your API key: Ensure NANOGPT_API_KEY is set
  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?

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?