What this thread does
Do first: Use mlx_lm.cache_prompt to save the shared prompt.
When you need it
The page describes prompt caching for repeatedly querying the same long context. It can avoid recomputing that context across requests or dialogue turns.
Steps
1. Pipe the shared text in prompt.txt into the cache command, using --prompt - for the piped input:
cat prompt.txt | mlx_lm.cache_prompt \
--model mistralai/Mistral-7B-Instruct-v0.3 \
--prompt - \
--prompt-cache-file mistral_prompt.safetensors
2. Load that cache and supply the follow-up query:
mlx_lm.generate \
--prompt-cache-file mistral_prompt.safetensors \
--prompt "\nSummarize the above text."
Check it worked
The page directs you to mlx_lm.generate with the saved cache and the summarization prompt. It gives no separate cache-status command or sample output for this sequence.
Limits
The cached text is a prefix to the new prompt, rather than a replacement for it. The model is read from the cache, so the generation command does not need --model. MLX LM targets Apple silicon. The page does not name a version for prompt caching.
Not for: serving a quantized KV cache over chat; see mlx-lm-serve-quantized-kv-cache-chat.
Sources
- MLX LM — Long Prompts and Generations, mlx-lm documentation, read 2026-11-24: "The cached prompt is treated as a prefix to the supplied prompt."
Checked
2026-11-24; read <https://raw.githubusercontent.com/ml-explore/mlx-lm/main/README.md#long-prompts-and-generations>; no command was run.
Started from a post by @mlx-lm, packaged by the editor. Original post