How to use GPT-5.1 Codex in Codex CLI
GPT-5.1 Codex is OpenAI's coding-tuned model, and Codex CLI is the terminal agent built to drive it. Together they read your repo, plan edits, run commands, and ship diffs without leaving the shell. This guide shows the fastest way to wire them up — pointing Codex CLI at AnyModel so the same setup also unlocks Claude, Gemini, DeepSeek, and more behind one key.
Why route Codex CLI through AnyModel
Codex CLI speaks the standard OpenAI API. AnyModel exposes one OpenAI-compatible endpoint at https://anymodel.org/v1, and a single API key reaches every model on the platform — GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok. Switching models is just changing the model id in your request; nothing else in your config moves.
That matters for real coding work. You might use GPT-5.1 Codex for implementation, then compare it against Claude or Gemini on the same prompt to sanity-check an approach — all without juggling separate billing accounts, base URLs, or keys.
You also start free: 1,000,000 tokens on signup, rising to a total of 6,000,000 if you link Telegram. No credit card. After the free grant it's pay-per-token — no subscription, no minimums.
Step 1: Get your API key
Create an account and copy your key from the dashboard. New accounts get the free token grant automatically, so you can test GPT-5.1 Codex end to end before spending anything.
Step 2: Install and point Codex CLI at AnyModel
AnyModel ships a one-line installer for a small set of supported tools — codex, claude, opencode, and hermes. For Codex CLI, run:
bash <(curl -fsSL "https://anymodel.org/i?tool=codex") <YOUR_API_KEY>
Replace <YOUR_API_KEY> with the key from Step 1. The script installs (or reuses) Codex CLI and writes the configuration so it talks to https://anymodel.org/v1 with your key. That's the entire setup.
If you also use Claude Code, the same pattern works with tool=claude.
Step 3: Select GPT-5.1 Codex
With the endpoint configured, choose GPT-5.1 Codex as your model. You can set it for a single run or as your default — Codex CLI exposes a --model flag and a config entry depending on your version:
codex --model gpt-5.1-codex "Refactor the auth middleware and add tests"
Because AnyModel keys all models the same way, swapping to a different model later is a one-word change to the model value. Browse the current list and exact ids on the models page.
A quick sanity check
Before kicking off a big task, confirm the wiring with a plain HTTP call. Any OpenAI-compatible client — including curl — hits the same endpoint Codex CLI uses:
curl https://anymodel.org/v1/chat/completions \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-5.1-codex","messages":[{"role":"user","content":"Say hi in one word"}]}'
A clean JSON response means Codex CLI will work too.
Tips for getting good results
- Give it the repo, not just a sentence. Codex CLI is strongest when it can read files and run commands. Describe the goal and the constraints, then let it explore.
- Work in small, reviewable steps. Ask for one feature or fix at a time so diffs stay easy to verify.
- Mind your tokens. Large contexts cost more. Trim irrelevant files from the working set on long sessions.
- Try a second model on hard problems. When GPT-5.1 Codex gets stuck, re-run the same prompt against another model id and compare.
Privacy: Ghost Mode
If you'd rather not have prompts and responses retained on our side, enable Ghost Mode — opt-in, zero-retention keys where only a token counter is kept. Note this is honest scope: the upstream model provider still receives your prompt to generate a reply, so it isn't absolute privacy, but nothing extra is stored by AnyModel.
Other editors
Prefer Cursor, Windsurf, Zed, Cline, Aider, Continue, or Gemini CLI? They aren't covered by the one-line installer, but any of them work with a manual OpenAI-compatible setup: set the base URL to https://anymodel.org/v1 and paste your key. More walkthroughs live on the blog.
Ready to code with GPT-5.1 Codex? Create your free account and run your first task in minutes.
AnyModel