Skip to main content

Generate Chat Completion

Generate the next message in a conversation thread with a specified model.

POST /api/chat

Request Parameters

  • model (string, required): Model tag.
  • messages (array of objects, required): Conversation message thread history. Each object requires:
    • role (string): system, user, assistant, or tool.
    • content (string): Message content.
    • images (array of strings, optional): Base64-encoded images.
    • tool_calls (array of objects, optional): Tool function calls returned by the model.
  • stream (boolean, default true): Return streamed response chunks.
  • format (string/object, optional): Set to "json" or provide a JSON Schema layout.
  • tools (array of objects, optional): Array of function tools the model can call.
  • options (object, optional): Override Modelfile parameters.
  • keep_alive (string/number, default "5m"): Cache duration in memory.

Examples

1. Simple Chat Request (Streaming)

curl http://localhost:11434/api/chat -d '{
"model": "gemma4",
"messages": [
{ "role": "user", "content": "Hello!" }
]
}'

Chunk Payload

{
"model": "gemma4",
"created_at": "2026-06-05T14:46:10Z",
"message": {
"role": "assistant",
"content": "Hello"
},
"done": false
}

2. Multi-turn Conversation (Non-Streaming)

curl http://localhost:11434/api/chat -d '{
"model": "gemma4",
"stream": false,
"messages": [
{ "role": "user", "content": "What is the capital of France?" },
{ "role": "assistant", "content": "The capital of France is Paris." },
{ "role": "user", "content": "What is its population?" }
]
}'

Response Payload

{
"model": "gemma4",
"created_at": "2026-06-05T14:46:12Z",
"message": {
"role": "assistant",
"content": "The population of Paris is approximately 2.1 million within the city limits."
},
"done": true,
"total_duration": 1928010000,
"load_duration": 4810000,
"prompt_eval_count": 28,
"prompt_eval_duration": 11928000,
"eval_count": 85,
"eval_duration": 1910800000
}