Ollama /api/generate vs /api/chat: Which Endpoint to Use and Why
Note: Some future links on this site may be affiliate links. We never claim hands-on testing; guides are researched from the public sources listed in each article.
How we wrote this: A plain-English summary of Ollama's official documentation (API reference), checked October 29, 2026.
Two ways to ask a model
Ollama's local API (http://localhost:11434) has two main text endpoints:
/api/generate |
/api/chat |
|
|---|---|---|
| Input | One prompt string |
A messages array, each with a role and content |
| Output | response text |
A message object with a role and content |
| Conversation | You manage any context yourself | You send the whole chat history each time |
| Tools | No | tools list for function calling |
| Extras | system, suffix (fill-in-the-middle), raw, images |
format, options, think |
Both accept model, stream (default true), format ("json" or a JSON schema), think and keep_alive. Both return timing fields such as total_duration and eval_count.
Minimal examples (from the docs)
curl http://localhost:11434/api/generate -d '{"model": "gemma4", "prompt": "Why is the sky blue?"}'
curl http://localhost:11434/api/chat -d '{"model": "gemma4", "messages": [{"role": "user", "content": "why is the sky blue?"}]}'
Replace gemma4 with a model you've pulled.
Which to use
/api/chatfor assistants, multi-turn conversations and tool calling./api/generatefor one-shot tasks such as summarizing a single text, or for code completion withsuffix.- Add
"stream": falsefor a single JSON reply instead of a stream; see streaming.
Related: local API basics, structured outputs, usage metrics and errors, OpenAI-compatible API.