Docs · Codex CLI

Two environment variables, and you are done

FreeModel is an AI model gateway: one key for 477 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 route instead:

If you wantUse
Best available for code, chosen for youauto/best-coding
Free quota onlyauto/best-free
Fastest that still worksauto/best-fast

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":"auto/best-chat","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

SymptomCause
404 on every requestBase URL carries /v1 twice, or carries /chat/completions — the base stops at /v1
401 on every requestKey not exported in the shell that launched the client
Works in one terminal, not anotherexport is per-shell. Put it in your profile for it to stick
Model not foundThe id is not in /v1/models; routes must match exactly, prefix included

Next