Skip to content

Ollama keeps unloading the model (slow first response)

Symptom

Every request after a few minutes of idle time has a long delay while the model reloads.

Likely causes

  • Default keep-alive is a few minutes

How to fix it

  1. Set OLLAMA_KEEP_ALIVE (e.g. 1h, or -1 to keep loaded forever).
  2. Or pass keep_alive in each API request.
bash
OLLAMA_KEEP_ALIVE=1h ollama serve
curl localhost:11434/api/generate -d '{"model":"llama3.1:8b","keep_alive":"1h"}'

Still stuck? Check the lessons or measure first with the benchmark lab.