Set an Ollama Output Token Limit With num_predict
Use options.num_predict to set a generation ceiling for one request. This is useful when a local tool needs a brief reply even when the model is inclined to keep writing.
Worked example
A local request with a small output budget
curl -sS http://localhost:11434/api/generate \
-H 'Content-Type: application/json' \
-d '{"model":"llama3.2:latest","prompt":"Describe a blue bicycle in several sentences.","stream":false,"options":{"num_predict":12}}'Steps
- Start Ollama locally and choose an installed model with ollama list. Replace the model in the example if needed.
- Send the example request with stream set to false so you get one JSON response. Record eval_count and done_reason when the server returns them.
- Change num_predict from 12 to 48 and run the same request again. Compare the token counts and check whether the first reply stopped early or hit the ceiling.
What to check
- An early stopping condition can produce fewer tokens than the limit. Check eval_count rather than counting characters in response.
- The context length has a separate setting. Increasing num_predict does not make a long input fit into the configured context window.