How to Connect Third‑Party LLMs to Codex App, CLI, and SDK
This guide explains how to configure Codex’s App, CLI, and SDK to use third‑party large language models such as Qwen, MiniMax, DeepSeek, and local Ollama/LM‑Studio models by adding provider entries to the ~/.codex/config.toml file and selecting the appropriate wire_api (chat or responses).
Provider configuration basics
Codex App, CLI, and SDK can connect to any LLM that implements a compatible OpenAI‑style API. The connection details are defined in a provider block placed in the user‑level configuration file ~/.codex/config.toml. Project‑local .codex/config.toml files are ignored.
A provider block consists of four keys: name – human‑readable identifier base_url – HTTP endpoint of the model API env_key – name of the environment variable that holds the API key wire_api – protocol to use ("responses" or the legacy "chat")
Reserved provider IDs openai, ollama, lmstudio, and amazon‑bedrock cannot be reused for custom providers.
Example: Adding Qwen (DashScope) as a provider
[model_providers.qwen]
name = "Qwen 通义千问 (DashScope)"
base_url = "https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
env_key = "DASHSCOPE_API_KEY"
wire_api = "responses"After saving the file, export the API key:
export DASHSCOPE_API_KEY="<YOUR_KEY>"To select the model without editing the file, override the configuration on the command line:
codex -c model='"qwen3.7-max"' -c model_provider='"qwen"'Wire API selection
The wire_api field tells Codex which protocol to use. Earlier versions accepted chat, which maps to the OpenAI /v1/chat/completions endpoint. Starting with codex‑cli 0.140.0 , chat is treated as a hard error. The recommended value is responses, which maps to the newer /v1/responses endpoint.
Models that already support the Responses API
Qwen (DashScope) – use the /v2/apps/protocols/compatible-mode/v1 path.
MiniMax – supports POST /v1/responses.
Step models from 阶跃星辰 – also expose the Responses endpoint.
model = "MiniMax-M3"
model_provider = "minimax"
model_context_window = 512000
[model_providers.minimax]
name = "MiniMax"
base_url = "https://api.minimaxi.com/v1"
experimental_bearer_token = "<MINIMAX_API_KEY>"
wire_api = "responses"Models that only expose Chat Completions
DeepSeek, GLM, Kimi, and Xiaomi MiMo currently provide only /chat/completions or Anthropic‑compatible endpoints. To use them with Codex you must either:
Set wire_api = "responses" and run a proxy that translates Responses requests to Chat Completions, or
Employ an existing bridge such as cc-switch, mimo2codex, or va-ai-api-bridge.
Local model providers
Codex includes built‑in support for local providers via Ollama and LM‑Studio. Launch a local model without writing a provider block by using the --oss flag:
codex --oss-m <MODEL_NAME>Or set the default local provider in config.toml:
oss_provider = "ollama" # or "lmstudio"Ollama (v0.13.3+) and LM‑Studio both implement the OpenAI‑compatible POST /v1/responses endpoint, allowing direct use with Codex as long as the host machine has sufficient resources.
Key points
Add a third‑party LLM by creating a provider entry in ~/.codex/config.toml with the appropriate wire_api value.
Prefer responses over the deprecated chat protocol (codex‑cli 0.140.0 enforces this).
Verify that the target model supports the Responses API; otherwise use a translation proxy or bridge.
Local models can be accessed directly via the --oss flag or by setting oss_provider to ollama or lmstudio.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
