File size: 2,862 Bytes
8baf122 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | ---
title: "Codex CLI"
description: "Use OpenAI's Codex CLI with Bifrost for powerful code generation with any provider."
icon: "openai"
---
[Codex CLI](https://developers.openai.com/codex/cli/) provides powerful code generation and completion capabilities directly in your terminal.
<Note>
If your Allowed Headers are already set to `*`, you can skip this note. If not, and you face issues integrating Bifrost with Codex CLI, try switching to `*` or adding the specific headers required by your client. By default, Bifrost whitelists: `Content-Type`, `Authorization`, `X-Requested-With`, `X-Stainless-Timeout`, and `X-Api-Key`.
</Note>
## Installing Codex CLI
```bash
npm install -g @openai/codex
```
## Configuring Codex CLI with Bifrost
<Warning>
Codex CLI always prefers OAuth over custom API keys. Make sure you run `/logout` before configuring the Bifrost gateway with Codex.
</Warning>
### Update codex.toml
Add the Bifrost base URL and credentials to your global `~/.codex/config.toml` or project-specific `.codex/config.toml`:
```bash
export OPENAI_API_KEY=<bifrost_virtual_key>
```
```toml
openai_base_url="http://localhost:8080/openai/v1"
env_key="OPENAI_API_KEY"
model = "openai/gpt-5.4"
```
Always run `codex` from the same terminal session where you exported variables, or restart the terminal after changing your profile. GUI-launched terminals or IDEs may not pick up shell-profile exports unless the environment is configured there as well.
## Model Configuration
Use the `--model` flag to start Codex with a specific model:
```bash
codex --model openai/gpt-5-codex
codex --model openai/gpt-5.4-pro
```
You can also switch models mid-session with the `/model` command:
```bash
/model openai/gpt-5.4-pro
/model openai/gpt-5-codex
```
## Using Non-OpenAI Models with Codex CLI
Bifrost automatically translates OpenAI API requests to other providers, so you can use Codex CLI with models from Anthropic, Google, Mistral, and more. Use the `provider/model-name` format to specify any Bifrost-configured model:
```bash
# Start with an Anthropic model
codex --model anthropic/claude-sonnet-4-5-20250929
# Start with a Google model
codex --model gemini/gemini-2.5-pro
# Switch mid-session
/model anthropic/claude-sonnet-4-5-20250929
/model mistral/mistral-large-latest
```
### Supported Providers
Bifrost supports the following providers with the `provider/model-name` format:
`openai`, `azure`, `gemini`, `vertex`, `bedrock`, `mistral`, `groq`, `cerebras`, `cohere`, `perplexity`, `xai`, `ollama`, `openrouter`, `huggingface`, `nebius`, `parasail`, `replicate`, `vllm`, `sgl`
<Warning>
Non-OpenAI models **must support tool use** for Codex CLI to work properly. Codex CLI relies on tool calling for file operations, terminal commands, and code editing. Models without tool use support will fail on most operations.
</Warning>
|