Conversational completions with message history, tool calling, thinking, vision.
POST http://localhost:11434/api/chat
POST https://ollama.com/api/chat # Cloud (requires OLLAMA_API_KEY)
modelmessagestoolsformat"json" or JSON schemastreamtruethinktrue/false or "high"/"medium"/"low"keep_alive"5m"optionslogprobstop_logprobsrole"system", "user", "assistant", or "tool"contentimagestool_calls{
"type": "function",
"function": {
"name": "get_temperature",
"description": "Get the current temperature for a city",
"parameters": {
"type": "object",
"required": ["city"],
"properties": {
"city": {"type": "string", "description": "City name"}
}
}
}
}
{
"function": {
"name": "get_temperature",
"arguments": {"city": "New York"}
}
}
modelcreated_atmessage{role, content, thinking, tool_calls, images}donedone_reasontotal_durationload_durationprompt_eval_countprompt_eval_durationeval_counteval_durationcurl http://localhost:11434/api/chat -d '{
"model": "qwen3:1.7b",
"messages": [
{"role": "user", "content": "Why is the sky blue?"}
],
"stream": false
}'
curl http://localhost:11434/api/chat -d '{
"model": "qwen3:1.7b",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Rayleigh scattering?"},
{"role": "assistant", "content": "Rayleigh scattering is the scattering of light by particles smaller than the wavelength of radiation."},
{"role": "user", "content": "How does that make the sky blue?"}
],
"stream": false
}'
curl http://localhost:11434/api/chat -d '{
"model": "qwen3:1.7b",
"messages": [{"role": "user", "content": "Tell me about Canada."}],
"stream": false,
"format": {
"type": "object",
"properties": {
"name": {"type": "string"},
"capital": {"type": "string"},
"languages": {"type": "array", "items": {"type": "string"}}
},
"required": ["name", "capital", "languages"]
}
}'
# Step 1: Model requests tool call
curl http://localhost:11434/api/chat -d '{
"model": "qwen3:1.7b",
"messages": [{"role": "user", "content": "What is the temperature in New York?"}],
"stream": false,
"tools": [{
"type": "function",
"function": {
"name": "get_temperature",
"description": "Get the current temperature for a city",
"parameters": {
"type": "object",
"required": ["city"],
"properties": {
"city": {"type": "string", "description": "City name"}
}
}
}
}]
}'
Step 2: Send tool result back
curl http://localhost:11434/api/chat -d '{
"model": "qwen3:1.7b",
"messages": [
{"role": "user", "content": "What is the temperature in New York?"},
{"role": "assistant", "tool_calls": [{"type": "function", "function": {"index": 0, "name": "get_temperature", "arguments": {"city": "New York"}}}]},
{"role": "tool", "tool_name": "get_temperature", "content": "22C"}
],
"stream": false
}'
curl http://localhost:11434/api/chat -d '{
"model": "deepseek-r1:1.5b",
"messages": [{"role": "user", "content": "How many r letters in strawberry?"}],
"think": true,
"stream": false
}'
Response includes message.thinking (reasoning trace) and message.content (final answer).
curl http://localhost:11434/api/chat -d '{
"model": "gemma3",
"messages": [{
"role": "user",
"content": "What is in this image?",
"images": ["iVBORw0KGgoAAAANSUhEUg...base64..."]
}],
"stream": false
}'
# Preload
curl http://localhost:11434/api/chat -d '{"model": "qwen3:1.7b"}'
Unload immediately
curl http://localhost:11434/api/chat -d '{"model": "qwen3:1.7b", "keep_alive": 0}'
Keep loaded forever
curl http://localhost:11434/api/chat -d '{"model": "qwen3:1.7b", "keep_alive": -1}'
Each chunk is newline-delimited JSON:
{"model":"qwen3:1.7b","created_at":"...","message":{"role":"assistant","content":"The"},"done":false}
{"model":"qwen3:1.7b","created_at":"...","message":{"role":"assistant","content":" sky"},"done":false}
{"model":"qwen3:1.7b","created_at":"...","message":{"role":"assistant","content":""},"done":true,"done_reason":"stop","total_duration":...,"eval_count":42}
The final chunk (done: true) includes performance metrics.
# Via OllamaAPI (api/ollama/ollama_url.py) — uses /api/chat when use_chat=True
result = await ollama_api.generate_text(
prompt="What is the weather?",
model="qwen3:1.7b",
use_chat=True,
messages=[
{"role": "system", "content": "You are mindX, an autonomous AI."},
{"role": "user", "content": "What is the weather?"}
]
)
Via OllamaChatManager (agents/core/ollama_chat_manager.py)
response = await chat_manager.chat(
message="Analyze the latest improvement cycle",
model="qwen3:1.7b",
system_prompt="You are mindX's autonomous improvement agent."
)