New Tool Radar

Local AI

How to Serve an MLX Model on Localhost with mlx_lm.server

Start mlx_lm.server on an Apple Silicon Mac to serve a local model through an OpenAI-compatible API on localhost:8080 for your own apps.

Schematic diagram with three boxes: the command mlx_lm.server with an MLX model, the server on localhost port 8080, and a curl chat request to v1 chat completions.

A chat REPL is for you; a server is for your other apps. mlx_lm.server turns an MLX model into an HTTP API for text generation that is compatible with the OpenAI chat API, so an editor plugin, a script, or any tool that speaks the OpenAI format can use the model on your Mac without the model leaving the machine. The server is not a chat window — it answers requests from other programs.

Start the server

Install MLX LM, then start the server with a model. You can provide a path to a local model or a Hugging Face repository ID using the --model flag, and the server defaults to running on localhost:8080:

pip install mlx-lm
mlx_lm.server --model mlx-community/Mistral-7B-Instruct-v0.3-4bit

The first launch downloads the model weights from Hugging Face if they are not already on your computer, so give it time on the first run.

Send it a chat request

Once the server is running, send a request to the /v1/chat/completions endpoint. The request body is a JSON object containing a messages array, where each object has a role and content:

curl localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{ "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7 }'
Check What you should see If you do not see it
Server up The mlx_lm.server command keeps running without an error Read the terminal output — the model may still be downloading
Model list curl localhost:8080/v1/models lists the model you started The server started with a different model, or has not finished loading
Chat reply The response contains “This is a test!” or words to that effect Check the request body and the server log

Expected result. We checked the MLX LM docs for the server command, its default address, and the chat request shape. We did not run mlx_lm.server or send a request.

Limits

The MLX LM docs say this server is not recommended for production due to basic security implementations, so keep it on localhost and do not expose it to the internet. A third-party MLX server guide reports that the server caps replies at 512 tokens by default unless a request sets max_tokens, so a long answer may stop short — that detail is third-party, not from the project’s own docs, so confirm it against your installed version. This needs an Apple Silicon Mac; MLX LM is built for Apple silicon. We did not run mlx_lm.server, so no reply here is a recorded result.

Sources

See all