OSS mode in Codex CLI removes hard lock-in to OpenAI’s hosted models. Running Ollama or LM Studio on a local machine and pointing Codex at the local API endpoint is all it takes to get started, and the same mechanism connects to internal enterprise model gateways or external routers like OpenRouter.

Defining Local Model Providers

Connecting a local model starts with adding a provider block to ~/.codex/config.toml. Codex CLI expects an OpenAI-compatible API endpoint, and configuring wire_api = "responses" is the safest choice for Ollama since legacy chat completions support is slated for deprecation.

model = "qwen2.5-coder:32b"
model_provider = "local_ollama"
oss_provider = "ollama"

[model_providers.local_ollama]
name = "Ollama"
base_url = "http://localhost:11434/v1"
wire_api = "responses"

LM Studio uses nearly the same setup - switching the port to 1234 connects immediately on localhost. When connecting to an external model gateway, place the API key inside the experimental_bearer_token field, and keep these config files strictly in your local home directory out of version control.

Standalone Profile Files Starting in v0.134.0

Starting with Codex 0.134.0, profile definitions must live in separate configuration files. Older tutorials referencing inline [profiles.xxx] tables inside a single config file no longer work. Instead, each profile gets its own dedicated file such as ~/.codex/fast-coder.config.toml.

model = "qwen2.5-coder:7b"
model_provider = "local_ollama"
model_reasoning_effort = "low"

[model_providers.local_ollama]
name = "Ollama"
base_url = "http://localhost:11434/v1"
wire_api = "responses"

Passing the –profile flag at launch selects the desired setup. Splitting lightweight local models and heavier models into separate profiles makes hardware management simple - for example, routing complex architectural reviews to a frontier cloud model while keeping routine edits on a fast local coder model.

Checking Protocol Compatibility Before Real Edits

If a local API server does not match OpenAI’s wire spec closely, runtime failures crop up frequently around streaming responses and tool calls. Running a quick smoke test before handing over multi-file edits saves wasted debugging time.

Protocol mismatches also remain the most fragile link on self-hosted vLLM or SGLang deployments, where endpoints that look compatible on the surface often fail during tool-argument parsing. Testing tool calls on a disposable dummy file first ensures your local backend can handle real repository edits cleanly.

On capable local hardware, OSS mode cuts API bills sharply while letting engineers tailor Codex CLI to their own model stack.

Summary

  • Codex CLI 0.134.0 and later require standalone per-profile config files rather than inline [profiles.xxx] tables.
  • Setting wire_api = "responses" instead of legacy chat mode avoids upcoming deprecation and reduces local LLM protocol issues.
  • Verifying streaming and tool-call compatibility on dummy files first prevents broken edits on local Ollama, vLLM, or SGLang endpoints.