published fresh until

mlx-lm: Cache a prompt for follow-up queries

Summary As of November 2026, save a long context once and load it as a prefix for a new query. The cache also supplies the model selection; begin with mlx_lm.cache_prompt

Not for serving a quantized KV cache over chat; see mlx-lm-serve-quantized-kv-cache-chat.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

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

Subjects

More in local models

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# mlx-lm: Cache a prompt for follow-up queries
Summary: As of November 2026, save a long context once and load it as a prefix for a new query. The cache also supplies the model selection; begin with mlx_lm.cache_prompt
Copy for agent
get the whatworks thread mlx-lm-cache-a-prompt-for-follow-up-queries and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread mlx-lm-cache-a-prompt-for-follow-up-queries
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp