Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

chore: change `built_in_model_providers` so "openai" is the only "bundled" provider (#1407)

Michael Bolina331a67b3e95
diff --git a/codex-rs/config.md b/codex-rs/config.md
index bb8b67162c..de9e4ec976 100644
--- a/codex-rs/config.md
+++ b/codex-rs/config.md
@@ -20,18 +20,32 @@ The model that Codex should use.
model = "o3" # overrides the default of "codex-mini-latest"
```
-## model_provider
+## model_providers
-Codex comes bundled with a number of "model providers" predefined. This config value is a string that indicates which provider to use. You can also define your own providers via `model_providers`.
+This option lets you override and amend the default set of model providers bundled with Codex. This value is a map where the key is the value to use with `model_provider` to select the corresponding provider.
-For example, if you are running ollama with Mistral locally, then you would need to add the following to your config:
+For example, if you wanted to add a provider that uses the OpenAI 4o model via the chat completions API, then you could add the following configuration:
```toml
-model = "mistral"
-model_provider = "ollama"
+# Recall that in TOML, root keys must be listed before tables.
+model = "gpt-4o"
+model_provider = "openai-chat-completions"
+
+[model_providers.openai-chat-completions]
+# Name of the provider that will be displayed in the Codex UI.
+name = "OpenAI using Chat Completions"
+# The path `/chat/completions` will be amended to this URL to make the POST
+# request for the chat completions.
+base_url = "https://api.openai.com/v1"
+# If `env_key` is set, identifies an environment variable that must be set when
+# using Codex with this provider. The value of the environment variable must be
+# non-empty and will be used in the `Bearer TOKEN` HTTP header for the POST request.
+env_key = "OPENAI_API_KEY"
+# Valid values for wire_api are "chat" and "responses".
+wire_api = "chat"
```
-because the following definition for `ollama` is included in Codex:
+Note this makes it possible to use Codex CLI with non-OpenAI models, so long as they use a wire API that is compatible with the OpenAI chat completions API. For example, you could define the following provider to use Codex CLI with Ollama running locally:
```toml
[model_providers.ollama]
@@ -40,39 +54,27 @@ base_url = "http://localhost:11434/v1"
wire_api = "chat"
```
-This option defaults to `"openai"` and the corresponding provider is defined as follows:
+Or a third-party provider (using a distinct environment variable for the API key):
```toml
-[model_providers.openai]
-name = "OpenAI"
-base_url = "https://api.openai.com/v1"
-env_key = "OPENAI_API_KEY"
-wire_api = "responses"
+[model_providers.mistral]
+name = "Mistral"
+base_url = "https://api.mistral.ai/v1"
+env_key = "MISTRAL_API_KEY"
+wire_api = "chat"
```
-## model_providers
+## model_provider
-This option lets you override and amend the default set of model providers bundled with Codex. This value is a map where the key is the value to use with `model_provider` to select the correspodning provider.
+Identifies which provider to use from the `model_providers` map. Defaults to `"openai"`.
-For example, if you wanted to add a provider that uses the OpenAI 4o model via the chat completions API, then you
+Note that if you override `model_provider`, then you likely want to override
+`model`, as well. For example, if you are running ollama with Mistral locally,
+then you would need to add the following to your config in addition to the new entry in the `model_providers` map:
```toml
-# Recall that in TOML, root keys must be listed before tables.
-model = "gpt-4o"
-model_provider = "openai-chat-completions"
-
-[model_providers.openai-chat-completions]
-# Name of the provider that will be displayed in the Codex UI.
-name = "OpenAI using Chat Completions"
-# The path `/chat/completions` will be amended to this URL to make the POST
-# request for the chat completions.
-base_url = "https://api.openai.com/v1"
-# If `env_key` is set, identifies an environment variable that must be set when
-# using Codex with this provider. The value of the environment variable must be
-# non-empty and will be used in the `Bearer TOKEN` HTTP header for the POST request.
-env_key = "OPENAI_API_KEY"
-# valid values for wire_api are "chat" and "responses".
-wire_api = "chat"
+model = "mistral"
+model_provider = "ollama"
```
## approval_policy
diff --git a/codex-rs/core/src/model_provider_info.rs b/codex-rs/core/src/model_provider_info.rs
index 44b406c985..a0e0aeb245 100644
--- a/codex-rs/core/src/model_provider_info.rs
+++ b/codex-rs/core/src/model_provider_info.rs
@@ -83,6 +83,10 @@ impl ModelProviderInfo {
pub fn built_in_model_providers() -> HashMap<String, ModelProviderInfo> {
use ModelProviderInfo as P;
+ // We do not want to be in the business of adjucating which third-party
+ // providers are bundled with Codex CLI, so we only include the OpenAI
+ // provider by default. Users are encouraged to add to `model_providers`
+ // in config.toml to add their own providers.
[
(
"openai",
@@ -94,76 +98,6 @@ pub fn built_in_model_providers() -> HashMap<String, ModelProviderInfo> {
wire_api: WireApi::Responses,
},
),
- (
- "openrouter",
- P {
- name: "OpenRouter".into(),
- base_url: "https://openrouter.ai/api/v1".into(),
- env_key: Some("OPENROUTER_API_KEY".into()),
- env_key_instructions: None,
- wire_api: WireApi::Chat,
- },
- ),
- (
- "gemini",
- P {
- name: "Gemini".into(),
- base_url: "https://generativelanguage.googleapis.com/v1beta/openai".into(),
- env_key: Some("GEMINI_API_KEY".into()),
- env_key_instructions: None,
- wire_api: WireApi::Chat,
- },
- ),
- (
- "ollama",
- P {
- name: "Ollama".into(),
- base_url: "http://localhost:11434/v1".into(),
- env_key: None,
- env_key_instructions: None,
- wire_api: WireApi::Chat,
- },
- ),
- (
- "mistral",
- P {
- name: "Mistral".into(),
- base_url: "https://api.mistral.ai/v1".into(),
- env_key: Some("MISTRAL_API_KEY".into()),
- env_key_instructions: None,
- wire_api: WireApi::Chat,
- },
- ),
- (
- "deepseek",
- P {
- name: "DeepSeek".into(),
- base_url: "https://api.deepseek.com".into(),
- env_key: Some("DEEPSEEK_API_KEY".into()),
- env_key_instructions: None,
- wire_api: WireApi::Chat,
- },
- ),
- (
- "xai",
- P {
- name: "xAI".into(),
- base_url: "https://api.x.ai/v1".into(),
- env_key: Some("XAI_API_KEY".into()),
- env_key_instructions: None,
- wire_api: WireApi::Chat,
- },
- ),
- (
- "groq",
- P {
- name: "Groq".into(),
- base_url: "https://api.groq.com/openai/v1".into(),
- env_key: Some("GROQ_API_KEY".into()),
- env_key_instructions: None,
- wire_api: WireApi::Chat,
- },
- ),
]
.into_iter()
.map(|(k, v)| (k.to_string(), v))