Ollama keeps a model in memory for 5 minutes after the last request, then unloads it. The next request must load the weights again, which is why the first reply after a pause is slow. You can change the time with the OLLAMA_KEEP_ALIVE variable or a keep_alive field on each API request.
What the default does
The Ollama FAQ states that by default models are kept in memory for 5 minutes before being unloaded. The idea is sensible. Idle models should not hold GPU or system memory forever, especially on a laptop that does other work.
The cost shows up in interactive tools. If a code assistant calls your local model once every ten minutes, each call pays the full load time. For a large model that can be many seconds of reading weights from disk.
The settings
According to the FAQ, keep_alive accepts a duration string such as "10m", a number of seconds, a negative number to keep the model loaded indefinitely, or 0 to unload right after the response.
The API parameter overrides the OLLAMA_KEEP_ALIVE environment variable, so you have two levels:
- Global: set OLLAMA_KEEP_ALIVE for the server.
- Per call: pass keep_alive in the request body.
curl http://localhost:11434/api/generate -d '{"model": "your-model", "keep_alive": "30m"}'
Replace the model name with one you have pulled, and check the API docs for your version for how a request without a prompt behaves.
Choosing a value
Match the setting to how you work:
- Interactive coding tool you use all day: a long value or a negative number, if you can spare the memory.
- Occasional scripts: the default is fine.
- Shared machine with several models: keep values short so models do not crowd each other out. The FAQ also describes a limit on how many models load at once, set by OLLAMA_MAX_LOADED_MODELS, which by default is 3 times the number of GPUs, or 3 for CPU inference.
- Battery or thermal limits: unload promptly with 0 or a short duration.
A loaded model that never unloads holds its memory, including the KV cache. If you keep a large model loaded all the time, you cannot use that memory for anything else. See how much memory a model needs.
What the setting does not do
keep_alive does not make generation faster once the model is loaded. It only removes the repeat load delay. If replies are slow even when the model is warm, look at context size, quantization and whether the model fits fully in GPU memory. See choosing a quant level.
A note on measuring
When you test speed, send one warm up request before timing. Otherwise your numbers mix load time with generation time and you will draw wrong conclusions about the model or the quantization.
Quick check
Does keep_alive change the model's answers?
No. It only controls how long the weights stay in memory after a request. Answers come from the same model either way.
What does a negative keep_alive do?
Per the Ollama FAQ, a negative number keeps the model loaded. Use it only when you can afford the memory.
Sources
Last reviewed: 19 October 2026.