Run Codex CLI with a Local Model on Mac (MLX Setup)

Three commands connect Codex CLI to a local model on your Mac through the Responses API.

Start with rapid-mlx serve qwen3.5-9b-4bit in one terminal. In another, run rapid-mlx agents codex --setup, then codex in your project. Full Codex setup and config.

To run Codex CLI with a local model, install Codex and Rapid-MLX, serve a model, run rapid-mlx agents codex --setup, then start codex. Setup writes Codex's local provider to ~/.codex/config.toml; its default base URL is http://localhost:8000/v1.

brew install rapid-mlx codex
rapid-mlx serve qwen3.5-9b-4bit --port 8000  # terminal 1; keep running
rapid-mlx agents codex --setup                # terminal 2
codex                                         # in your project directory

Codex appends /responses to the configured /v1 base URL. If you serve on another port, pass the printed URL ending in /v1 to setup with --base-url. The v0.16.5 Codex guide recommends qwen3.5-9b-4bit as the practical floor for a 16 GB Mac; smaller models can struggle with file edits.

Codex CLI is OpenAI's terminal coding agent. It talks to models over the Responses API (/v1/responses), and Rapid-MLX serves that same API on your Mac, so the agent loop is unchanged: it reads, edits and runs code, just against a local model.

The whole thing

  1. Install Rapid-MLX and serve a model.
  2. rapid-mlx agents codex --setup writes ~/.codex/config.toml.
  3. codex in your project.

1 · Install Rapid-MLX and Codex

curl -fsSL https://rapidmlx.com/install.sh | bash
npm install -g @openai/codex

Rapid-MLX is also in Homebrew core: brew install rapid-mlx.

2 · Serve a model

rapid-mlx serve qwen3.5-9b-4bit

The v0.16.5 Codex guide calls this the practical floor for a 16 GB Mac; keep the server running. rapid-mlx recipe prints a pick for your memory, and Best local LLMs by Mac shows measured speeds per chip.

3 · Point Codex at it

rapid-mlx agents codex --setup

It checks that the server answers, then writes ~/.codex/config.toml with:

An existing config.toml is merged: your other settings are kept, but comments are not and no backup is made, so copy the file first if it matters to you. --dry-run reports whether it would write or merge, without touching the file. Setup ends by printing the saved model, provider and endpoint, read back from the file.

The provider block it writes is the whole trick:

model_provider = "rapid-mlx"

[model_providers.rapid-mlx]
name = "Rapid-MLX (local)"
base_url = "http://localhost:8000/v1"

base_url includes /v1: Codex appends /responses to it. A plain rapid-mlx serve needs no key. If you start the server with RAPID_MLX_API_KEY set, export it before running setup, and keep it exported in the shell you run Codex from.

4 · Run it

Start codex in a project, or hand it one task:

# inside your project folder
codex exec "Add a function add(a, b) to hello.py that returns a + b. Edit the file."

From our run, trimmed:

exec
/bin/zsh -lc 'cat hello.py'
def greet(name):
    return "Hello, " + name

def add(a, b):
    return a + b

codex
I've added the `add(a, b)` function to `hello.py` that returns `a + b`.

Verified on 2026-10-06 with rapid-mlx 0.15.6, Codex CLI 0.160.1 and qwen3.5-4b-4bit on a Mac mini (M2 Pro, 32 GB): after rapid-mlx agents codex --setup, codex exec with the command above, and no extra flags, edited the file; a timed run took about 20 seconds.

What to expect

A local model isn't a frontier cloud model. It's great for private work and the everyday tasks (refactors, tests, questions about the code) with no bill. For the hardest reasoning, switch model_provider back to OpenAI for that task.

Frequently asked questions

How do I run Codex CLI with local models?

Serve a model with Rapid-MLX (rapid-mlx serve qwen3.5-4b-4bit), run rapid-mlx agents codex --setup in a second terminal, then start codex. Setup adds a rapid-mlx model provider with base_url = "http://localhost:8000/v1" to ~/.codex/config.toml and makes it the default, so Codex sends its Responses API requests to the model on your Mac.

What base URL does Codex CLI use for a local model?

http://localhost:8000/v1, including /v1: Codex appends /responses. If you started the server on another port, use that port, or run setup with --base-url.

Can Codex CLI use a local model?

Yes. Codex supports custom model providers. Serve a model with Rapid-MLX and run rapid-mlx agents codex --setup; Codex then uses the model on your Mac through the Responses API at http://localhost:8000/v1.

Does Codex need an OpenAI API key to run locally?

No. A plain rapid-mlx serve doesn't require a key, and setup doesn't add one. If you protect the server with RAPID_MLX_API_KEY, setup makes Codex read that variable. Rapid-MLX itself sends anonymous usage counts by default, never prompts or code; rapid-mlx telemetry off turns that off (details).

Which local model works best with Codex?

Use the largest model rapid-mlx recipe suggests for your Mac. Codex relies on tool calls and long context, so qwen3.8-27b-4bit (32 GB and up) or qwen3.6-35b-4bit (48 GB and up) are better partners than a 4B model.

Where to go next


Run this yourself. Rapid-MLX is an open-source, OpenAI- and Anthropic-compatible inference server for Apple Silicon. One command installs it, then rapid-mlx serve <alias> serves any model on localhost:8000/v1.
curl -fsSL https://rapidmlx.com/install.sh | bash

New models and speedups, in your inbox

A short note whenever Rapid-MLX gets faster or adds models worth running on your Mac. No spam — unsubscribe anytime.