Codex CLI
Add FreeModel as a model provider in Codex CLI's config.toml.
Overview
Codex CLI is OpenAI's open-source coding agent for the terminal. Besides OpenAI's own service, it can use any provider you define in its config file. Codex talks the OpenAI Responses format, and FreeModel serves it at POST /v1/responses, so the provider only needs a base URL and a key.
Prerequisites
- Codex CLI installed (
codex --versionworks). - A FreeModel key from Dashboard → API Keys.
- Free accounts: free models only, such as
gpt-6-luna. Claude Haiku 5.5 and GPT-6.2 Astra are on the free plan; the other Claude models, GPT-6 Astra, GPT-6 Sol and the other premium models need a paid plan.
Configuration
Export the key under a name of your choice:
export FREEMODEL_API_KEY=fm_your_key_here
Then edit ~/.codex/config.toml:
model = "gpt-6-luna"
model_provider = "freemodel"
[model_providers.freemodel]
name = "FreeModel"
base_url = "https://freemodel.in/v1"
env_key = "FREEMODEL_API_KEY"
wire_api = "responses"
| Setting | Meaning |
|---|---|
model | Default model id — an exact FreeModel id. |
model_provider | Which provider block to use; matches the name after model_providers. |
base_url | https://freemodel.in/v1 |
env_key | Name of the environment variable that holds the key. Codex sends it as a Bearer token. |
wire_api | "responses" — Codex calls /v1/responses. |
Codex options change between releases. If your version rejects a setting, check Codex's own configuration docs; the values that matter for FreeModel are always the same: OpenAI-compatible base URL https://freemodel.in/v1, your fm_ key, and a FreeModel model id.
To try another model for one session without editing the file, pass it on the command line: codex --model claude-sonnet-5 (paid plan).
Test the connection
Run one task without the interactive interface:
codex exec "Reply with the word ok."
If it fails, call the Responses endpoint directly with the same key:
curl https://freemodel.in/v1/responses \
-H "Authorization: Bearer $FREEMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-6-luna", "input": "Reply with the word ok."}'
A JSON response with an output array means the key, URL and model are correct and the problem is in config.toml.
Which model ids to use
| Account | Ids |
|---|---|
| Free | gpt-6-luna; other free models: GPT-6.2 Astra, GPT-6 Luna, Grok 4.6, Grok 4.7, Claude Haiku 5.5, GLM-5.3 Flash, Qwen 3.8 Omni Flash and DeepSeek V4.1 Flash 1017. |
| Paid | gpt-6-astra or gpt-6.1-sol (1.75×), claude-opus-5-5 (3×), or any id on Models. |
Codex runs shell commands and applies patches through tool calls, so pick a model with the Tools capability. Codex may warn that it has no built-in metadata for a model id it does not know; that is a Codex-side notice, not an error from FreeModel.
Input and output tokens both count, at each model's multiplier. A failed request is not charged.
Common errors and fixes
| Status | What it means | Fix |
|---|---|---|
401 | No key or a wrong key reached FreeModel. | Make sure the variable named in env_key is exported in the same shell. If Codex is signed in to an OpenAI account, check it really uses model_provider = "freemodel". |
403 upgrade_required | Free account, paid model. | Set model to a free id, or buy a plan. |
404 model_not_found | The model id is not listed on FreeModel. | Copy the id from Models. Names like gpt-4o are not mapped to another model. |
402 | Tokens used up (tokens_exhausted). | Renew or upgrade. Refused requests are not charged. |
429 | Plan requests-per-minute limit. | Wait and retry. |
Related pages
- OpenAI SDKs — the Responses API from Python and Node
- Using Coding Agents
- Tool Calling