2026-11-07 · 5 min read

What Codex CLI Actually Costs

Plan sign-in vs API key, automatic caching, and the token math of agentic Codex sessions — the cost picture for OpenAI's coding agent, without the guesswork.

Codex CLI users split into two camps: those on a ChatGPT plan who never see a token count, and those on API keys who see nothing but token counts. Both camps are guessing — the plan camp can't see the meter, the API camp can't see the model's behavior. This post is the cost picture for Codex CLI: which mode bills what, where the tokens actually go, and why agentic sessions behave differently from chat.

Disclosure up front: I operate Teapot Router, a gateway that serves Codex CLI and Claude Code over OpenAI-compatible and Anthropic protocols. The mechanics below apply to any OpenAI-compatible endpoint — nothing depends on ours.

Two modes, two metering realities

Codex CLI runs in two modes with fundamentally different billing. Plan sign-in: usage is included in a ChatGPT subscription up to limits, and you see a quota indicator, not a bill — cheap until you hit the wall, then throttled. API-key mode: every token is metered and priced per model, which is where cost questions actually live. Teams that need to see what work costs run API-key mode; teams that just need the work done run plans until limits bite. Knowing which camp you are in is step one of every Codex cost conversation.

Where the tokens go in an agentic session

A Codex session is not a chat; it is a loop of tool calls, file reads, and edits, and every turn re-sends the working context. The bill is therefore driven by the same three variables as any coding agent:

  1. Turns per task — agents iterate; a refactor is dozens of billed round-trips, not one prompt.
  2. Context growth — every file read and tool result rides along in later turns; message 20 pays for messages 1-19 again.
  3. Cache behavior — OpenAI discounts repeated prompt prefixes automatically; you don't tune it, but your session shape decides how much of your bill gets the discount.

The trade the automatic cache makes

OpenAI's prompt caching requires no configuration: stable, repeated prefixes are discounted on hit. The trade is control — you get the discount when your session shape happens to be cache-friendly, and you can't tag or steer it the way Anthropic-style caching lets you. Practical consequence: session discipline (scoped tasks, fresh sessions, boring stable prefixes) moves your effective rate more than model choice does, and there is no knob to compensate for a chaotic context.

Running Codex through a gateway

API-key mode is also the mode that routes: change one base_url and Codex talks to any OpenAI-compatible endpoint. That is where teams put a gateway — one shared pool instead of per-developer keys, per-request metering (model, tokens, cache hits, exact cost) instead of a monthly mystery, and org-level spend rollups. The metering is the point: plan mode hides what work costs; a metered gateway shows it, per task, per key, per project.

Pick your mode deliberately: plans for included-and-opaque, API keys for metered-and-auditable. Then manage the three variables that decide the API bill — turns, context growth, cache-friendly session shape — because in agentic coding those dominate everything else.

FAQ

Is Codex CLI free on a ChatGPT plan?

Usage is included up to plan limits — you pay the subscription, not per token, and you hit throttling rather than a bill when limits are reached. Heavier workloads generally end up in API-key mode.

Does prompt caching apply to Codex sessions?

Yes — repeated stable prefixes get discounted automatically on OpenAI endpoints. You don't configure it; your session shape (scoped tasks, stable context) determines how much of the bill gets discounted.

Can I point Codex CLI at my own endpoint?

Yes — set the base URL to any OpenAI-compatible endpoint. Gateways add per-request metering and shared team pools on top; the protocol is the same.

All posts