Ollama REST API: /api/generate vs /api/chat, with curl and Postman examples

Every Ollama app, command and library talks to the same REST API. Here are its two main endpoints side by side, tested in curl and Postman, plus what stream and think really do when you set them to true or false.

Two panels. POST /api/generate, one prompt in and one answer out, with a request holding model, prompt and stream false, and a response holding response, done and eval_count. POST /api/chat, a list of messages each with a role, with a request holding model, a messages list with a user message, and stream false, and a response holding a message with role assistant and content.
Fig. 1 — Two endpoints. /api/generate takes one prompt. /api/chat takes a conversation.

The terminal, the desktop app, coding tools, Python, Java: they all talk to Ollama the same way, by sending JSON over HTTP to http://localhost:11434. That is the Ollama REST API, and once you can use it directly, you can use Ollama from any language or tool.

This guide covers the two endpoints you will use most, /api/generate and /api/chat, and the difference between them. We test them with curl and then with Postman, first with only a user message and then with a system message too, and we read every field of the response. Finally we look at two settings that confuse everyone at first: stream and think.

It is part six of a series, but it stands on its own. All you need is Ollama installed and a model pulled, for example ollama pull qwen3.5:4b.

The base URL

Ollama runs as a small server on your own computer. Every endpoint starts with:

http://localhost:11434

localhost means “this computer” and 11434 is Ollama’s port. (Why it works this way is explained in What is Ollama?.) A quick check that the server is up is to list your models:

curl http://localhost:11434/api/tags

Endpoint 1: /api/generate (one prompt in, one answer out)

/api/generate is the simplest endpoint. You send one prompt, you get one answer. No conversation, no roles.

