Generate Completion
Generate a completion response for a given prompt. This is a streaming endpoint by default.
POST /api/generate
Request Parameters
model(string, required): Model tag to execute (e.g.gemma4).prompt(string, required): Input prompt text.suffix(string, optional): Text appended after completion.images(array of strings, optional): Base64-encoded image files.stream(boolean, defaulttrue): Return a stream of JSON chunks.raw(boolean, optional): Bypass template formatting logic.format(string/object, optional): Set to"json"or provide a JSON Schema structure.options(object, optional): Override Modelfile parameters (e.g.{"temperature": 0.5}).keep_alive(string/number, default"5m"): Cache duration in memory.
Examples
1. Streaming Request
curl http://localhost:11434/api/generate -d '{
"model": "gemma4",
"prompt": "Why is the sky blue?"
}'
Chunk Payload
{
"model": "gemma4",
"created_at": "2026-06-05T14:46:00Z",
"response": "The",
"done": false
}
Final Chunk Payload
{
"model": "gemma4",
"created_at": "2026-06-05T14:46:05Z",
"response": "",
"done": true,
"total_duration": 4820918000,
"load_duration": 12093000,
"prompt_eval_count": 12,
"prompt_eval_duration": 18239000,
"eval_count": 210,
"eval_duration": 4790290000
}
2. Non-Streaming Request
curl http://localhost:11434/api/generate -d '{
"model": "gemma4",
"prompt": "Why is the sky blue?",
"stream": false
}'
Response Payload
{
"model": "gemma4",
"created_at": "2026-06-05T14:46:05Z",
"response": "The sky is blue because of Rayleigh scattering.",
"done": true,
"total_duration": 4820918000,
"load_duration": 12093000,
"prompt_eval_count": 12,
"prompt_eval_duration": 18239000,
"eval_count": 210,
"eval_duration": 4790290000
}
3. Structured Output (JSON Schema)
curl -X POST http://localhost:11434/api/generate -H "Content-Type: application/json" -d '{
"model": "gemma4",
"prompt": "GoingMerry is 22 years old. Respond in JSON.",
"stream": false,
"format": {
"type": "object",
"properties": {
"age": { "type": "integer" }
},
"required": ["age"]
}
}'
Response Payload
{
"model": "gemma4",
"created_at": "2026-06-05T14:46:05Z",
"response": "{\n \"age\": 22\n}",
"done": true
}