Using OpenAI Codex CLI with Multiple Model Providers Using Bifrost
TL;DR
OpenAI's Codex CLI is a powerful terminal-based coding agent, but it ships locked to OpenAI models by default. Bifrost CLI changes that. By routing Codex through the Bifrost AI gateway, you can run Codex with models from Anthropic, Google, Mistral, and 15+ other providers, all without touching a single config file. One command. Any model. Full observability.
Codex CLI: A Quick Primer
Codex CLI is OpenAI's open-source coding agent that runs directly in your terminal. It can read your codebase, edit files, execute commands, and iterate on code changes with human-in-the-loop approvals. Built in Rust, it ships with features like sandboxed execution, MCP server integration, subagent workflows, and web search.
The default model is GPT-5.4, and Codex supports the full range of OpenAI's coding-optimized models including GPT-5.3-Codex and GPT-5.4-mini. It is included with ChatGPT Plus, Pro, Business, Edu, and Enterprise plans.
But here is the catch: Codex CLI talks to OpenAI's API out of the box. If you want to use a different provider, say Claude for its strong reasoning or Gemini for its large context window, you are looking at manual configuration of custom model_providers entries in config.toml, managing multiple API keys, and handling provider-specific quirks yourself.
That is exactly the problem Bifrost solves.
What Bifrost CLI Does Differently
Bifrost CLI is an interactive terminal tool that sits between your coding agent and your AI providers. Instead of manually editing environment variables, juggling API keys, and wiring up provider paths, you run a single command:
npx -y @maximhq/bifrost-cli
The CLI walks you through an interactive setup: pick your gateway URL, choose a harness (Codex CLI, Claude Code, Gemini CLI, or Opencode), select a model from any configured provider, and launch. Bifrost handles all the environment variables, base URL configuration, and API key management automatically.
For Codex specifically, Bifrost routes traffic through its /openai provider path, which means Codex sees a fully OpenAI-compatible API. No patches. No forks. Just a proxy that translates requests to whatever provider you choose.
Setting Up Codex CLI with Bifrost
There are two ways to connect Codex CLI to Bifrost: the automated path through Bifrost CLI, and manual environment variable configuration.
Option 1: Bifrost CLI (Recommended)
Start your Bifrost gateway:
npx -y @maximhq/bifrost
Then in another terminal, launch Bifrost CLI:
npx -y @maximhq/bifrost-cli
Select Codex CLI as your harness, pick any model from the list, and press Enter. Bifrost CLI installs Codex if it is missing, configures the base URL and API key, and launches the agent with everything wired up.
Option 2: Manual Configuration
If you prefer setting things up yourself, point Codex at your Bifrost gateway using environment variables:
export OPENAI_BASE_URL=http://localhost:8080/openai
export OPENAI_API_KEY=your-bifrost-virtual-key
codex
Both approaches achieve the same result: all Codex traffic flows through Bifrost.
Running Non-OpenAI Models in Codex
This is where things get interesting. Bifrost automatically translates OpenAI API requests to other providers, so you can pass any provider/model-name identifier directly to Codex:
# Launch Codex with Claude
codex --model anthropic/claude-sonnet-4-5-20250929
# Launch with Gemini
codex --model gemini/gemini-2.5-pro
# Launch with Mistral
codex --model mistral/mistral-large-latest
You can also switch models mid-session using Codex's /model command:
/model anthropic/claude-sonnet-4-5-20250929
/model gemini/gemini-2.5-pro
Bifrost supports 20+ providers including OpenAI, Azure, Anthropic, Google (Gemini and Vertex), AWS Bedrock, Mistral, Groq, Cerebras, Cohere, xAI, Ollama, OpenRouter, and more. One important caveat: non-OpenAI models must support tool use for Codex to work properly, since Codex relies on function calling for file operations, terminal commands, and code editing.
Why Route Codex Through a Gateway
Pointing Codex at Bifrost is not just about accessing more models. It unlocks several infrastructure capabilities that matter in production and team environments:
Automatic failover. Configure fallback chains so that if your primary provider returns an error or hits a rate limit, Bifrost automatically retries with a secondary provider. Your Codex session stays uninterrupted.
Load balancing. Distribute requests across multiple API keys or provider accounts to maximize throughput and stay within rate limits.
Observability. Every request flowing through Bifrost is logged with latency, token usage, and provider metadata. Bifrost's native observability gives you full visibility into what your agents are doing.
Cost governance. Use virtual keys to set budgets per developer, team, or project. Track spend across providers from a single dashboard.
Semantic caching. Bifrost's semantic caching can serve cached responses for semantically similar queries, cutting both cost and latency for repetitive operations.
Bifrost CLI's Tabbed Session UI
One underrated feature of Bifrost CLI is its persistent tabbed terminal UI. After launching Codex, you are not dumped back to the shell when the session ends. Instead, Bifrost CLI keeps a tab bar at the bottom of the terminal where you can:
- Press
Ctrl+Bthennto open a new agent session (potentially with a different model or even a different agent like Claude Code) - Switch between active sessions with
h/lor number keys - See at-a-glance status badges showing whether each session is active, idle, or waiting for input
This makes it practical to run parallel Codex sessions against different models, compare outputs, or keep a Claude Code session open alongside a Codex session for cross-referencing.
Wrapping Up
Codex CLI is one of the most capable terminal coding agents available today. Bifrost removes the single-provider constraint, letting you run Codex with any model from any provider, all while adding failover, observability, caching, and cost controls at the gateway layer.
Get started by installing Bifrost CLI, or check out the Codex CLI integration guide for the full setup reference. If you want production-grade monitoring for your AI agents beyond the gateway, Maxim's evaluation and observability platform integrates natively with Bifrost to give you end-to-end visibility from prompt to production.