Skip to content

VersusGPU

Ollama /api/generate vs /api/chat: Which Endpoint Should You Use?

Ollama's /api/generate takes a single prompt and suits one-off tasks, with extras such as suffix for fill-in-the-middle and raw mode; /api/chat takes a list of role-based messages and supports tool calling, so it's the one for chatbots and agents.

By , Senior Hardware Editor

3 min read

Ollama /api/generate vs /api/chat: Which Endpoint Should You Use?

Once you've got Ollama running on your PC, sooner or later you'll want to call a model from a script or another app rather than typing into a chat window. Ollama's own API, which listens on http://localhost:11434 by default, gives you two main endpoints for text: /api/generate and /api/chat. They overlap a lot, but they're built for different jobs. This comparison is based on Ollama's API reference. It hasn't been timed or tested by us on specific hardware, and field names can change between Ollama releases, so check the docs for your version.

The short version

/api/generate

/api/chat

Input

A single prompt string (plus an optional system prompt)

A messages array, each message with a role and content

Best for

One-off tasks: summarise this, classify that, complete this code

Conversations and assistants where earlier turns matter

Roles

Not applicable

system, user, assistant and tool

Tool (function) calling

Not in the request schema

Yes, via a tools list; replies can contain tool_calls

Fill-in-the-middle

Yes, via suffix

No

Raw mode (no prompt template)

Yes, via raw

No

Images

images array of Base64 strings

images on individual messages

Reply field

response

message (with role and content)

Both endpoints share many options: format for JSON or a JSON schema, stream, think, keep_alive, an options object for settings such as temperature, seed, num_ctx and num_predict, and log probabilities via logprobs.

/api/generate: one prompt in, one answer out

/api/generate is the simplest way to get text from a model. Ollama's reference shows a request as little as:

curl http://localhost:11434/api/generate -d '{
  "model": "gemma4",
  "prompt": "Why is the sky blue?",
  "stream": false
}'

The answer comes back in the response field. Because each call is self-contained, it suits batch jobs where every prompt stands alone, such as tagging a folder of documents or rewriting product descriptions.

It also has two options /api/chat lacks. suffix is for fill-in-the-middle models: Ollama describes it as text that appears after the user prompt and before the model response, which is how code editors ask a model to complete the gap between two pieces of code. And raw returns the model's response without any prompt templating, for when you want to format the prompt yourself.

/api/chat: conversations, roles and tools

/api/chat takes a messages array. Each message has a role (system, user, assistant or tool) and content. To hold a conversation, your app sends the earlier messages back with each new request, so the model sees the whole history. The reply arrives as a message object with the role assistant.

This is the endpoint to use for chatbots, assistants and anything agent-like. Ollama's chat reference includes a tools field, described as an optional list of function tools the model may call, and responses can include tool_calls that your code then runs, returning the result as a tool message. Images for vision models go on individual messages; see our guide to vision models in Ollama.

Settings that work the same on both

  • Streaming: both stream partial responses by default; set "stream": false to get a single reply.

  • Structured output: format accepts json or a JSON schema. Our structured outputs guide covers this.

  • Thinking: think controls reasoning output on models that support it; see turning off thinking in Ollama.

  • Keeping models in memory: keep_alive takes a duration such as 5m, or 0 to unload straight away. See keeping Ollama models loaded.

  • Speed stats: both return timing fields including eval_count and eval_duration (in nanoseconds), so you can work out generation speed yourself.

What about the OpenAI-compatible API?

If you're plugging Ollama into a tool that already expects OpenAI's API format, you may not need either native endpoint. Our guide to using Ollama's OpenAI-compatible API explains that route, and the Ollama Python library guide covers calling these endpoints from Python without writing raw HTTP requests.

Our verdict

Use /api/chat for anything conversational, anything with a system/user/assistant structure, and anything that needs tool calling. Use /api/generate for single, standalone prompts, and when you need its extras: suffix for fill-in-the-middle code completion or raw to skip the prompt template.

The bottom line

Use /api/chat for anything conversational, anything with a system/user/assistant structure, and anything that needs tool calling. Use /api/generate for single, standalone prompts, and when you need its extras: `suffix` for fill-in-the-middle code completion or `raw` to skip the prompt template.

Sources

  1. 01Ollama, API reference: Generate a response
  2. 02Ollama, API reference: Generate a chat message

About the author

Callum Reid

Senior Hardware Editor

Callum leads GPU, CPU and platform architecture coverage at Forge PC. Before joining the editorial desk, he spent nine years specifying, assembling and stress-testing custom gaming and workstation systems in the UK, with a focus on PCIe bandwidth, VRM thermal design, DDR5 memory tuning and 1440p/4K frame-time consistency.

More from Callum Reid

Read next

How to Use Tool Calling in Ollama

How-To

How to Use Tool Calling in Ollama

How to use tool calling (function calling) in Ollama: describe functions in a tools list on /api/chat, read the model's tool_calls, run them and send results back as tool messages, plus parallel calls, agent loops and streaming, based on Ollama's documentation.

Marcus Thorne3 min

Temperature vs Top-p vs Top-k in Ollama: Which Setting to Change?

Versus

Temperature vs Top-p vs Top-k in Ollama: Which Setting to Change?

What Ollama's sampling settings do: temperature controls creativity, top_k and top_p limit which tokens are considered, min_p is a relative alternative to top_p, and seed makes output repeatable, with Ollama's documented defaults and how to set them.

Callum Reid3 min

How to Fix Slow Token Generation in llama.cpp

How-To

How to Fix Slow Token Generation in llama.cpp

How to fix slow llama.cpp text generation by confirming GPU offload with -ngl and setting -t to your physical core count or lower, with the llama.cpp developers' own example showing the effect of each setting.

Marcus Thorne2 min