Docs · Codex CLI
How do I configure Codex CLI with FreeModel? Two environment variables
最后更新:
FreeModel is an AI model gateway: one key for 200+ models across dozens of providers, routed by task with free capacity tried first. Codex CLI speaks the OpenAI API, so the whole setup is pointing one variable at the right base URL and handing over a key.
Setup
# OpenAI-compatible base. Note: /v1 is part of the base —
# the client appends /chat/completions itself.
export OPENAI_BASE_URL="https://freemodel.online/v1"
export OPENAI_API_KEY="sk-your-key"
Restart the shell that launches Codex CLI, or put the two lines in your shell profile so they survive a new terminal.
Which model you get
Whatever you ask for. If you name a specific model, that is what answers. If you would rather not track model names, pass a tier alias instead:
| If you want | Use |
|---|---|
| Strongest available, chosen for you | fm-v1-pro |
| Balanced default | fm-v1-standard |
| Lowest cost per call | fm-v1-lite |
The full set of ids is at Models, and the live list is
curl https://freemodel.online/v1/models.
Checking it works
# does the base answer at all? 401 = yes, it wants a key. 404 = wrong path.
curl -s -o /dev/null -w "%{http_code}\n" \
-X POST https://freemodel.online/v1/chat/completions \
-H "Content-Type: application/json" -d '{}'
# and a real call, which proves the key
curl -s https://freemodel.online/v1/chat/completions \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{"model":"fm/qwen-plus","messages":[{"role":"user","content":"hi"}]}'
A 400 with messages: ... required on the first command is the
good outcome — it means the endpoint exists and parsed your (empty) body.
Common problems
| Symptom | Cause |
|---|---|
| 404 on every request | Base URL carries /v1 twice, or carries /chat/completions — the base stops at /v1 |
| 401 on every request | Key not exported in the shell that launched the client |
| Works in one terminal, not another | export is per-shell. Put it in your profile for it to stick |
| Model not found | The id is not in /v1/models; routes must match exactly, prefix included |
Next
Set up in three steps
The whole configuration is two environment variables. The order matters only in that the shell which exports them has to be the shell that launches the client.
- Step 1: Export the base and the key.
OPENAI_BASE_URLtakeshttps://freemodel.online/v1andOPENAI_API_KEYtakes yoursk-key from the console. The base stops at/v1; the client appends/chat/completionson its own. - Step 2: Make it survive a new terminal. On macOS and Linux that means the same two lines in
~/.zshrcor~/.bashrc. On Windows,setx OPENAI_BASE_URL "..."writes the value for future shells, while$env:OPENAI_BASE_URLcovers only the current PowerShell session. - Step 3: Restart Codex CLI and check the endpoint before you blame the model.
curl -s https://freemodel.online/v1/modelsis public and needs no key, so it separates a reachability problem from a key problem in one command.
Codex CLI is a coding agent, so whatever answers has to hold up across a long run. The 199 listed models are 77% chat models[1], and a routed request is re-decided on every call, so a provider that stops answering mid-session is skipped rather than fatal.
What you get to choose from
Naming a model pins the request to it. Naming a tier alias hands the decision to the router per request, and the aliases are a deliberately small slice of the catalogue — three of them, one per subscription plan.[1] That is the point of them: they stand in for a choice you would otherwise make yourself, and they move when a provider stops answering.
The wider catalogue is worth a look if you care about depth rather than convenience. The
199 listed models put chat, image, video, speech and embeddings in one list, and six
auto/* routes cover the non-chat side — auto/image, auto/video,
auto/tts, auto/asr, auto/embed, auto/rerank — each carrying
a candidates field that shows how many models sit behind it.[1]
A route is not a model name: it is a standing instruction to the router, re-evaluated on every call. Two identical requests inside one session can be served by two different providers, which is what you want for uptime and not what you want while comparing two prompts against each other.
Codex CLI FAQ
Do I have to edit a config file?
Will these variables affect other tools on the same machine?
OPENAI_BASE_URL and OPENAI_API_KEY are the names most OpenAI-shaped tools read. Anything else in that shell which reads them will also send its requests here, which is usually fine and occasionally surprising.What happens when the model name I pass is not in the catalogue?
auto/ prefix. /v1/models is the authority on what this gateway accepts.Does Codex CLI's approval mode change with this setup?
Should I use a route or a concrete model for long sessions?
fm-v1-standard moves the request to its next candidate instead of returning that failure.Sources
Every third-party figure quoted on this site was read from the vendor documentation linked below, on the date stated. None of these links are affiliate links and none of these vendors paid to be listed. If a number here disagrees with the page it came from, the page is right — tell us and it gets corrected.
- OpenRouter — credit-purchase fees and free-model rate limits
- OpenRouter — rate-limit reference
- OpenRouter — public model list
- LiteLLM — licence, deployment options and supported models
- Cloudflare AI Gateway — features and pricing
- Vercel AI Gateway — features
- Portkey — plans
- Helicone — plans
- Model Context Protocol — specification
- OpenAI Python SDK — base_url and OPENAI_BASE_URL
- Anthropic Messages API — request format
Where the percentages come from
Every share quoted on this site is counted from the live model list, not estimated. Divide the two counts in the last column, round to the nearest whole percent, and you get the number in the first.
| Share | Of what | Count |
|---|---|---|
| 77% | are chat models | 153 of 199 listed entries |
| 9% | generate images | 18 of 199 listed entries |
| 23% | are not chat models | 46 of 199 listed entries |
| 3% | are modality routes | 6 of 199 listed entries |
| 17% | carry a context length | 34 of 199 listed entries |
[1] Counted on 29 September 2026 from GET https://freemodel.online/v1/models, which needs no key and no account. Every row uses all 199 listed entries as the denominator, because the only thing the endpoint states for every entry is its modality. It no longer publishes per-model capability flags such as tool calling or reasoning, so this site quotes no shares for them. Fetch the list and recount whenever you want to check the arithmetic.
Troubleshooting Codex CLI + FreeModel
- Environment variables not picked up: export them in the same shell that launches the CLI, or put them in the shell profile. A variable set in another terminal does not apply.
- 401 after switching keys: the CLI may cache credentials; restart the process after changing the key.
- Wrong model served: print the model field in the response. If it differs from the requested name, the gateway routed a fallback.
- Timeout on long tasks: the CLI request timeout may be shorter than the gateway timeout. Raise it before assuming the gateway is down.
Keep a one-line curl command next to the CLI config. When something breaks, run the curl first; if it succeeds, the problem is in the CLI environment, not the gateway.