Codex
OpenAI's Codex CLI uses the OpenAI Responses API exclusively (Chat Completions was deprecated for Codex in 2026). optiq serve exposes /v1/responses by default so Codex talks to your local OptiQ-quantized model with a one-block config addition.
Quick start: optiq run
One command starts optiq serve for the model (or reuses one already running on the port), configures Codex for that session only, and launches it. When Codex exits, a server it started is stopped. Arguments after -- go to Codex.
# interactive $ optiq run codex -m mlx-community/Qwen3.5-9B-OptiQ-4bit # one-shot, non-interactive $ optiq run codex -m mlx-community/Qwen3.5-9B-OptiQ-4bit -- exec "fix the failing test"
The provider is passed as -c overrides for that session, together with the model's context window, so ~/.codex/config.toml is never edited.
The steps below set up the same connection by hand, for when you run optiq serve yourself. See optiq run for every option.
1. Install Codex
$ npm install -g @openai/codex
2. Start optiq serve
$ optiq serve \ --model mlx-community/Qwen3.5-9B-OptiQ-4bit \ --mtp --mtp-depth 2 \ --port 8080
The default --responses flag installs /v1/responses; --mtp adds in-checkpoint MTP speculation for ~1.4-1.8× decode speedup on Qwen3.5 / 3.6 family.
3. Configure Codex
Edit ~/.codex/config.toml and add:
[model_providers.optiq] name = "OptiQ Local" base_url = "http://localhost:8080/v1" env_key = "OPTIQ_API_KEY" wire_api = "responses" requires_openai_auth = false [profiles.optiq] model_provider = "optiq" model = "mlx-community/Qwen3.5-9B-OptiQ-4bit"
Then export the auth token and launch Codex with this profile:
export OPTIQ_API_KEY=sk-optiq-local $ codex -p optiq
On an OptiQ Cloud model
With an OptiQ Cloud login (optiq cloud login), Codex can run on one of OptiQ Cloud's models, billed per token from your balance. No local model is loaded.
$ optiq run codex --cloud glm-5.3-flash $ optiq run codex --cloud deepseek-v4.1-flash
If you run optiq serve yourself, pick the model optiq-cloud/glm-5.3-flash or optiq-cloud/deepseek-v4.1-flash in the setup above; optiq serve --cloud-only serves only the cloud models. Only clients on the same Mac as optiq serve can use them. Prices and limits are on OptiQ Cloud.
Notes
- wire_api = "responses" is required. Codex no longer accepts
wire_api = "chat". - Tool calls: Codex relies on function-calling for its edit / run / search loop. Models without robust function-calling training won't drive the full agent. Qwen3.5-9B-OptiQ and up handle this well; smaller models work for plain chat only.
- Built-in tools (web_search, file_search, computer_use): silently dropped by our shim. Codex's local-tool stack (apply_patch, shell, etc.) runs in the CLI itself and works fine.
- Streaming: works. Codex relies on
response.output_text.deltaandresponse.completedevents; both are emitted in spec-compliant order. - Verified: tested against Codex v0.153.4, including
optiq runon macOS (Apple Silicon).optiq run --cloudon GLM 5.3 Flash and DeepSeek V4.1 Flash with Codex 0.163.0.
--mtp stays at ~70% acceptance on Qwen3.5/3.6 family for typical code-edit prompts. Pairs well with longer max_tokens settings since the MTP head amortizes the per-token cost.