mlx-optiq
Integration · Codex

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.

terminalbash
# 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

terminalbash
$ npm install -g @openai/codex

2. Start optiq serve

terminalbash
$ optiq serve \
    --model mlx-community/Qwen3.5-9B-OptiQ-4bit \
    --mtp --mtp-depth 1 \
    --port 8080

The default --responses flag installs /v1/responses; --mtp adds the Qwen3.5 / 3.6 MTP head, measured at 1.20-1.40× decode speed at depth 1 (see speculative decoding).

3. Configure Codex

Edit ~/.codex/config.toml and add:

~/.codex/config.tomltoml
[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:

terminalbash
export OPTIQ_API_KEY=sk-optiq-local

$ codex -p optiq

On an OptiQ Cloud model

To run Codex on an OptiQ Cloud model with no local model loaded (optiq run codex --cloud glm-5.3-flash), see Use with coding agents.

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.delta and response.completed events; both are emitted in spec-compliant order.
  • Verified: tested against Codex v0.153.4, including optiq run on macOS (Apple Silicon). optiq run --cloud on GLM 5.3 Flash and DeepSeek V4.1 Flash with Codex 0.163.0.
Codex + MTP on Apple Silicon Codex's edit-run-review loop is decode-heavy. The MTP speculation in --mtp accepts about two drafts in three on Qwen3.5/3.6 (66-72% measured greedy). Pairs well with longer max_tokens settings since the MTP head amortizes the per-token cost.