The /api/chat endpoint is the chat-shaped version of the generate endpoint: it takes a list of messages with roles and returns the assistant message. With stream false the whole reply arrives as one JSON object.
What you need
- Ollama running with a chat model pulled, for example llama3.2
- curl installed
- A terminal on the same machine
Step 1: Build the chat request
Send a POST to http://localhost:11434/api/chat with a JSON body holding model, a messages array with a system message and a user message, and stream false. The system message sets the assistant role for the whole chat.
Step 2: Send it with curl
Run: curl http://localhost:11434/api/chat -d ‘{model: llama3.2, messages: [{role: user, content: Explain what a GGUF file is in one sentence.}], stream: false}’. The -d flag sends the JSON body.
Step 3: Read the assistant message
The reply JSON has a message object with role assistant and a content string holding the answer. The same endpoint with stream true sends the reply token by token instead.
Worked example: one chat call
The table below is a synthetic example. The endpoint and message format come from the Ollama API docs; the question and answer are illustrative.
| Part | Value | Note |
|---|---|---|
| Endpoint | POST /api/chat | Localhost port 11434 |
| Messages | system + user | Roles in order |
| Reply | message.content | Assistant answer |
Expected result (UNTESTED). curl returns HTTP 200 with a JSON object whose message.content holds a one-sentence answer. This check was not run live; the endpoint and message format come from the cited API docs.
Limits
- The messages array must use the documented roles: system, user, and assistant.
- The model name must match a pulled model exactly.
- The API has no authentication on localhost; keep port 11434 private.
- Long chats grow the message list; the context window still caps total tokens.
