# Codex model providers and config.toml, explained

> Codex picks its model from the model key and its endpoint from the model_provider key in ~/.codex/config.toml, and each custom provider is a [model_providers.<id>] table with a base URL, an environment variable for its API key and the Responses wire API. Profiles are separate files loaded with --profile, -c overrides one key for one run, and --oss runs a local Ollama or LM Studio model. Enabling Auto, the Mac app for all your coding agents, adds it to config.toml after saving a copy of the file, and disabling it switches Codex back.

Author: Tyler J. Cagle (https://x.com/tjcages)
Published: 2026-10-12T14:10:00.000Z
Updated: 2026-11-20T15:20:00.000Z
Reading time: 7 min
Canonical: https://auto.sh/blog/codex-model-providers
Part of: How to choose and change models in Codex and Claude Code (https://auto.sh/blog/models-in-codex-and-claude-code.md)
Publisher: Auto (https://auto.sh)

![Provider keys skip Codex's project config layer. Config layer, highest first: 1. CLI flags and --config; 2. Project .codex/config.toml, Ignored; 3. A --profile file; 4. User ~/.codex/config.toml, Belong here; 5. Cloud-managed defaults; 6. System config; 7. Built-in defaults. Source: OpenAI's Codex configuration docs, checked October 22, 2026.](https://auto.sh/blog/images/codex-model-providers/1-config-layers.png)

Codex decides where each turn goes from two keys in `~/.codex/config.toml`: `model` names the model, and `model_provider` names the provider, which is OpenAI's built-in `openai` provider unless you set another. To reach a different endpoint, you add a `[model_providers.<id>]` table with a `name`, a `base_url`, an `env_key` that names the environment variable holding the API key, and a `wire_api`, where `responses` is the only supported value ([OpenAI config reference](https://learn.chatgpt.com/docs/config-file/config-reference)). Auto, the [Mac app for all your coding agents](https://autorouter.com/), makes this edit for you: enabling it adds Auto to `config.toml` after saving a copy of the file, and disabling it switches Codex back.

Auto wrote this post. Every key, flag and example below is quoted from OpenAI's Codex configuration docs or, where marked, from Ollama's docs, as checked on October 22, 2026. OpenAI's Codex docs now live on learn.chatgpt.com, and the old developers.openai.com/codex links redirect there.

## Where does Codex read its model and provider settings?

Codex reads your personal settings from `~/.codex/config.toml`, or from `config.toml` in the folder that `CODEX_HOME` names if you set that variable ([OpenAI docs](https://learn.chatgpt.com/docs/config-file/config-advanced#config-and-state-locations)). OpenAI's [Models page](https://learn.chatgpt.com/docs/models) says "The ChatGPT desktop app, Codex CLI, and IDE extension use the same `config.toml`". The Codex app merged into the ChatGPT desktop app on July 9, 2026 ([What's new](https://learn.chatgpt.com/docs/whats-new)).

When the same key is set in more than one place, Codex uses this order, highest first ([Config basics](https://learn.chatgpt.com/docs/config-file/config-basic#configuration-precedence)):

1. CLI flags and `--config` overrides
2. Project `.codex/config.toml` files, where the one closest to your working directory wins (trusted projects only)
3. A profile file selected with `--profile`
4. Your user config, `~/.codex/config.toml`
5. Cloud-managed defaults for your signed-in workspace
6. System config, `/etc/codex/config.toml` on Unix
7. Built-in defaults

Provider keys skip the project layer. Codex ignores `model_provider`, `model_providers`, `openai_base_url`, `profile` and `profiles` when they appear in a project's `.codex/config.toml`, so provider definitions belong in your user config ([Configuration Reference](https://learn.chatgpt.com/docs/config-file/config-reference#configtoml)).

## Which config.toml keys control the model and provider?

The keys below cover most provider setups. Descriptions follow OpenAI's [Configuration Reference](https://learn.chatgpt.com/docs/config-file/config-reference) as of October 22, 2026; the fields from `name` down sit inside a `[model_providers.<id>]` table.

| Key                                                                   | What it does                                                                                          | Default             |
| --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------- |
| `model`                                                               | The model to use, for example `gpt-6.1-sol`                                                           | A recommended model |
| `model_provider`                                                      | Provider id from `model_providers`                                                                    | `openai`            |
| `openai_base_url`                                                     | Base URL override for the built-in `openai` provider                                                  | Not set             |
| `[model_providers.<id>]`                                              | A custom provider definition; `openai`, `ollama` and `lmstudio` are reserved ids                      | Not set             |
| `name`                                                                | Display name for the provider                                                                         | Not set             |
| `base_url`                                                            | API base URL for the provider                                                                         | Not set             |
| `env_key`                                                             | Environment variable that supplies the provider's API key                                             | Not set             |
| `wire_api`                                                            | Protocol the provider uses; `responses` is the only supported value                                   | `responses`         |
| `http_headers`, `env_http_headers`, `query_params`                    | Static headers, headers filled from environment variables, and extra query parameters on each request | Not set             |
| `request_max_retries`, `stream_max_retries`, `stream_idle_timeout_ms` | HTTP retries, streaming retries and the stream idle timeout                                           | 4, 5 and 300000 ms  |
| `[model_providers.<id>.auth]`                                         | A command that prints a bearer token, for providers that need one fetched                             | Not set             |
| `oss_provider`                                                        | Default local provider for `--oss`: `ollama` or `lmstudio`                                            | Codex asks          |

## How do you add a custom model provider to Codex?

Add a `[model_providers.<id>]` table to `~/.codex/config.toml`, then set `model_provider` to that id and `model` to a model the provider serves. This is the first part of OpenAI's own example, which sends requests through a proxy ([Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced#custom-model-providers)):

```toml
model = "gpt-6.1-sol"
model_provider = "proxy"
[model_providers.proxy]
name = "OpenAI using LLM proxy"
base_url = "http://proxy.example.com"
env_key = "OPENAI_API_KEY"
```

Codex reads the API key from the environment variable that `env_key` names. The reference also lists `experimental_bearer_token` for a token written into the file, marked "discouraged; use `env_key`", and an `[model_providers.<id>.auth]` table that runs a command to fetch a token, which you shouldn't combine with `env_key`. Because `responses` is the only `wire_api` value, the provider has to accept OpenAI's Responses API. For hosted providers' own Codex blocks and the keys they need, see [Try a new model in Codex or Claude Code without another API key](/blog/try-new-models-in-codex-and-claude-code).

If you only want OpenAI traffic to pass through a proxy or router, OpenAI's docs say to set `openai_base_url` "instead of defining a new provider". It changes the base URL of the built-in `openai` provider. A `[model_providers.openai]` table won't work, because built-in provider ids can't be overridden.

```toml
openai_base_url = "https://us.api.openai.com/v1"
```

![Where Codex sends requests decides what you change. Where should requests go? To OpenAI, through a proxy: Set openai_base_url; To Another provider: Add a \[model_providers.<id>\] table; To A local model: Run codex --oss; To One run only: Pass --model or --config. Source: OpenAI's Codex configuration docs, checked October 22, 2026.](https://auto.sh/blog/images/codex-model-providers/2-where-requests-go.png)

## How do profiles work in Codex now?

A profile is a separate file, `~/.codex/<name>.config.toml`, that Codex layers over `config.toml` when you run `codex --profile <name>` ([Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced#profiles)). The file uses top-level keys and only needs the values that differ from your base config. In Codex 0.134.0 and later, `--profile` no longer reads `[profiles.<name>]` tables from `config.toml`, and the top-level `profile = "<name>"` selector is gone, so guides that show those tables are out of date. [How to choose and change models in Codex and Claude Code](/blog/models-in-codex-and-claude-code) sets these next to their Claude Code equivalents.

Ollama's Codex guide uses a profile to keep a local provider apart from your everyday setup ([Ollama docs](https://docs.ollama.com/integrations/codex)). Its profile file is `~/.codex/ollama-launch.config.toml`:

```toml
model = "gpt-oss:120b"
model_provider = "ollama-launch"
model_catalog_json = "/Users/you/.codex/model.json"

[model_providers.ollama-launch]
name = "Ollama"
base_url = "http://localhost:11434/v1/"
wire_api = "responses"
```

Then `codex --profile ollama-launch` starts Codex with that provider, and plain `codex` keeps using your base config. Ollama's own `ollama launch codex` command uses a dedicated Codex profile and refreshes the model catalog for you; `--config` sets it up without launching, and `--restore` removes the profile and the generated catalog.

## How do you change the model or provider for one run?

Pass `--model` (or `-m`) for the model and `-c` (or `--config`) for any other key; both apply to that run only and outrank every config file ([Command line options](https://learn.chatgpt.com/docs/developer-commands?surface=cli)). `-c` values are parsed as TOML, a value that can't be parsed is treated as a string, and nested keys use dot notation. These are OpenAI's examples ([Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced#one-off-overrides-from-the-cli)):

```bash
codex --model gpt-6.1-sol
codex --config model='"gpt-6.1-sol"'
```

## What does codex --oss do?

`--oss` runs Codex against a local open-source model provider, Ollama or LM Studio ([Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced#oss-mode-local-providers)). Choose one for a single run with `--local-provider`, or set a default in `config.toml`:

```toml
# Default local provider used with `--oss`
oss_provider = "ollama" # or "lmstudio"
```

With neither set, the interactive CLI asks you to choose, and `codex exec` exits with an error. Ollama's guide adds the model with `-m`, as in `codex --oss -m gpt-oss:120b`, and recommends a context window of at least 64k tokens for Codex ([Ollama docs](https://docs.ollama.com/integrations/codex)).

## What does Auto change in Codex's config.toml?

Enabling Codex in Auto adds Auto to `config.toml` after saving a copy of the file, and your other settings stay as they are. Once it is enabled, `config.toml` points at `api.autorouter.com`. Auto's [agent setup guide](https://autorouter.com/setup.md) confirms the Codex connection with this check:

```sh
grep -q 'api.autorouter.com' "${CODEX_HOME:-$HOME/.codex}/config.toml" && echo "Codex: connected"
```

Disabling Codex in Auto's settings switches it back. You don't write a provider table, export a key or set an endpoint. Auto adds models from different providers to the Codex model menu under the message box, beside the models already there, plus Auto itself, which picks a model for each turn. In Codex, OpenAI models run on your ChatGPT plan.

Choosing a specific model in the menu sends your turns straight to it; AutoRouter routes only while Auto is the model selected. [How AutoRouter picks a model for each turn](/blog/how-autorouter-picks-a-model) explains the order it follows. Auto runs on macOS 14 or later, is in beta, and sends requests through its servers on their way to each provider ([Auto privacy](https://autorouter.com/privacy)).

## Questions

### Can a project's .codex/config.toml set the model provider?

No. Codex ignores `model_provider`, `model_providers` and `openai_base_url` in a project's `.codex/config.toml`, so provider definitions go in `~/.codex/config.toml`. Project files load only when you trust the project.

### Why did my [profiles.name] table stop working?

Codex 0.134.0 and later no longer reads `[profiles.<name>]` tables or the `profile = "<name>"` selector. Move the table's keys to the top level of `~/.codex/<name>.config.toml`, delete the old table and selector from `config.toml`, and run `codex --profile <name>`.

### Can I point the built-in openai provider at another URL?

Yes. Set `openai_base_url`, which changes the base URL of the built-in `openai` provider without a new provider table. You can't define `[model_providers.openai]`, because `openai`, `ollama` and `lmstudio` are reserved ids.

### Where should a custom provider's API key go?

Put it in an environment variable and name that variable in `env_key`. OpenAI's reference marks `experimental_bearer_token`, a token written into `config.toml`, as discouraged. For short-lived tokens, `[model_providers.<id>.auth]` runs a command that prints one, and Codex refreshes it every 300000 ms unless you change `refresh_interval_ms`.

### Do I need a model_providers entry to use Auto in Codex?

No. Enabling Codex in Auto adds Auto to `config.toml` after saving a copy of the file, and its models appear in the Codex model menu with no keys or endpoints to set up ([Codex setup](/integrations/codex)). Auto makes the same kind of change to Claude Code's `settings.json`; [Claude Code model settings](/blog/claude-code-model-settings) covers that app's own model options.

## Sources

- [OpenAI: Config basics](https://learn.chatgpt.com/docs/config-file/config-basic)
- [OpenAI: Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced)
- [OpenAI: Configuration Reference](https://learn.chatgpt.com/docs/config-file/config-reference)
- [OpenAI: Developer commands, CLI](https://learn.chatgpt.com/docs/developer-commands?surface=cli)
- [OpenAI: Models](https://learn.chatgpt.com/docs/models)
- [OpenAI: What's new](https://learn.chatgpt.com/docs/whats-new)
- [Ollama: Codex CLI](https://docs.ollama.com/integrations/codex)
- [Auto](https://autorouter.com/)
- [Auto agent setup guide](https://autorouter.com/setup.md)
- [Auto privacy](https://autorouter.com/privacy)

## Read next

- [How to use Claude in Codex and GPT in Claude Code](https://auto.sh/blog/claude-in-codex-and-gpt-in-claude-code.md): Use Auto, the Mac app for all your coding agents: connect the AI subscriptions you already pay for, and your Claude plan runs inside Codex and your ChatGPT plan inside Claude Code, with no keys or config. The Free plan connects two subscriptions for $0 a month. Natively, Claude in Codex takes a Responses-compatible gateway such as OpenRouter in `config.toml`, and GPT in Claude Code takes a gateway such as a LiteLLM proxy behind `ANTHROPIC_BASE_URL`; both bill per token on a key.
- [How to choose and change models in Codex and Claude Code](https://auto.sh/blog/models-in-codex-and-claude-code.md): To give each task the right model, use Auto, the Mac app for all your coding agents: it adds models from every leading provider to the picker you already use (Claude Code, Codex, Cursor, etc.) and can pick one for each turn. To choose yourself, give hard, multi-file work a frontier model such as Claude Opus 5.5 or GPT-6.2 Astra and quick edits a fast one such as Claude Haiku 5.5 or GPT-6 Luna. Switch with /model in either app, a launch flag for one session, or a settings file for every session.
- [How to use Codex in Cursor](https://auto.sh/blog/codex-in-cursor.md): Use Auto, the Mac app for all your coding agents, to run your ChatGPT plan inside Cursor's own Agent: connect the plan, enable Cursor, restart it, and new chats start on Auto. To run Codex itself in Cursor, install OpenAI's Codex extension (`openai.chatgpt`) from Cursor's Extensions view, open the Codex sidebar and sign in with ChatGPT; it runs on your ChatGPT plan's Codex limits, from Plus up. Without either, Cursor's Agent bills GPT models from prepaid credit at API list price.

Tags: [Codex](https://auto.sh/blog/tags/codex.md), [Guides](https://auto.sh/blog/tags/guides.md), [Models](https://auto.sh/blog/tags/models.md)

Drafted with AI from the sources linked above, then checked and edited by the Auto team.

Auto is a Mac app for AI model routing in Codex, Claude Code, Cursor and other supported coding agents. It uses eligible connected subscriptions first. See [setup](https://auto.sh/setup.md) and [pricing](https://auto.sh/pricing).
