May 26, 20263 min readSetupGPT-5.2Codex CLI

How to use GPT-5.2 in Codex CLI

Codex CLI is a fast, terminal-native coding agent. By default it talks to OpenAI's API, but you can point it at any OpenAI-compatible endpoint — which means you can run GPT-5.2 through a single gateway and switch to Claude, Gemini, or DeepSeek without touching your config. This guide shows the quickest way to do that with AnyModel.

Why route Codex CLI through a gateway

Codex CLI speaks the OpenAI Chat Completions format. AnyModel exposes exactly that format at one base URL, so Codex doesn't know (or care) that the request is being routed. The practical wins:

  • One API key for every model. GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok all sit behind the same endpoint. Switching models is a one-word change.
  • No subscription. You pay per token, with no minimums and no monthly fee.
  • Free to start. New accounts get 1,000,000 tokens on signup, and a total of 6,000,000 if you link Telegram — no credit card required.

You can browse the full catalog on the models page and see side-by-side cost and capability on the compare page.

Step 1: Get your API key

Create an account and copy your key from the dashboard. If you don't have one yet, register here — it takes under a minute and the starter tokens are credited immediately.

Step 2: Install and configure with one line

AnyModel ships a small installer that configures Codex CLI for you. Run this in your terminal, replacing the placeholder with your real key:

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

That's it. The script writes the correct base_url (https://anymodel.org/v1) and key into your Codex configuration. The same installer supports claude (Claude Code), opencode, and hermes — just swap the tool= value.

Note: the one-line installer only supports those four tools (codex, claude, opencode, hermes). For other clients like 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.

Step 3: Select GPT-5.2 as the model

Once configured, tell Codex to use GPT-5.2. With Codex CLI you can set the model per session:

codex --model gpt-5.2 "refactor this module and add tests"

Because everything goes through one OpenAI-compatible endpoint, switching models is just changing the model id — nothing else in your setup changes. Want to compare GPT-5.2's output against another model on the same task? Run the same command with --model claude-sonnet-4.5 or --model gemini-2.5-pro and diff the results.

What you want What you change
Use GPT-5.2 --model gpt-5.2
Try a different model swap the model id only
Use a different endpoint nothing — base URL stays the same

Step 4 (optional): Turn on Ghost Mode

If you're working on sensitive code, AnyModel offers Ghost Mode — opt-in, zero-retention API keys. With Ghost Mode on, your prompts and responses are not stored on our side; we keep only a token counter for billing. Be clear-eyed about what this does and doesn't mean: the underlying model provider still receives your prompt to generate a response, so this is not "100% privacy." It does remove our side of the storage equation. Read the details on the Ghost Mode page.

Verifying the connection

If Codex throws an auth or connection error, sanity-check the endpoint directly with curl:

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

A normal JSON completion confirms your key and the GPT-5.2 model id are valid; from there, Codex CLI should work without further changes.

Tips for everyday use

  • Keep the gateway base URL fixed and treat model choice as a runtime decision — heavier reasoning on GPT-5.2, cheaper drafts on a smaller model.
  • Watch your token counter in the dashboard; pay-per-token means you only spend on what you run.
  • For more setup walkthroughs and model comparisons, check the blog.

GPT-5.2 in your terminal, plus every other major model behind one key — no subscription, no lock-in. Create your free account and start with up to 6,000,000 tokens.

Read next