Case study · August 2, 2026

How to connect Reality Router to Codex CLI

Six lines of TOML in ~/.codex/config.toml. On a real 297-request stretch, RR cut Codex CLI's bill from $52.10 to $4.60 (91% off). Yes, even OpenAI's own coding agent.

Actual bill via RR
$4.60
Same run, no routing
$52.10
Saved automatically
91%

Six lines of TOML. On a real 297-request stretch, RR cut the bill from $52.10 to $4.60 — same tasks, 91% off. Yes, even in OpenAI's own coding agent.

Here's a fun one: Codex CLI is OpenAI's official coding agent. Rust-based, TUI-driven, ships with codex-mini-latest as the default. You'd think it would be locked to OpenAI's servers by design.

It isn't. Codex CLI has a first-class [model_providers.<name>] config section — meant for corporate proxies and Azure OpenAI, but nothing stops you from pointing it at Reality Router instead. OpenAI's own tool, doing OpenAI-agnostic model routing, using OpenAI's own config syntax.

Four things happen the moment you flip the switch:

  • Every Codex call goes through RR. RealitySignal calibrated probabilities pick the model per step — GPT-5 for the hard turns, Haiku or DeepSeek for the boilerplate. Even the "GPT-5 for hard turns" call is still going to OpenAI via RR, so nothing is degraded — it's just that you stop paying GPT-5 rates when a cheaper model would nail the task.
  • You escape Codex's model-lock defaults without giving up its polished UX. Codex's TUI is genuinely one of the best coding-agent surfaces in the wild; you get to keep it.
  • Full receipts on every call. OpenAI's usage dashboard tells you dollars-per-month; RR's tells you dollars-per-turn, per-model, per-agent.
  • One config replaces the rest of your keys. Anthropic, DeepSeek, Groq — all handled server-side by RR, not by 12 different env_key entries in your ~/.codex/config.toml.

Here's the setup.


1. Add RR as a model provider (60 seconds)

Codex CLI reads ~/.codex/config.toml. Open it (create if it doesn't exist) and add:

model = "auto"
model_provider = "reality-router"

[model_providers.reality-router]
name = "Reality Router"
base_url = "http://localhost:8000/v1"
env_key = "OPENAI_API_KEY"

Then export a placeholder key — RR accepts anything for local instances, the header just needs to exist:

export OPENAI_API_KEY="rr-local"

That's the whole change. Codex now sends every request to http://localhost:8000/v1/chat/completions with the rr-local bearer token, and RR routes from there.

A few notes on the pattern (all straight from the Codex config docs):

  • The section header must be [model_providers.<id>] where <id> is your name for the provider. Reserved IDs (openai, ollama, lmstudio) can't be reused, so reality-router is fine.
  • env_key names the env var Codex reads for the auth header — the value can be anything RR will accept.
  • wire_api defaults to OpenAI-compatible, so you don't need to set it. If you're pointing at RR's /responses endpoint instead, add wire_api = "responses".

2. Verify it worked (10 seconds)

codex

Ask it anything trivial:

> what does this repo do?

Then open the RR dashboard at http://localhost:8000. Your Codex call shows up in the Agent Activity table.

What you'll see

Dashboard mid-run, Codex CLI on top:

Reality Router dashboard mid-run: 297 requests, $4.60 actual spend against $52.10 potential, 91% savings, Codex CLI as the top consumer in the Agent Activity table.Enlarge

Total Volume: 297 requests. Accrued Expense: $4.60. Potential Cost (if everything had run on the top model in the pool): $52.10. Retained Value: $47.50 — 91% of the bill you'd have paid without routing, saved automatically. The top row of Agent Activity is Codex CLI itself, tagged with model_provider=reality-router.

Why bother

Codex is the most polished CLI in the space. That's not up for debate — OpenAI knows what it's doing when it builds developer tools. What Codex isn't is cheap, or transparent about cost, or willing to reach across the aisle to a Claude or DeepSeek model when that's the right call. Because why would it be — it's OpenAI's tool, built to promote OpenAI's models.

Route it through RR and every one of those changes:

  • Not-OpenAI models become fair game. RR routes to Claude, DeepSeek, Groq, Ollama, whatever you configure — from inside Codex, without Codex knowing or caring. Model choice happens per call based on RealitySignal, not on OpenAI's preferences.
  • Cost becomes a real-time signal, not a monthly surprise. Every turn shows up in RR's dashboard with model, tokens, latency, success rate. If Codex's default behavior is silently churning through expensive turns, you find out within seconds.
  • No usage caps. Codex + your OpenAI plan share the same rate limits as the rest of your OpenAI account. Route through RR and you're paying per token to whichever provider RR picked — no shared bucket to hit.

Same TUI. Same codex command. Same polish. Just not locked to a single provider anymore, and 89% cheaper on the same work.

realityrouter.dev


Reality Router is open source and self-hosted. Metrics in this post are from a real 297-request run.