Models → Pricing → Docs → Blog → Changelog → Contact → Status →
Get started freeLog in

Codex CLI with a Custom Provider (config.toml)

Codex CLI reads its providers from one TOML file. Add a FreeModel block, point it at the Responses API, and keep the key in an environment variable. Here is every line explained.

OpenAI's Codex CLI is a coding agent for the terminal. Out of the box it talks to OpenAI, but it also supports custom model providers defined in its config file. FreeModel serves the OpenAI Responses API at https://freemodel.in/v1/responses, which is the API Codex uses, so a FreeModel provider block is all it takes.

FreeModel is an independent service and is not affiliated with OpenAI. This guide only covers how to point Codex at it.

The complete config

Codex reads ~/.codex/config.toml (on Windows, %USERPROFILE%\.codex\config.toml). Create the file if it does not exist and add:

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"

Then set the key and start Codex:

export FREEMODEL_API_KEY=fm_your_key_here
codex

In PowerShell, use $env:FREEMODEL_API_KEY = "fm_your_key_here" before running codex.

Line by line

model

The model Codex uses when you do not pass one. It must be an id that FreeModel lists in GET /v1/models. Codex's own default model names are not FreeModel ids, and FreeModel does not map unknown names to another model, so always set this line. gpt-6-luna is one of the free models.

model_provider

Which provider block to use. The value must match the name after model_providers. below, here freemodel.

base_url

https://freemodel.in/v1. Codex adds /responses itself. Do not include the endpoint path.

env_key

The name of the environment variable that holds your key, not the key itself. Codex reads the variable at start-up and sends it as a Bearer token. Keeping the key out of the file means you can share or back up config.toml safely.

wire_api

"responses" tells Codex to use the Responses API. FreeModel's /v1/responses supports streaming and tool calls, which Codex needs to read files, run commands and apply patches.

Optional: retry settings

Codex retries failed requests on its own. If you would rather see errors immediately while you test the setup, add these to the provider block:

request_max_retries = 0
stream_max_retries = 0

Remove them, or set small numbers, once everything works.

What FreeModel does with Responses requests

A few details of FreeModel's /v1/responses endpoint matter for agents like Codex:

  • Streaming and non-streaming requests are both supported. Codex streams.
  • Tool calls come back as Responses-style function calls, and Codex sends the results back the same way.
  • previous_response_id works: unless a request sets store to false, the conversation is kept for 7 days and only your account can continue it.
  • Billing is the same as any other endpoint: input and output tokens both count, at the model's rate, and a request that fails is not charged.

Switching models

For a single run, pass the model on the command line:

codex -m gpt-6-luna
codex exec -m gpt-6-luna "explain what this repository does"

codex exec runs one task without the interactive interface, which is handy in scripts.

If you switch often, profiles keep it tidy. Each profile can set its own model on the same provider:

[profiles.light]
model = "gpt-6-luna"
model_provider = "freemodel"

[profiles.heavy]
model = "gpt-6.1-sol"
model_provider = "freemodel"

Start with codex --profile heavy. GPT-6.1 Sol is a paid model.

Which models work well

NeedLook forExample id
Free plana free model with Toolsgpt-6-luna
Edits and commandsTools capabilityany model with the Tools badge
Hard debuggingReasoning capabilitygpt-6.1-sol (paid)
Large repositoriesa published large contextcheck each model page

Capabilities and context sizes are on the models page. Premium models need a paid plan; plans start at $1.20 for 30 days and every paid plan reaches every model. GPT-6 Sol models use plan tokens at 1.75×, so one token counts as 1.75 plan tokens. The full table is on the pricing page.

Troubleshooting

  • Codex asks you to sign in to OpenAI — it is not using your provider block. Check that model_provider matches the block name exactly.
  • 401 — FREEMODEL_API_KEY is not set in the shell that runs Codex, or the key is wrong or revoked.
  • 404 model_not_found — the model is not a FreeModel id. Set model or pass -m.
  • 404 on every request — base_url includes /responses, or the domain is mistyped.
  • 403 upgrade_required — a free account picked a paid model.
  • 402 — tokens used up (tokens_exhausted). The rejected request is not charged.
  • 429 — your plan's rate limit for this key. Codex waits and retries unless you set retries to 0.
  • 503 — the model is temporarily unavailable. Try again later or switch models.

To check the endpoint without Codex:

curl https://freemodel.in/v1/responses \
  -H "Authorization: Bearer $FREEMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-6-luna", "input": "Say hello"}'

Prefer Claude Code? It uses the Anthropic format instead; see Claude Code with a custom API.

FAQ

Which API does Codex use with FreeModel?

The Responses API. With wire_api set to responses, Codex sends its requests to https://freemodel.in/v1/responses, which FreeModel serves with streaming and tool calls.

Why do I get model_not_found right after starting Codex?

Codex used a default model name that FreeModel does not list. Set model in config.toml, or pass -m with a FreeModel id such as gpt-6-luna.

Can a free account use Codex with FreeModel?

Yes, with a free model 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.

Is FreeModel connected to OpenAI?

No. FreeModel is an independent service and is not affiliated with OpenAI. Codex works with it because Codex supports custom providers.

Ready to build?

Grab a free API key — 1M tokens on 8 free models after a one-time Telegram verification, no card. Every model from $1.20.