Verdict: You can run OpenAI's Codex CLI — the open-source terminal coding agent — entirely on free AI model APIs in 2026, no ChatGPT Plus subscription required. The tool itself is free under Apache 2.0; the "brain" (the model) is what normally costs money. By defining a custom model provider in ~/.codex/config.toml, you can point Codex at any OpenAI-compatible endpoint: free tiers from OpenRouter, aggregated free providers via the OmniRoute gateway, or direct connections to services like Groq and Cerebras. For a broader survey of no-cost options, see our 12 Free AI API Providers in 2026: Every Free LLM API Compared. Pair that with automatic token compression and multi-model fallback, and you get a genuinely usable coding agent at $0/month.
Last verified: 2026-08-04 · Codex CLI is open-source (Apache 2.0) · OmniRoute is free (MIT) with 90+ free providers · OpenRouter free tier: 20 RPM, 50 requests/day · Token compression saves 15–95% · Pricing and limits change often — re-check before relying on any figure here.
What Is Codex CLI and Why Is It Free?
OpenAI Codex CLI is an open-source, terminal-based AI coding agent written in Rust. It reads your repository, edits files, runs shell commands, and iterates on its own work — all from the command line. It was open-sourced under the Apache 2.0 license, which means the software itself is free to install and use.
What is not free by default is the model that powers it. Out of the box, Codex CLI calls OpenAI's Codex models (GPT-5.3-Codex, GPT-5.4-Codex, etc.), which bill against a ChatGPT subscription or OpenAI API credits. A ChatGPT Plus subscription costs $20/month; the API charges per token.
The key insight: Codex CLI is not locked to OpenAI's models. The CLI speaks the OpenAI Chat Completions API protocol, and any provider that implements that same protocol can be plugged in as a custom provider — including free ones.
How Does Codex CLI Support Custom Model Providers?
Codex CLI supports custom providers through a config.toml file located at ~/.codex/config.toml (on Windows: %USERPROFILE%\.codex\config.toml). You define a provider with its base URL, API key environment variable, and wire protocol, then tell Codex to use that provider and model.
Here is a minimal working configuration pointing Codex at an OpenAI-compatible free endpoint:
# ~/.codex/config.toml
model = "free-model-id-here"
model_provider = "my-free-provider"
[model_providers.my-free-provider]
name = "My Free Provider"
base_url = "https://your-provider-endpoint/v1"
env_key = "MY_FREE_PROVIDER_API_KEY"
wire_api = "chat"
Then set the API key as an environment variable:
export MY_FREE_PROVIDER_API_KEY="your-api-key-here"
Critical gotcha — wire_api: Most third-party providers (OpenRouter, OmniRoute, Groq) implement the Chat Completions API, so you must set wire_api = "chat". If you only change the base_url without defining the provider block and setting the wire protocol correctly, Codex will fail. OpenAI's own Responses API (wire_api = "responses") is the default, and third-party endpoints generally do not support it. OpenAI has also noted that Chat Completions support will eventually be removed from Codex, so verify compatibility against your installed version.
You can also use the --provider flag at the command line for built-in providers:
codex --provider openrouter "explain this codebase to me"
codex --provider deepseek "refactor this function"
codex --provider groq "write a test for this module"
The built-in provider options include: openai, openrouter, azure, gemini, ollama, mistral, deepseek, xai, groq, arceeai, and any other provider compatible with the OpenAI API. For providers not in that list, define your own in config.toml.
What Free Model Providers Work With Codex CLI?
Three approaches give you free models inside Codex CLI. Each has different trade-offs in setup complexity, model variety, and rate limits.
1. OpenRouter (Direct, Simplest Setup)
OpenRouter is a managed API gateway that offers 28+ free models with a :free suffix on their model IDs. No credit card required — sign up with an email at openrouter.ai and generate an API key.
Free tier rate limits (as of mid-2026):
| Limit | Free tier (no credits) | After $10 in credits |
|---|---|---|
| Per-minute | 20 requests | 20 requests |
| Per-day | 50 requests | 1,000 requests |
| Token-per-minute | Provider-dependent | Provider-dependent |
| Free models | All :free variants |
All :free variants |
The $10 credit is a one-time top-up (not a subscription) that permanently raises your daily limit from 50 to 1,000 requests. The per-minute cap stays at 20 RPM regardless.
Notable free coding models on OpenRouter:
| Model ID | Context | Best for |
|---|---|---|
qwen/qwen3-coder:free |
262K | Strongest free coding model |
deepseek/deepseek-r1:free |
128K | Reasoning, math, general coding |
nvidia/nemotron-3-ultra-550b-a55b:free |
1M | Long-context reasoning |
meta-llama/llama-3.3-70b-instruct:free |
128K | General tasks, stable pool |
meta-llama/llama-4-scout:free |
10M | High-volume extraction, fast chat |
Codex config for OpenRouter:
# ~/.codex/config.toml
model = "qwen/qwen3-coder:free"
model_provider = "openrouter"
[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
env_key = "OPENROUTER_API_KEY"
wire_api = "chat"
2. OmniRoute (Aggregated Free Gateway, Most Models)
OmniRoute is a free, open-source (MIT-licensed) AI gateway that aggregates 268+ providers into a single OpenAI-compatible endpoint. It includes 90+ providers with a free tier, 11 of which are free forever — no credit card, no payment ever.
Free-forever providers available through OmniRoute:
| Provider | Models | Auth method | Key feature |
|---|---|---|---|
| Kiro | claude-sonnet-4.5, claude-haiku-4.5 |
AWS Builder ID / Google / GitHub | Unlimited Claude access, free |
| Qwen | qwen3-coder-plus, qwen3-coder-flash, 2 more |
Device code authorization | Unlimited usage |
| Pollinations | GPT-5, Claude, Gemini, DeepSeek, Llama | No API key required | 1 req/15s, zero friction |
| Cloudflare Workers AI | Llama 3.3 70B, Gemma 3, Qwen 2.5 Coder, Whisper | Free Cloudflare API key | 10,000 daily neurons on free tier |
| iFlow / Qoder | Kimi K2 Thinking, GLM 4.7, DeepSeek R1, Qwen3 Coder | OAuth | 5 free models, unlimited |
OmniRoute's standout feature is 4-tier auto-fallback: when a provider hits its rate limit or goes down, the gateway automatically routes the next request to the next available provider in milliseconds — Subscription → API → Cheap → Free. You do not see the error; your coding session keeps running.
Codex config for OmniRoute:
# ~/.codex/config.toml
model = "kr/claude-sonnet-4.5"
model_provider = "omniroute"
[model_providers.omniroute]
name = "OmniRoute"
base_url = "http://localhost:4400/v1"
env_key = "OMNIROUTE_API_KEY"
wire_api = "chat"
OmniRoute runs locally (via npm, Docker, or an Electron desktop app) and exposes http://localhost:4400/v1 as its endpoint. You connect your providers (OAuth or API key) through the OmniRoute dashboard, then point Codex at the local endpoint. For a walkthrough of routing OmniRoute with Google Antigravity, see How to Set Up AI Model Routing With OmniRoute and Google Antigravity.
3. Direct Provider Free Tiers (No Gateway)
You can skip the gateway entirely and connect Codex directly to providers that offer free APIs:
| Provider | Free tier | Rate limit | Models available |
|---|---|---|---|
| Groq | Free API key at console.groq.com | 14,400 req/day, 30 RPM/model | Llama 3.3 70B, Mixtral 8x7B, Gemma 2 9B |
| Cerebras | Free API key at inference.cerebras.ai | 1M tokens/day, 60K TPM, 30 RPM | Llama 3.3 70B, Llama 3.1 8B, DeepSeek R1 distill |
| Google AI Studio | Free tier at aistudio.google.com | Varies by model | Gemini Flash, Gemma 3 |
| Moonshot AI (Kimi) | $9/month flat | 10M tokens/month | Kimi K2 (not free, but very cheap) |
For a DeepSeek-specific free coding agent setup, our DeepSeek V4 Flash 0731 free coding agent guide covers the config in detail.
Comparison of the three approaches:
| Approach | Setup time | Free models | Auto-fallback | Token compression | Best for |
|---|---|---|---|---|---|
| OpenRouter direct | 2 min | 28+ | No (manual via fallbackModels) |
No | Quick start, single provider |
| OmniRoute gateway | 10 min | 90+ (11 free-forever) | Yes (automatic, 4-tier) | Yes (RTK + Caveman) | Long sessions, max uptime |
| Direct provider | 5 min each | 1–5 per provider | No | No | Lowest latency, simple |
How Does Token Compression Keep Free Models Going Longer?
The biggest enemy of free-tier coding is the rate limit. Every request consumes tokens; free tiers cap how many tokens you get per minute and per day. Token compression directly stretches those limits.
OmniRoute ships with two compression engines that run automatically before requests hit the upstream provider:
RTK (Rust Token Killer) — targets command output, tool results, git diffs, and build logs. These are the most token-dense parts of an agentic coding session. RTK filters them intelligently while preserving developer-relevant content.
- Savings: 60–90% on command/tool output
- Best for: Agentic workflows where Codex runs shell commands and reads their output
Caveman — targets human prose, chat history, and filler language. It removes redundant phrases and condenses conversation context.
- Savings: ~30% on prose input, ~46% input compression on tool-heavy sessions
- Best for: Long conversations with accumulated context
Stacked mode (RTK → Caveman) — runs both engines in sequence. RTK compresses the tool output first (60–90% savings), then Caveman compresses the remaining prose (additional ~46% savings). The combined savings are multiplicative:
Combined = 1 - (1 - RTK savings) × (1 - Caveman savings)
Average = 1 - (1 - 0.80) × (1 - 0.46) = 89.2%
Range = 1 - (1 - 0.60..0.90) × (1 - 0.46) = 78.4–94.6%
That means in a tool-heavy coding session, compressed requests use 78–95% fewer tokens than raw requests. If your free tier gives you 1M tokens/day, compression turns that into the equivalent of 4.5–19M tokens of raw capacity. Code blocks, URLs, and structured data are always preserved byte-perfect — the compression targets whitespace, filler, and verbose tool output, not your actual code.
Step-by-Step: Set Up Codex CLI With a Free Model
Prerequisites
- Node.js 22+ installed
- A free OpenRouter API key (or any OpenAI-compatible free provider)
- Codex CLI installed:
npm install -g @openai/codex
Step 1: Get a free API key
For OpenRouter (simplest path):
- Go to openrouter.ai and sign up with email (no credit card).
- Navigate to Keys → Create Key.
- Copy the key starting with
sk-or-v1-.
For OmniRoute (max free models + compression):
- Clone or install OmniRoute:
npm install omnirouteor use Docker. - Start the server and open the dashboard.
- Connect free providers (Kiro, Qwen, Pollinations) via OAuth.
- Create an API key from the Endpoints panel.
Step 2: Configure Codex CLI
Create or edit ~/.codex/config.toml:
# Using OpenRouter with a free coding model
model = "qwen/qwen3-coder:free"
model_provider = "openrouter"
[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
env_key = "OPENROUTER_API_KEY"
wire_api = "chat"
Step 3: Set the API key environment variable
# Add to ~/.bashrc or ~/.zshrc
export OPENROUTER_API_KEY="sk-or-v1-..."
Step 4: Verify the connection
codex "write a hello world function in Python"
If Codex starts working, the free model is connected. If you get a 401, check the API key. A 404 means the model ID is wrong. A 429 means you hit the rate limit — try a different free model or wait.
Step 5 (Optional): Add a fallback model
If your primary free model saturates, Codex will error out. You can switch manually with --provider, or use a gateway like OmniRoute that handles fallback automatically. With OpenRouter, a practical pattern is to keep 2–3 free model IDs handy and swap by editing config.toml when you hit a 429.
Can You Use Free Models With Claude Code and Cursor Too?
Yes. The same OpenAI-compatible free endpoints work with other AI coding agents — the "harness" (the tool) and the "brain" (the model) are separable.
- Claude Code: Supports custom base URLs via the
ANTHROPIC_BASE_URLenvironment variable or through a router like OmniRoute, which translates between Anthropic, OpenAI, and Gemini API formats automatically. For setting up a free agent team across tools, see How to Build a Free AI Agent Team With Hermes Agent and OpenCode. - Cursor: Has built-in OpenAI-compatible model configuration in Settings → Models.
- Cline / Copilot / Antigravity: All support OpenAI-compatible endpoints through configuration.
This is the core idea behind a gateway like OmniRoute: connect it once, then point every tool at the same http://localhost:4400/v1 endpoint. You switch models from the OmniRoute dashboard without touching individual tool configs. The same free Claude model (via Kiro) can power Codex CLI, Claude Code, and Cursor simultaneously.
What This Means for You
If you are a developer, student, or solo builder who cannot justify $20–200/month for AI coding subscriptions:
- Start with OpenRouter direct — it takes 2 minutes, gives you 28+ free coding models, and 50 requests/day is enough to test the workflow.
- Upgrade to OmniRoute when you need longer sessions — the auto-fallback across 90+ free providers means you almost never see a rate limit error, and the built-in token compression (15–95%) stretches free-tier limits dramatically. If you want to try other free coding agents, our DeepSeek V4 Flash free setup guide covers five no-cost paths.
- Keep
wire_api = "chat"in your config — this is the single most common setup failure. Third-party providers use Chat Completions, not OpenAI's Responses API. - Re-check limits monthly — free tiers change. OpenRouter's model roster rotates; OmniRoute adds providers. What works today may shift. Bookmark the provider's pricing/models page.
The practical takeaway: you do not need a ChatGPT subscription to use Codex CLI as a serious coding agent. The software is free; the models are free; the only investment is 10 minutes of configuration.
FAQ
Q: Is Codex CLI really free?
A: The Codex CLI software is free and open-source under the Apache 2.0 license. What normally costs money is the OpenAI model it calls by default. By configuring a custom provider in ~/.codex/config.toml pointing at a free OpenAI-compatible endpoint, you can run Codex CLI at $0/month.
Q: What is the best free model for coding in Codex CLI?
A: As of August 2026, qwen/qwen3-coder:free on OpenRouter is the strongest free coding model with 262K context. For Claude-quality results, use OmniRoute's Kiro provider (kr/claude-sonnet-4.5) which offers unlimited free access. For long-context reasoning, nvidia/nemotron-3-ultra-550b-a55b:free provides 1M context.
Q: How much can I use a free model before hitting limits? A: On OpenRouter's free tier without credits: 20 requests per minute, 50 requests per day. A one-time $10 credit raises the daily limit to 1,000 permanently. With OmniRoute's stacked RTK + Caveman compression saving 78–95% of tokens on tool-heavy sessions, your effective capacity multiplies by 4–20x.
Q: Why does my custom provider return a 401 or 404 error?
A: A 401 means the API key environment variable is not set or is invalid — verify the env_key in config.toml matches your exported variable name. A 404 usually means the model ID is wrong or the provider does not host that model. A 429 means you hit a rate limit. Also confirm wire_api = "chat" is set, as most third-party providers do not support OpenAI's Responses API.
Q: Can I run Codex CLI with no internet connection?
A: Codex CLI itself runs locally, but it needs to reach a model API. For fully offline use, you can point it at a local model via Ollama (--provider ollama) or a self-hosted inference server. Free cloud models (OpenRouter, OmniRoute, Groq) require internet.
Q: Does token compression affect code quality? A: RTK and Caveman compression target whitespace, filler language, and verbose tool output — code blocks, URLs, and structured data are preserved byte-perfect. In practice, compressed sessions produce equivalent results because the compression removes noise, not meaning. However, test on your own payloads to confirm, as compression behavior is payload-dependent.

Discussion
0 comments