Claude Code and Codex CLI are the two terminal agents most developers ask about when they move off a subscription and onto metered API usage. The Claude Code vs Codex CLI cost question has two layers: what a session bills in tokens, and what it takes to connect either agent to an OpenAI- or Anthropic-compatible gateway in the first place. The second layer is less symmetric than most comparisons admit.
The prices below are the public AtmoRouter catalogue rates captured on the day of writing. The session numbers are illustrative arithmetic, not an independent benchmark of either agent. Rates refresh, so treat the model page as authoritative.
Two agents, two protocols
Both agents talk to a model over HTTP and both can run against a third-party gateway, but they speak different protocols:
- Claude Code uses the Anthropic Messages API. Point it at a base URL and a credential, and it works against any gateway that serves
/v1/messages. - Codex CLI uses the OpenAI Responses API. On current builds
wire_api = "responses"is the only accepted value, so a gateway that only serves Chat Completions is not enough.
That difference decides the setup effort. On AtmoRouter, Claude Code is a two-variable change. Codex CLI needs one extra component, a local bridge that translates Responses calls into Chat Completions, because the public gateway does not implement /v1/responses.
Claude Code: two environment variables
Claude Code reads its endpoint from the environment. Anthropic's gateway documentation describes ANTHROPIC_BASE_URL for the address and ANTHROPIC_AUTH_TOKEN for a bearer-token credential, and that is all a gateway needs:
bashexport ATMOROUTER_API_KEY="ar-xxxxxxxxxxxx"
export ANTHROPIC_BASE_URL="https://atmorouter.dev"
export ANTHROPIC_AUTH_TOKEN="$ATMOROUTER_API_KEY"
export ANTHROPIC_MODEL="cc/claude-sonnet-5-5"
claudeLeave off the /v1: Claude Code appends /v1/messages itself. The model ID must be the exact catalogue ID, family prefix included. One nice consequence of the Anthropic-compatible endpoint is that the model does not have to be a Claude model; any catalogue ID that accepts the Messages format can sit in ANTHROPIC_MODEL.
To confirm the connection before opening the agent, send one bounded request:
bashcurl -sS -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"cc/claude-sonnet-5-5","max_tokens":16,"messages":[{"role":"user","content":"Reply with OK."}]}'A JSON response with a usage block means the route works. A 401 means the credential variable is wrong or empty.
Codex CLI: the bridge step you cannot skip
Older tutorials tell you to add a [model_providers.<id>] table to ~/.codex/config.toml with wire_api = "chat". Current Codex rejects that value when the config loads. Switching it to "responses" gets past the config check, but the request then lands on a /responses route AtmoRouter does not serve.
The path that works today is the setup helper's optional bridge. It runs on localhost, accepts the Responses calls Codex makes, and forwards them as Chat Completions. The first command only previews; the second launches Codex through a temporary bridge:
bashnpx @atmorouter/[email protected] configure --target codex --model cx/gpt-6.2-sol
npx @atmorouter/[email protected] codex --model cx/gpt-6.2-solSet ATMOROUTER_API_KEY first; the bridge reads it from the environment. It needs Node.js 22 or newer. The bridge handles stateless text, function tools, and streaming, which covers a normal read-edit-run loop. It rejects unsupported built-in tools and stateful Responses features, hosted web search is disabled for the run, and reasoning summaries are unavailable. Calls are billed normally to your key. Our Codex CLI setup guide covers the standalone bridge and troubleshooting in more detail.
The illustrative session
Here is the workload the rest of the math uses. Treat every number as a stand-in you should replace with your own usage logs:
- 120 model requests over one working session
- 60,000 input tokens per request (system prompt, tool definitions, file context, conversation so far)
- 400 output tokens per request
That is 7.2 million input tokens and 48,000 output tokens. Against the public catalogue prices at writing time, with no caching:
| Model | Agent route | From price per million input / output | Session cost | | --- | --- | --- | --- | | cc/claude-sonnet-5-5 | Claude Code (Messages) | from $0.50 / $2.50 | about $3.72 | | cx/gpt-6.2-sol | Codex CLI (bridge) | from $1.00 / $5.00 | about $7.44 | | cx/gpt-5.6-terra | Codex CLI (bridge) | from $0.05 / $0.30 | about $0.37 | | zai/glm-5.4 | either | from $0.0035 / $0.011 | about $0.03 |
Two things stand out. First, the agent does not set the price; the model does. The Claude Code row is cheaper than the Codex row here only because Sonnet 5.5's from-price is half of GPT-6.2 Sol's. Second, the gap between tiers is far larger than the gap between agents: moving from a frontier model to a mid-tier one changes the session cost by an order of magnitude, while the choice of terminal changes it by zero.
For very cheap models, read the pricing page for any per-request minimum before trusting a sub-cent total.
Where the bill actually goes
Coding agents resend the same prefix on every turn: system prompt, tool schemas, the files already read. That makes prompt caching the largest lever on session cost, far bigger than which agent you pick. On AtmoRouter, cached input is billed at 10% of the input rate where the model supports it.
Suppose 85% of input tokens hit the cache in the same session. The arithmetic in Python, so you can swap in your own numbers:
pythonPRICES = { # USD per million tokens
"cc/claude-sonnet-5-5": (0.50, 2.50),
"cx/gpt-6.2-sol": (1.00, 5.00),
"cx/gpt-5.6-terra": (0.05, 0.30),
"zai/glm-5.4": (0.0035, 0.011),
}
requests, input_per_req, output_per_req = 120, 60_000, 400
input_m = requests * input_per_req / 1e6
output_m = requests * output_per_req / 1e6
for model, (pin, pout) in PRICES.items():
no_cache = input_m * pin + output_m * pout
cached = 0.85 * input_m * pin * 0.10 + 0.15 * input_m * pin + output_m * pout
print(f"{model:22s} no cache ${no_cache:6.2f} 85% cached ${cached:6.3f}")The output:
textcc/claude-sonnet-5-5 no cache $ 3.72 85% cached $ 0.966
cx/gpt-6.2-sol no cache $ 7.44 85% cached $ 1.932
cx/gpt-5.6-terra no cache $ 0.37 85% cached $ 0.099
zai/glm-5.4 no cache $ 0.03 85% cached $ 0.006An 85% hit rate cuts the Sonnet session from about $3.72 to about $0.97. Whether you get that rate depends on the model honoring cache markers and on the client sending a stable prefix; check the usage block on real responses for a cached-tokens field rather than assuming it. The bridge makes no caching promise on top of what the serving model reports.
How to choose
- You want the shortest setup path. Claude Code on the Anthropic-compatible endpoint is two environment variables and no extra process. See the Anthropic-compatible endpoint guide.
- You need Codex-specific workflow. Budget the bridge, and accept its limits: no hosted web search, no reasoning summaries, no stateful Responses features.
- You care about the bill. Pick the model tier first. Compare
cx/gpt-5.6-terraorzai/glm-5.4against the frontier rows on your own tasks before paying frontier rates for every turn. - You run long sessions. Watch context length:
cx/gpt-6.2-sollists a 628k window andcx/gpt-5.6-terra400k, whilecc/claude-sonnet-5-5andzai/glm-5.4list 1M.
Prices above are the public "from" rates at writing time; models can have several price tiers, and the bill uses the tier that served your request. Check live rates on the model page before you commit a budget.
Next step
Create a key at atmorouter.dev, point Claude Code or the Codex bridge at it, and run one real session on two model tiers. Compare the usage numbers against the pricing page and the live model list before you settle on a default.
FAQ
Does Codex CLI work with wire_api = "chat" on AtmoRouter?
No. Current Codex builds reject "chat" at config load, and the gateway does not serve /v1/responses. Use the helper bridge.
Can Claude Code run non-Claude models through AtmoRouter?
Yes. The Anthropic-compatible Messages endpoint serves the catalogue, so any model ID that accepts that format can go in ANTHROPIC_MODEL. Tool-calling quality depends on the model.
Is API usage cheaper than a Claude or ChatGPT subscription?
It depends entirely on volume. Subscriptions bill by plan limits rather than tokens. Run the session math above against your real request counts to see where you land.
Why is my session cost higher than the table?
Larger context per request, more requests, or a cache hit rate below 85%. Read the usage numbers on your responses and recompute.