Skip to main content
OpenAI’s Codex CLI is an AI coding assistant that runs in your terminal. By setting two environment variables, you can route all Codex CLI requests through Flatkey and pay Flatkey’s discounted rates — typically 40%+ savings on GPT model usage.

Prerequisites

  • Codex CLI installed: npm install -g @openai/codex
  • A Flatkey account with an API key — get one here

Configuration

Set the following environment variables before running Codex CLI:
Or add them to your shell profile (~/.bashrc, ~/.zshrc) to make the setting permanent:
~/.zshrc

Configure with CC Switch

CC Switch is a third-party desktop configuration manager for coding assistants. You can also download it from the official GitHub repository.
  1. Open CC Switch and select Codex.
  2. Add a Custom Provider named Flatkey.
  3. Set Base URL to https://router.flatkey.ai/v1.
  4. Select the OpenAI Responses protocol.
  5. Enter your Flatkey API key (sk-fk-...) and choose a supported GPT model from the Model Directory.
  6. Activate the provider, fully quit Codex CLI, and start it again.
  7. Run a small command, then confirm the request in Usage Logs.
Use Custom Provider if your CC Switch version does not include a Flatkey preset. Flatkey supports the Responses route directly, so you do not need CC Switch Local Routing for this setup.

Running Codex CLI

Once the environment variables are set, use Codex normally:
or in interactive mode:
All requests are routed through Flatkey and billed against your prepaid balance at Flatkey’s discounted rates.

Choosing a model

By default, Codex CLI uses a GPT model. You can specify a different model with the --model flag:
Any GPT model available in the Model Directory works with Codex CLI through Flatkey.

Verifying the setup

After running a Codex command, check Usage Logs — you should see the request logged with the model and token counts. If no request appears, confirm the active provider and OPENAI_BASE_URL in the current shell session.
Use the $200 top-up tier for the best effective rate on sustained Codex usage — the stacked bonus brings costs to as low as 50% of official GPT pricing.

Troubleshooting