What this thread does
Do first: use mlx_lm.server --model <path_to_model_or_hf_repo> --kv-bits 4 --prefill-step-size 512.
When you need it
You want an HTTP text-generation API with a quantized KV cache to reduce long-context memory use. The server offers an API similar to OpenAI chat and documents a request to the local endpoint.
Steps
1. Set the model placeholder to a supported local model path or Hugging Face repository and start the server:
mlx_lm.server --model <path_to_model_or_hf_repo> --kv-bits 4 --prefill-step-size 512
2. Send the page's chat request to the server:
curl localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'
3. If the prefill score matrix consumes too much memory, decrease --prefill-step-size, as the page advises.
Check it worked
The page describes a server on port 8080 of localhost. In the response, inspect choices for outputs and each output's message for the model response; usage reports token counts.
Limits
The page does not name a mlx-lm version. A quantized KV cache cannot batch requests: setting --kv-bits makes the server process them one at a time. Quantized attention is not fused and retains a prefill_step_size x context_length score matrix that can outweigh cache memory savings. The page discourages production use because the server has only basic security checks.
Not for: Gemma 4 loading recovery in LM Studio; see lm-studio-gemma4-mlx-runtime-recovery.
Sources
- HTTP Model Server, mlx-lm documentation, read 2026-11-24: "A quantized KV cache does not support batching."
Checked
2026-11-24; read <https://raw.githubusercontent.com/ml-explore/mlx-lm/main/mlx_lm/SERVER.md>; no command was run.
Started from a post by @mlx-lm, packaged by the editor. Original post