Windows Command Prompt (the inner quotes must be escaped as \"):

curl http://localhost:11434/api/generate -d "{\"model\":\"qwen3.5:4b\",\"prompt\":\"Explain RAG in simple terms\",\"stream\":false}"

macOS, Linux or Git Bash (wrap the JSON in single quotes, no escaping):

curl http://localhost:11434/api/generate -d '{"model":"qwen3.5:4b","prompt":"Explain RAG in simple terms","stream":false}'

The request body, formatted so it’s easier to read:

{
  "model": "qwen3.5:4b",
  "prompt": "Explain RAG in simple terms",
  "stream": false
}
  • model: which model to use.
  • prompt: your text.
  • stream: false means “send me one complete JSON when you’re done”. More on this below.

The response (example output; yours will differ):

{
  "model": "qwen3.5:4b",
  "response": "RAG means the model first looks up relevant facts, then answers with them...",
  "done": true,
  "prompt_eval_count": 15,
  "eval_count": 118
}

The answer is in the response field. eval_count is how many tokens the model wrote, which is how speed and, on cloud APIs, cost are measured.

Endpoint 2: /api/chat (a conversation of messages)

/api/chat takes a list of messages instead of one prompt. Each message has a role (who wrote it) and content (what it says).

Windows Command Prompt:

curl http://localhost:11434/api/chat -d "{\"model\":\"qwen3.5:4b\",\"messages\":[{\"role\":\"user\",\"content\":\"Explain MCP with an example\"}],\"stream\":false}"

macOS, Linux or Git Bash:

curl http://localhost:11434/api/chat -d '{"model":"qwen3.5:4b","messages":[{"role":"user","content":"Explain MCP with an example"}],"stream":false}'

Formatted:

{
  "model": "qwen3.5:4b",
  "messages": [
    { "role": "user", "content": "Explain MCP with an example" }
  ],
  "stream": false
}

And the answer comes back as a message, with the role assistant:

{
  "model": "qwen3.5:4b",
  "message": {
    "role": "assistant",
    "content": "MCP lets an AI app plug into tools like a calendar..."
  },
  "done": true,
  "eval_count": 142
}

/api/generate vs /api/chat: the difference

/api/generate /api/chat
Input One prompt string A list of messages, each with a role
Instructions Optional system field A message with role system
Conversation history Not built in Send earlier user and assistant messages
Answer is in response message.content (role assistant)
Best for One-off tasks: summarise, translate, classify Chatbots, assistants, agents, tool calling

The short version: use /api/chat for almost everything. It does everything /api/generate does, plus conversations, plus tools. /api/generate is handy for quick single-shot jobs and for learning.

Notice that neither endpoint remembers anything between requests. If you want a conversation, you send the history in messages every time. That idea, being stateless, is the heart of the Python and Java guides.

Testing the API in Postman

curl is fine for one line, but the JSON comes back as one long unformatted line, which is hard to read. Postman is a free app for testing APIs. It formats the request and the response neatly, colours the JSON, shows status and timing, and lets you save requests to reuse. That is why we use it here: to see the messages clearly.

To set up a request:

  1. Click New → HTTP request.
  2. Set the method to POST and the URL to http://localhost:11434/api/chat.
  3. Open the Body tab, choose raw, and pick JSON from the dropdown.
  4. Paste a request body (below) and click Send.

Test 1: only a user message

Our first body has a single user message. We also set think to false (explained below) and stream to false so we get one tidy JSON back:

{
  "model": "qwen3.5:4b",
  "messages": [
    {
      "role": "user",
      "content": "Explain AI in two sentences."
    }
  ],
  "think": false,
  "stream": false
}
Postman with a POST request to http://localhost:11434/api/chat. The raw JSON body holds model qwen3.5:4b, one user message saying Explain AI in two sentences, think false and stream false. The response is 200 OK in 52.37 seconds, 800 bytes, and shows model, created_at, a message with role assistant and content explaining AI as a branch of computer science, then done true, done_reason stop, total_duration 52318088200, load_duration 28710500, prompt_eval_count 19, prompt_eval_cached_count 0, prompt_eval_duration 567510000, eval_count 60 and eval_duration 6122402000.
Only a user message. A plain, correct, textbook-style answer, plus timing details.

Let’s read the response, field by field, using the real numbers from this run:

Field Value here What it means
model qwen3.5:4b Which model answered
created_at 2026-11-15T06:19:52.6448518Z When the answer finished (UTC)
message.role assistant Written by the model
message.content “AI is a branch of computer science…” The answer
done true The answer is complete
done_reason stop It stopped naturally (it could also stop because it hit a length limit)
total_duration 52318088200 Total time for the request, in nanoseconds: about 52.3 s
load_duration 28710500 Time to load the model: about 0.03 s (it was already in memory)
prompt_eval_count 19 Tokens the model read (your input, including the chat template)
prompt_eval_duration 567510000 Time to read them: about 0.57 s
eval_count 60 Tokens the model wrote
eval_duration 6122402000 Time to write them: about 6.1 s

All the durations are in nanoseconds, so divide by 1,000,000,000 to get seconds. A useful number to work out is speed: 60 tokens in 6.12 seconds is about 9.8 tokens per second on this laptop.

You may notice that total_duration (52 s) is far bigger than load + reading + writing added together (about 6.7 s). The total counts everything from the moment the request arrived, so when it is much bigger than the parts, the request spent time outside those steps, such as waiting its turn. The writing itself took about 6 seconds, and that is the number to compare between models.

Test 2: a system message plus a user message

Now the same question, but with a system message first. The system message sets the rules: who the model is and how it must reply.

{
  "model": "qwen3.5:4b",
  "messages": [
    {
      "role": "system",
      "content": "You are AI Explainer who can explain any complex topic with a metaphore. Reply with STRICT JSON"
    },
    {
      "role": "user",
      "content": "Explain AI in two sentences."
    }
  ],
  "think": false,
  "stream": false
}
Postman with the same POST request, now with a system message first saying You are AI Explainer who can explain any complex topic with a metaphore. Reply with STRICT JSON, then the user message Explain AI in two sentences. The response is 200 OK in 7.20 seconds, 727 bytes. The message content is a JSON string with an explanation, Imagine an AI as a student who has read every book ever written; instead of memorizing, it instantly recognizes patterns to solve puzzles you haven't even asked about yet, and a metaphor, A library's omniscient reader that never stops studying. Below it: done true, done_reason stop, total_duration 7199929700, load_duration 10906100, prompt_eval_count 44, prompt_eval_cached_count 0, prompt_eval_duration 676312000, eval_count 65, eval_duration 6485217000.
Add a system message, and the same question comes back as JSON, built around a metaphor.

Three things changed:

  1. The style changed completely. The answer is now built around a metaphor: “Imagine an AI as a student who has read every book ever written…”, with a second line, “A library’s omniscient reader that never stops studying.” The user didn’t ask for a metaphor. The system message did.
  2. The format changed. content is now JSON with explanation and metaphor keys. Notice it is JSON inside a string (you can see the escaped \" and \n), so your code reads message.content and then parses it as JSON a second time.
  3. The input got bigger. prompt_eval_count went from 19 to 44 tokens. The system message is sent, and read, on every request. Keep system messages focused: on a cloud API you would pay for those tokens every time.

The roles themselves (system, user and assistant) are explained in depth in System, user and assistant roles explained.

stream: true or false?

Two panels. Stream: with true, the default, the answer arrives as many small JSON lines, each with a piece of content and done false, and a last line with done true and the stats. With false, one complete JSON arrives after the whole answer is ready. Think: with true, the message has a thinking field with the model's reasoning and a content field with the answer, which costs more tokens and time but is often better on hard questions. With false, there is no thinking field and the model goes straight to the answer.
stream decides how the answer arrives. think decides whether the model reasons before answering.

"stream": true is the default, if you leave the field out. Ollama sends the answer as it is written: many small JSON objects, one per line (a format called NDJSON). Each piece carries a little bit of the text:

{"model":"qwen3.5:4b","message":{"role":"assistant","content":"RAG"},"done":false}
{"model":"qwen3.5:4b","message":{"role":"assistant","content":" means"},"done":false}
{"model":"qwen3.5:4b","message":{"role":"assistant","content":" look"},"done":false}
{"model":"qwen3.5:4b","message":{"role":"assistant","content":""},"done":true,"eval_count":118}

Your app joins the pieces together. The last line has "done": true and all the timing and token stats. This is how chat apps show words appearing one by one: the user sees the answer start in under a second instead of staring at a spinner.

"stream": false makes Ollama wait until the whole answer is ready and send one complete JSON, like the Postman responses above. Simpler to read and to code, so we use it while learning. The trade-off is that nothing appears until the very end.

stream: true (default) stream: false
What arrives Many small JSON lines One JSON object
First words appear Almost immediately Only when the answer is finished
Your code Read line by line, join the pieces Read one JSON, take message.content
Good for Chat UIs, long answers Learning, scripts, Postman, parsing JSON

The Python guide includes a working streaming example.

think: true or false?

Some models, including Qwen 3.5, are thinking models: they can reason step by step before giving the final answer. The think field controls that:

  • "think": true asks the model to reason first. The reasoning comes back in a separate field, message.thinking (or thinking on /api/generate), and the final answer stays in message.content. This often helps with maths, logic and tricky questions, but it writes many more tokens, so it is slower.
  • "think": false skips the reasoning and goes straight to the answer. Faster, and fine for simple questions.
  • Leave it out, and the model uses its own default. Qwen 3.5 thinks by default, which is why our examples set "think": false. On a laptop, thinking can be slow: in the Ollama desktop app, asking qwen3.5:4b to “Explain Ramayana in 10 lines” showed Thought for 331.9 seconds before the ten lines appeared (see the desktop app guide).

With thinking on, a response looks like this (example):

"message": {
  "role": "assistant",
  "thinking": "The user wants AI in two sentences. I should define it, then say how it works...",
  "content": "AI is a branch of computer science..."
}

Show thinking to users only if it helps them; most apps hide it and show just content.

Other fields worth knowing

Field Example What it does
format "json" or a JSON schema Forces the reply to be valid JSON, or to match a schema
options { "temperature": 0.3, "num_ctx": 8192 } Generation settings: lower temperature is more focused; num_ctx sets the context window size
keep_alive "10m", 0, -1 How long the model stays in memory after this request (default about 5 minutes; 0 unloads now; -1 keeps it loaded)
tools a list of functions Lets the model ask your code to call functions, the basis of AI agents

Two more endpoints from this series

# Which models are on my disk?
curl http://localhost:11434/api/tags
# Turn text into an embedding (a vector of numbers), after: ollama pull nomic-embed-text
curl http://localhost:11434/api/embed -d '{"model":"nomic-embed-text","input":"Spring Boot is a Java framework"}'

Embeddings are what make semantic search and RAG work. See tokens and embeddings for the idea behind them.

When something goes wrong

  • “Connection refused”: the Ollama server isn’t running. Open the Ollama app, or run ollama serve.
  • A “model not found” error (HTTP 404): you haven’t downloaded that model, or the name or tag is spelled differently. Run ollama pull qwen3.5:4b and check ollama list.
  • Very slow first answer: the model is being loaded into memory. Later requests within about 5 minutes are faster.
  • Invalid JSON from curl on Windows: a quote isn’t escaped. Use -d @body.json or Postman instead.

Key takeaways

  • Every client talks to Ollama with JSON over HTTP at http://localhost:11434.
  • /api/generate: one prompt in, response out. /api/chat: a list of role-tagged messages in, a message out. Prefer /api/chat.
  • A system message changes style and format for every answer, and its tokens are read on every request.
  • Durations are in nanoseconds. eval_count / eval_duration gives you tokens per second.
  • stream: true (default) sends many small pieces; false sends one JSON. think: true adds a reasoning step in thinking; false skips it.

The full series: Run LLMs locally with Ollama

Each part stands on its own, so jump to whichever you need:

  1. How to run an LLM on your own computer
  2. What is Ollama? The video player for AI models, and localhost:11434 explained
  3. Ollama CLI commands: the complete cheat sheet
  4. The Ollama desktop app: chat, pick models, and launch Claude Code or Copilot
  5. System, user and assistant roles explained
  6. Ollama REST API: /api/generate vs /api/chat (you are here)
  7. Call a local LLM from Python: a stateless request, then a chatbot with memory
  8. Call a local LLM from Java: HttpClient, a stateless request, then a chatbot with memory

See it in action

Prefer watching? This video walks through the same ideas with live, hands-on demos.

Video thumbnail: Ollama REST API: /api/generate vs /api/chat, with curl and Postman examplesWatch on YouTube ↗

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.