June 28, 20263 min readSetupCodex CLI

How to use Codex CLI through one API

Codex CLI is a fast way to do real work from your terminal: read a repo, write a patch, run a command, iterate. By default it talks to OpenAI. But if you want to try a different model on a stubborn bug, or you'd rather not juggle several provider accounts and bills, you can point Codex at a single OpenAI-compatible endpoint instead.

This guide shows how to run Codex CLI through AnyModel: one base URL, one key, every model.

Why route Codex through one API

Codex speaks the OpenAI Chat Completions format. Any gateway that implements the same format is a drop-in replacement — you only change where requests go and which model id you ask for.

AnyModel exposes exactly that:

  • One endpoint: https://anymodel.org/v1
  • One API key that reaches GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok
  • Switching models means changing the model id — nothing else in your setup moves

So you can keep your Codex workflow and muscle memory, but swap the engine underneath whenever a task calls for it. Want to see which model fits your code-gen budget? Check the comparison page before you commit.

The one-line setup

Create a free account, grab your key, then run the installer for Codex. It writes the right config so the CLI points at AnyModel:

bash <(curl -fsSL "https://anymodel.org/i?tool=codex") <YOUR_API_KEY>

Replace <YOUR_API_KEY> with your actual key. That's it — open Codex and start a session.

The same installer supports a short list of CLI tools. Use the tool= parameter to pick:

Tool Command
Codex CLI bash <(curl -fsSL "https://anymodel.org/i?tool=codex") <KEY>
Claude Code bash <(curl -fsSL "https://anymodel.org/i?tool=claude") <KEY>
opencode bash <(curl -fsSL "https://anymodel.org/i?tool=opencode") <KEY>
hermes bash <(curl -fsSL "https://anymodel.org/i?tool=hermes") <KEY>

For other clients (Cursor, Windsurf, Zed, Cline, Aider, Continue, Gemini CLI), there's no installer — do a manual OpenAI-compatible setup instead: set the base URL to https://anymodel.org/v1 and paste your key. Most of these tools have a "custom OpenAI endpoint" field; that's where both values go.

Picking a model

Once Codex is wired up, choosing a model is a one-token change. Pass the model id you want — for example a GPT id for general work, a Claude id for long-context refactors, or a cheaper open model for bulk edits. Because billing and auth are unified, you never re-authenticate to switch.

A quick sanity check that your key and endpoint work, straight from the shell:

curl https://anymodel.org/v1/chat/completions \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5","messages":[{"role":"user","content":"Say hi"}]}'

If you get a normal completion back, Codex will too.

What it costs

You can start without a credit card. New accounts get 1,000,000 free tokens, and linking Telegram brings the total to 6,000,000. After that it's pay-per-token: no subscription, no monthly minimums, no seat fees. You spend what you use, which suits the spiky nature of CLI coding sessions — heavy some days, idle others.

A note on privacy

Code is sensitive, so be clear-eyed about data flow. AnyModel offers Ghost Mode: opt-in, zero-retention API keys where your prompts and responses aren't stored on our side — only a token counter for billing. That's a real reduction in what we keep, but it isn't magic: the model provider you call still receives the prompt to generate a response. We won't claim "100% privacy," because no proxy can honestly promise that. Use Ghost Mode keys for your most sensitive repos and judge providers accordingly.

Wrap-up

Routing Codex CLI through one API removes the friction of multiple accounts and lets you match the model to the task without changing your workflow. Install once, change a model id when you feel like it, and pay only for tokens. For more setup walkthroughs, browse the blog.

Ready to try it? Create a free account and run the one-liner — your first million tokens are on us.

Read next