Ollama REST API Generate

The Ollama REST API lets any program talk to your local models over HTTP. The simplest endpoint is POST /api/generate, which takes a single prompt and returns a completion.

A Basic Generate Request

By default responses are streamed as many JSON lines. Set "stream": false to get one JSON object, which is easier while learning.

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "Name three primary colours.",
  "stream": false
}'
{
  "model": "llama3.2",
  "created_at": "2026-10-31T09:12:01.123Z",
  "response": "Red, blue and yellow.",
  "done": true,
  "done_reason": "stop",
  "total_duration": 812345678,
  "prompt_eval_count": 31,
  "eval_count": 8
}
(Sample response.)

Response Fields

  • response - the generated text.
  • done - true on the final message.
  • eval_count - tokens generated; prompt_eval_count - tokens in the prompt.
  • total_duration / eval_duration - timings in nanoseconds.

Streaming Responses

With streaming on, each line is a JSON object carrying a small piece of text. Your app prints pieces as they arrive, which feels much faster to users.

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "Count to three."
}'
{"model":"llama3.2","response":"One","done":false}
{"model":"llama3.2","response":",","done":false}
{"model":"llama3.2","response":" two","done":false}
...
{"model":"llama3.2","response":"","done":true,"eval_count":7}

Passing Options and a System Prompt

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "system": "You answer like a pirate.",
  "prompt": "What is the weather like at sea?",
  "stream": false,
  "options": { "temperature": 0.9, "num_ctx": 4096, "seed": 42 },
  "keep_alive": "10m"
}'
{"response":"Arr, the sea be choppy today, matey, with winds howlin' from the west!", "done":true, ...}
(Sample response.)

options overrides Modelfile parameters for this request only. keep_alive controls how long the model stays in memory afterwards; "0" unloads it immediately and -1 keeps it loaded indefinitely.

Frequently asked questions

What is the difference between /api/generate and /api/chat?

/api/generate takes a single prompt string. /api/chat takes a list of messages with roles, which is better for multi-turn conversations and tool calling.

How do I disable streaming in Ollama?

Add "stream": false to the request body. You will receive one complete JSON object.

Can I call the Ollama API from another computer?

Yes, set OLLAMA_HOST=0.0.0.0 so the server listens on all interfaces, and protect it with a firewall or reverse proxy because it has no authentication.