Ollama Chat API

The Ollama chat API at POST /api/chat is the endpoint most apps use. Instead of one prompt, you send a list of messages, each with a role and content. The model replies with one new assistant message.

Message Roles

  • system - instructions that shape behaviour for the whole conversation.
  • user - what the person typed.
  • assistant - earlier replies from the model.
  • tool - results from a tool the model asked you to call.

A Chat Request

curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2",
  "stream": false,
  "messages": [
    { "role": "system", "content": "You are a concise cooking assistant." },
    { "role": "user", "content": "How long should I boil an egg for a soft yolk?" }
  ]
}'
{
  "model": "llama3.2",
  "message": {
    "role": "assistant",
    "content": "About 6 minutes in boiling water, then cool it in cold water for a minute."
  },
  "done": true
}
(Sample response.)

Keeping Conversation Context

The API is stateless: the server does not remember previous requests. To continue a conversation, send the whole history every time, including the model's last reply.

"messages": [
  { "role": "system", "content": "You are a concise cooking assistant." },
  { "role": "user", "content": "How long should I boil an egg for a soft yolk?" },
  { "role": "assistant", "content": "About 6 minutes..." },
  { "role": "user", "content": "And for a hard yolk?" }
]
{"message":{"role":"assistant","content":"About 10 to 12 minutes."}, "done":true}
(Sample response.)

Because the model sees the earlier turns, it understands that "And for a hard yolk?" is about eggs. Long histories eventually exceed num_ctx, so real apps trim or summarise old messages.

Sending Images

Vision-capable models (for example gemma3 or llava) accept base64-encoded images in an images array on a user message:

{ "role": "user", "content": "What is in this picture?", "images": ["iVBORw0KGgoAAAANSUhEUg..."] }
{"message":{"role":"assistant","content":"A ginger cat sleeping on a laptop keyboard."}}
(Sample response.)

Frequently asked questions

Does Ollama remember chat history?

No. The API is stateless, so your application must store the messages and send them with every request.

How do I set a system prompt in the Ollama API?

Add a message with role "system" at the start of the messages array, or define SYSTEM in a Modelfile.

Which Ollama models support images?

Vision models such as gemma3, llava, llama3.2-vision and qwen2.5vl at the time of writing. Check the model page for a vision tag.