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:~/.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.- Open CC Switch and select Codex.
- Add a Custom Provider named
Flatkey. - Set Base URL to
https://router.flatkey.ai/v1. - Select the OpenAI Responses protocol.
- Enter your Flatkey API key (
sk-fk-...) and choose a supported GPT model from the Model Directory. - Activate the provider, fully quit Codex CLI, and start it again.
- 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:Choosing a model
By default, Codex CLI uses a GPT model. You can specify a different model with the--model flag:
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 andOPENAI_BASE_URL in the current shell session.