The api/generate endpoint is the direct text-generation path for a single prompt. It is a good fit for scripts that do not need chat history but still need model options, streaming control, and a JSON response.
By default, Ollama streams newline-delimited JSON chunks. Set stream to false when the caller wants one complete JSON object that is easier to parse in shell scripts and tests.
Use a small prompt and a low num_predict value for smoke tests. Longer prompts and larger limits belong in application code after the endpoint, model name, and response shape are known to work.
Related: How to check the Ollama API server
Related: How to stream Ollama API responses
Related: How to run a chat request with the Ollama API
$ curl -s http://localhost:11434/api/version {"version":"0.31.1"}
$ curl -s http://localhost:11434/api/generate -d '{ "model": "gpt-oss:20b", "prompt": "Return the word OK and nothing else.", "think": "low", "stream": false, "options": {"num_predict": 24} }' {"model":"gpt-oss:20b","response":"OK","thinking":"Just output \"OK\".","done":true}
$ python3 - <<'PY'
import json
payload = {"response": "OK", "done": True}
print(payload["response"])
PY
OK
$ curl -s http://localhost:11434/api/generate -d '{ "model": "gpt-oss:20b", "prompt": "Return OK.", "stream": false, "options": {"temperature": 0, "num_predict": 24} }' {"response":"OK","done":true}
$ curl -s http://localhost:11434/api/chat -d '{"model":"gpt-oss:20b","messages":[{"role":"user","content":"Reply OK."}],"stream":false}' {"message":{"role":"assistant","content":"OK"},"done":true}