Run the HTTP server included with MLX LM when you want a local text model to answer requests from another process on the same Apple Silicon Mac. Install the package in an isolated Python environment, select one MLX model, and start the server on loopback. Verify the health route and then send a short chat request. The chat result is the direct test that your selected model and its tokenizer can process the request.
This guide runs the server provided by the MLX LM package. It uses a small published instruction checkpoint to keep the exercise focused on the server. The model name comes from its converter’s repository. The first start can fetch model files if they are absent from the local cache. Allow the download to finish before interpreting a health or chat failure. The deployment is a local development session, using a foreground process you can inspect and stop from Terminal.
Verify the interpreter and install MLX LM
Open Terminal on the Mac that will run both server and client. Run the architecture, Python version, and interpreter checks. An Apple Silicon Mac can also contain a translated shell or an Intel Python. Check the interpreter architecture as well as the machine value, because the package will load through that interpreter. If you see an Intel architecture, use a native Apple Silicon shell and Python installation before continuing.
uname -m
python3 --version
python3 -c 'import platform; print(platform.machine())'
Consult the MLX LM project for its current installation and Python compatibility requirements. Create a new practice directory and virtual environment. This keeps the package separate from other local model tools and lets you open a second experiment with a different package version later. Activate the environment in the first Terminal, then install the package using that Python. The installation command may need internet access even if your model files are already cached. MLX LM repository and installation instructions.
mkdir -p ~/mlx-lm-http-practice
cd ~/mlx-lm-http-practice
python3 -m venv .venv
. .venv/bin/activate
python -m pip install mlx-lm
python -m pip show mlx-lm
mlx_lm.server --help
Look for the executable’s model, host, and port options in its help. Record the installed MLX LM version when those options are present. If the command is absent, inspect the package environment and the active shell before reinstalling. An activated environment affects that Terminal window. A second Terminal can use curl without activating the Python environment because it sends an HTTP request and does not import the server’s packages.
Run a text model in a foreground process
Use the published MLX conversion of Qwen2.5 1.5B Instruct as the sample target. The conversion has its own repository name and files. If you choose a substitute, select an MLX text instruction model with its matching tokenizer and chat template. Weights for a different runtime can use the same model family name while being packaged in an incompatible form. MLX Community model conversion.
mlx_lm.server --model mlx-community/Qwen2.5-1.5B-Instruct-4bit \
--host 127.0.0.1 --port 8080
Leave this Terminal visible. Watch for the model download, startup message, or initialization error. Port 8080 is explicit, so all requests below refer to the same listener. If it is already occupied by another tool you use, pick an unused port for this test and change both the startup command and every client URL together. A successful response from an existing process on the old port would otherwise be easy to mistake for MLX LM.
The project source defines the host and port flags and documents the server’s intended development scope in its startup message. Keep the host at the loopback address for this exercise. This server can accept calls from other processes on the same Mac. Its bind address tells you where the listener accepts connections. Clients running on another computer would interpret the same numeric loopback as their own machine. MLX LM HTTP server implementation.
Check health and learn what the model listing represents
From another Terminal, request the health route and the model listing. These two small requests are easier to interpret before sending generated text. Give the server a short explicit connect timeout. The health route in current upstream source returns a status indicator, while the model listing can reflect what the server recognizes from its cache and an explicitly served local path. MLX LM route and cache implementation.
curl -sS --connect-timeout 2 http://127.0.0.1:8080/health
curl -sS --connect-timeout 2 http://127.0.0.1:8080/v1/models
Record the returned status and confirm that the server Terminal received the calls. A healthy response shows that the API loop is active. If the model listing includes several available IDs, keep using the one you started with for this example. An empty list can arise when the particular artifact does not satisfy the cache scan used by the installed version. The next check exercises the explicitly chosen model and is the observation you need for a caller.
If both requests get connection errors, return to the server Terminal. Look for download progress, load failures, or an address error. If the process has already exited, its final message often identifies the first substantive issue. If the status response clearly belongs to another service, confirm the startup port and any other listener using it. Correcting those details gives you a cleaner starting point than sending an unrelated minimal prompt.
Send a chat completion with a visible expected answer
The fictional notice below names two different locations. Ask the model to extract the location tied to one specific item. This checks that the selected model can read instructions inside chat messages and that the server returns visible chat content. The model value is the explicit repository used when starting the sample server.
curl -sS --max-time 90 -w '\nHTTP %{http_code}\n' \
http://127.0.0.1:8080/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model":"mlx-community/Qwen2.5-1.5B-Instruct-4bit",
"messages":[{"role":"user","content":"Open studio note: the spare sketch pads are in Orange Drawer. Brush trays are at the Wash Station. Reply with the sketch pad location only."}],
"max_tokens":64,
"stream":false
}'
Read the first choice’s message content. The expected location is Orange Drawer. This result has two parts. A successful chat HTTP response shows that the model executed for that route. The expected words show that the simple direction in the test had the intended effect. If the request returns a normal completion with extra wording, preserve that detail when deciding whether a later program needs its own output validator.
Run the same request again with Indigo Shelf replacing Orange Drawer. Leave the brush tray location unchanged. This second independent turn verifies that the answer follows changed input. Use a new command each time and compare the visible content outside your previous test’s transcript. If an ordinary text answer is blank, inspect the raw body and server output for a finish reason or load event. Confirm the template and request format before assuming a given checkpoint is unsuited to your project.
Keep the server configuration reproducible
Save a short note with the package version, model repository or local model directory, launch command, tested endpoint, and expected synthetic answer. Record a revision if you intentionally pin the model files for a project. Two copies can share a model repository name even when one was downloaded before the repository changed. The filename inventory and chosen revision help explain a difference between two environments with the same command line.
If a client asks for a base URL, a client written for the OpenAI-compatible paths generally starts with http://127.0.0.1:8080/v1 and appends the endpoint. If it asks for the entire chat endpoint, supply the longer path used in the command. Confirm the field’s behavior before migrating an existing integration. A path added twice can return a route error while the server remains healthy. Keep the client text-only for the initial check so that image, tool, and other request capabilities are investigated independently.
When the session ends, press Control-C in the server Terminal and repeat the short health query. With the process stopped and no other listener on the port, the connection should fail. This is a useful local negative check. A response after shutdown tells you something still accepts that address, which is a reason to confirm process identity before treating its output as the server you just configured.
If you want to rehearse starting over, leave the model files and the Python directory in place. Open a fresh Terminal, activate the same environment, and repeat the launch command followed by the second synthetic prompt. An import failure in the fresh window points to the environment. An accepted request returning the changed location gives you independent evidence that your setup instructions can bring the intended local model back without relying on the earlier shell state.
Investigate a model cache or configuration mismatch
A repository ID and a local directory are two ways to identify model files. When you pass a repository ID, the library can look for its cached snapshot and fetch missing files, subject to the environment’s download settings. When you provide a local directory, keep the configuration, tokenizer, and weights together in the layout the model expects. Moving only a weight shard to a new folder is easy to do accidentally when cleaning up a download. In this case, compare the selected directory to the converter’s file listing before trying another revision.
The same Terminal can also point to a different package environment after activation. To reproduce a reported issue, use the recorded version and interpreter first. Run the server help in that environment, start the same explicit command, and send the unchanged location request. If help shows the expected options but inference fails, focus on the model artifact or the body sent to the endpoint. A different error in the first Terminal after the launch usually gives you a better clue than a client error that just says generation failed.
If you need to distinguish a model error from a request format error, keep a known request body in a scratch directory. Send it as a file, then make one deliberate change such as replacing the destination text. Keep its message role and model field stable between those runs. This gives you a clean check of the application’s text path when a new dashboard or shell script later constructs a richer body with extra options.