How to use GPT-5.2 Codex in Codex CLI
GPT-5.2 Codex is OpenAI's coding-tuned model, and the Codex CLI is the terminal agent built to drive it: read your repo, plan edits, run commands, and iterate. This guide shows how to wire the two together using AnyModel as an OpenAI-compatible gateway, so the same API key also reaches Claude, Gemini, DeepSeek, and more.
Why route Codex CLI through AnyModel
The Codex CLI speaks the OpenAI API format. AnyModel exposes a single OpenAI-compatible endpoint at https://anymodel.org/v1, so the CLI connects with zero protocol changes. The payoff: one API key reaches every model on the platform (GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, Grok). To switch models you change one string — the model id — and nothing else in your setup.
You also start free: 1,000,000 tokens on signup, and 6,000,000 total if you link Telegram, no credit card required. After that it's pay-per-token with no subscription and no minimums. That makes it cheap to test whether GPT-5.2 Codex actually fits your workflow before committing.
Step 1: Get a key and install
Create an account and grab your API key from the dashboard. Then run the one-line installer, which configures the Codex CLI to point at AnyModel automatically:
bash <(curl -fsSL "https://anymodel.org/i?tool=codex") <YOUR_API_KEY>
That's it for setup. The installer wires the base URL and key into the Codex CLI config so you don't have to edit files by hand. (The same installer supports tool=claude, tool=opencode, and tool=hermes if you use those agents too.)
Step 2: Select GPT-5.2 Codex
With the CLI configured, choose the model. Most builds of the Codex CLI accept a model flag or a config entry — set it to the GPT-5.2 Codex id you see on your AnyModel models page. A typical invocation looks like:
codex --model gpt-5.2-codex "Refactor the auth module to use async sessions"
Because everything runs through one endpoint, you can keep a second model handy for comparison. If you want a second opinion on a tricky diff, swap the id to a Claude or Gemini model and re-run — no new keys, no new config. The compare page is useful for picking which model to reach for on a given task.
Step 3: Use it well
A few practices that make GPT-5.2 Codex in the CLI noticeably more productive:
- Work in a clean git state. The agent edits files directly; commit or stash first so you can review and revert easily.
- Be specific about scope. "Add input validation to
createUserinusers.ts" beats "fix the user code." - Let it run commands. Codex CLI can execute tests and read output. Point it at your test command so it can self-correct.
- Cap large tasks. Break a big migration into reviewable chunks rather than one giant prompt.
Quick reference
| What | Value |
|---|---|
| Base URL | https://anymodel.org/v1 |
| Auth | Your single AnyModel API key |
| Switch model | Change the model id only |
| Free tokens | 1M on signup, 6M with Telegram linked |
A note on privacy
If you're pointing an agent at a private codebase, consider Ghost Mode — opt-in, zero-retention API keys. With Ghost Mode on, your prompts and responses aren't stored on our side; only a token counter runs. To be clear, this is not "100% privacy": the underlying model provider still receives the prompt to generate a response. Ghost Mode controls retention on AnyModel's side. You can read the details on the ghost page.
Other clients
The one-line installer covers codex, claude, opencode, and hermes. For other tools — Cursor, Windsurf, Zed, Cline, Aider, Continue, or Gemini CLI — use a manual OpenAI-compatible setup instead: set the base URL to https://anymodel.org/v1 and paste your key. The model-switching trick works there too.
Wrap-up
Running GPT-5.2 Codex in the Codex CLI through AnyModel takes one install command and one model id. From there you get a coding agent in your terminal plus the freedom to swap to any other model on a whim, all on a single key and a generous free tier. For deeper walkthroughs and model notes, browse the blog.
Ready to try it? Create your free account and run your first Codex session in minutes.
AnyModel