Codex CLI Third-Party API Setup Guide
As of 2026-10-07, you connect Codex CLI to a third-party or custom API endpoint by adding your own table under model_providers in ~/.codex/config.toml, with base_url, wire_api and env_key (the name of the environment variable that holds your key), and pointing the top-level model_provider at it; the official config reference says responses is the only supported wire_api value. For QCode, base_url is https://api.qcode.cc/openai and env_key is the name of the environment variable you choose to hold your QCode key. This page walks through each key, the common errors and which models to pick.
Updated 2026-10-07
Four values to get right
The only wire_api value
The official config reference states that responses is the only supported value and also the default when the field is omitted. QCode's docs set wire_api to responses too, which maps to the /openai/v1/responses path.
env var that holds the key
env_key holds the name of an environment variable, not the key itself; the official wording is the environment variable supplying the provider API key. QCode keys start with cr_. You can pick the variable name yourself; the QCode docs example uses CRS_OAI_KEY.
Where QCode's base_url ends
QCode's docs say Codex's base_url must be https://api.qcode.cc/openai; Codex speaks the Responses protocol, so requests land on /openai/v1/responses.
Newest CLI in the official changelog
The official changelog lists Codex CLI 0.160.1 on 2026-10-05; since 0.159.1 (2026-09-29) the bundled model catalog uses GPT-6.1 Sol as its default model.
How Codex picks an endpoint
As of 2026-10-07, Codex CLI decides where requests go from model_provider in config.toml: its value is the id of a table under model_providers, and it defaults to openai when unset. The official docs say a model provider defines how Codex connects to a model, covering the base URL, wire API, authentication and optional HTTP headers, and custom providers can't reuse the reserved built-in ids openai, ollama and lmstudio. User-level config lives in ~/.codex/config.toml (on Windows under %USERPROFILE%\.codex\); a project's .codex/config.toml loads only once you trust the project, and model_provider and model_providers are ignored at that project level. QCode's docs name the provider crs and use the OpenAI Responses protocol, and the same key works on api.qcode.cc, us.qcode.cc and asia.qcode.cc.
Recent releases that touch providers
Per the official changelog: from 2026-09-22 GPT-6 Sol and GPT-6 Luna began rolling out to Codex, selectable in the CLI with /model or codex --model gpt-6-sol; on 2026-09-29 Codex CLI 0.159.1 made GPT-6.1 Sol the default model in the bundled catalog; 0.160.0 on 2026-10-01 clarified how env_key identifies the API-key environment variable, stopped explicit provider model catalogs from including unsupported bundled models, and made the terminal UI keep server provider settings; 0.160.1 followed on 2026-10-05. Separately, an official notice of 2026-09-14 says GPT-5.5 retires from ChatGPT, ChatGPT Work and Codex on 2026-10-14 (the retirement does not apply to the OpenAI API), and asks you to update saved model settings, custom agents and scripts that still select gpt-5.5. Check your local version with codex --version.
Timeline
GPT-6 Sol and GPT-6 Luna start rolling out to Codex; OpenAI recommends Sol for complex coding and agentic workflows, and in the CLI you switch with /model or codex --model gpt-6-sol.
GPT-6.1 Sol arrives in Codex; the same day Codex CLI 0.159.1 makes it the default model in the bundled catalog. QCode's docs list gpt-6.1-sol as the updated GPT-6 Sol.
Codex CLI 0.160.1 ships, the newest CLI entry in the official changelog when this page was checked on 2026-10-07; before it, 0.160.0 on 2026-10-01 had clarified the env_key documentation.
Confirmed vs not verified
Confirmed (verbatim in official pages and QCode docs)
Official Codex docs: model_provider defaults to openai; openai, ollama and lmstudio are reserved ids that can't be overridden; responses is the only supported wire_api value and the default when omitted; env_key is the environment variable supplying the API key; requires_openai_auth defaults to false; putting a direct bearer token in experimental_bearer_token is discouraged; model and model_provider must sit before the first TOML table. Official changelog: GPT-6.1 Sol is the bundled catalog default from 0.159.1, and 0.160.1 shipped on 2026-10-05. QCode docs: base_url is https://api.qcode.cc/openai, wire_api is responses, requires_openai_auth is true, env_key is CRS_OAI_KEY, keys start with cr_, and auth.json takes precedence when both it and the environment variable are set.
Not verified or not documented
Four points are unverified, so don't build on them: first, QCode's example includes a preferred_auth_method line, but the official config reference fetched for this page on 2026-10-07 has no such entry, so its effect in current versions is unverified; second, the official reference also offers a command-backed auth table, http_headers, supports_websockets and more, which QCode's docs don't cover, and this page makes no promise they work with QCode; third, whether Codex releases before 0.159.1 recognize the name gpt-6.1-sol was not checked, and the official gateway doc only says that without a custom catalog you should first confirm your Codex version recognizes the model; fourth, OpenAI says GPT-6.1 Sol offers near-Astra performance at a lower cost than Astra, which is the vendor's own claim with no third-party measurement.
Two choices to settle
Custom provider vs openai_base_url
The official docs offer two routes: if you only need to point the built-in openai provider at a proxy or router, set openai_base_url instead of defining a new provider; if you need your own key variable and protocol settings, add a table under model_providers. You can't create a table named openai, because built-in ids can't be overridden. QCode's docs use the second route (provider crs) and don't document openai_base_url, so this page doesn't recommend it for QCode.
auth.json vs environment variable
QCode's docs say to pick one: put OPENAI_API_KEY in ~/.codex/auth.json, or set the environment variable CRS_OAI_KEY. If both exist, auth.json wins, so when you switch to the variable, set OPENAI_API_KEY in auth.json to null. OpenAI advises keeping credentials out of TOML files and repositories, and notes that a variable set in a terminal may not be available to an app launched from the desktop.
Five steps to connect QCode
Following QCode's docs: ① create the config folder ~/.codex (on Windows, %USERPROFILE%\.codex); ② put the top-level keys at the start of config.toml: model_provider set to crs, model set to gpt-6-sol or gpt-6.1-sol, and optionally model_reasoning_effort; they must come before the first table header, or they are read as part of that table; ③ add a model_providers.crs table with name crs, base_url https://api.qcode.cc/openai, wire_api responses, requires_openai_auth true and env_key CRS_OAI_KEY (from North America and Europe you can swap the host for us.qcode.cc); ④ supply the key, either by exporting CRS_OAI_KEY with your cr_ key or by writing it as OPENAI_API_KEY in ~/.codex/auth.json, not both; ⑤ start codex and run /status to confirm the active model and provider, or run codex doctor to check the config.
Using Codex on QCode
Copy a key starting with cr_ from the QCode console and follow the five steps above; or use the one-click setup script from QCode's docs, which installs the CLI, writes the ~/.codex config and runs a connectivity check. Codex speaks the OpenAI Responses protocol, so what it runs on QCode is the GPT family: gpt-6.1-sol, gpt-6-sol, gpt-5.6-sol, gpt-5.6-terra, gpt-6-astra and gpt-6-luna can all be called, and you switch by changing model only; Claude and the GLM, Kimi, DeepSeek and Qwen models don't use this protocol. The same key also works in Claude Code. Billing is per token; per-model prices are on /models.
Frequently asked questions
What do I change to use a third-party API in Codex CLI?
Two things in ~/.codex/config.toml: point the top-level model_provider at your own provider id, then add a table for that id under model_providers with base_url, wire_api and env_key. The official config reference says responses is the only supported wire_api value and env_key names the environment variable that supplies the API key; requires_openai_auth marks a provider that uses OpenAI authentication, defaults to false, and QCode's docs set it to true.
What goes in base_url? Do I add /v1?
For QCode, use https://api.qcode.cc/openai, with no /v1 and no trailing slash. QCode's docs say Codex's base_url must be exactly this, and Codex then uses the /openai/v1/responses path. The endpoints doc's general rule is to leave off the trailing slash, since it produces a double-slash path and a 404; a 404 usually means the path prefix is wrong. The Asia backup is https://asia.qcode.cc/openai, and us.qcode.cc serves North America and Europe.
What if I get 401 or API key not found?
Check three things: that the key starts with cr_ and the one in auth.json has no stray spaces or line breaks; when you use an environment variable, that its name is exactly what env_key says in config.toml (CRS_OAI_KEY in QCode's docs) and that it is really set in the current shell; and finally the key's status in the QCode console. Remember that auth.json wins when both are present, so if you rely on the variable, set OPENAI_API_KEY in auth.json to null.
I edited config.toml, so why isn't my provider active?
Most often a top-level key is in the wrong place: the official docs say model and model_provider must come before the first TOML table, because keys after a table header belong to that table. Next, a project's .codex/config.toml ignores model_provider and model_providers, so the provider has to live in your user-level ~/.codex/config.toml, and the table can't be named openai. Also, QCode's docs note that since Codex 0.134.0 the old profiles tables in config.toml are retired, and running --profile while they are still there is a hard error. After starting, /status shows the active model and provider.
Can I use Claude models in Codex? What does model_not_available_on_endpoint mean?
Not on QCode. QCode's docs say Codex uses the OpenAI Responses protocol, which serves only the GPT family, not Claude or the GLM, Kimi, DeepSeek and Qwen models; Claude models only work over the Anthropic protocol. The docs' example: sending a Claude model to /openai/v1/chat/completions returns model_not_available_on_endpoint, and that check runs before authentication, so it means the wrong protocol, not a bad key. For Claude, use Claude Code with the same key.
Which model should I use with Codex on QCode?
As of 2026-10-07, QCode's docs recommend gpt-6-sol by default (1.05M context, general and complex work); gpt-6.1-sol is the GPT-6 Sol update of 2026-09-29, also with 1.05M context and, per the docs, cheaper cache reads, and it has been the bundled catalog default in official Codex since 0.159.1; gpt-5.6-sol belongs to the GPT-5.6 flagship line, gpt-5.6-terra is tuned for code, gpt-6-astra is the top tier at a high price, and gpt-6-luna is what OpenAI positions for focused, high-volume tasks, with its price on /models. All of them can be called on QCode; switch by changing model or with codex --model.
Sources
Codex config keys: OpenAI's official Codex configuration reference and advanced configuration docs (learn.chatgpt.com, fetched 2026-10-07), covering the model_provider default, reserved ids, the wire_api value, env_key and requires_openai_auth, openai_base_url and the keys ignored at project level. Top-level key placement, credential handling and the /status check: the official Connect to a gateway doc, fetched the same day. Versions and models: the official ChatGPT and Codex changelog, fetched the same day (0.159.1, 0.160.0, 0.160.1 the GPT-6 Sol and GPT-6.1 Sol announcements, and the GPT-5.5 retirement notice). QCode's setup, base_url, env_key name, key prefix and model list: the Codex complete guide, Codex quick start and endpoints and API formats pages on docs.qcode.cc, fetched 2026-10-07.
Connect Codex with one key
Set base_url to https://api.qcode.cc/openai and pick gpt-6.1-sol, gpt-6-sol or gpt-5.6-sol, billed per token, ready the moment you sign up.
Related reading
Codex CLI Complete Guide
Installing and configuring OpenAI Codex CLI, and how it compares with Claude Code.
Use GPT-5.6 in Codex CLI
Four steps to run gpt-5.6-sol and gpt-5.6-terra in Codex CLI via QCode.
Codex 5-Hour Rolling Limit Guide
How the 5-hour rolling limit works, its timeline, and what to do when you hit it.
The config keys and version details on this page were checked on 2026-10-07 against OpenAI's official Codex docs and changelog and QCode's docs; go by the official pages, as changes on OpenAI's side may happen without notice. This page promises no compatibility beyond what the docs state; model availability is whatever /models shows.