When to use /api/generate
/api/generate takes a single prompt string instead of a messages array. It's the right shape when:
- You're doing fill-in-the-middle (FIM) code completion. The
suffixfield holds the code after the cursor; the model fills the gap. - You want a one-shot completion without conversation framing.
- You need to send raw mode (
raw: true) and bypass the model's chat template entirely — useful for fine-tuned models with custom prompt formats.
FIM is the killer use case
FIM is not a property of the endpoint — it is a property of the model's template. suffix only does anything if the model's Ollama template has a .Suffix branch that wraps your prefix and suffix in the model's own fill-in-the-middle tokens; otherwise the field is quietly ignored. The families that carry one today: qwen2.5-coder (every tag, base and instruct), deepseek-coder-v2, starcoder2, and Code Llama's code tags such as codellama:code. Check before you trust it: ollama show MODEL --template | grep -c Suffix, or look for insert in the model's Capabilities block. Given a prefix and a suffix, such a model completes the middle of a function. This is what powers local GitHub-Copilot-style autocomplete in Continue.dev, whose autocomplete role is explicitly FIM-based and lists Ollama as a provider with Qwen2.5-Coder 1.5B/7B as its open recommendations. Not every local-model tool uses this endpoint: Aider talks to Ollama through ollama_chat/, and Cursor's Tab model is its own hosted service, not your suffix field.
Other useful fields
images— array of base64 image strings (multimodal models).options— same as/api/chat.format— same as/api/chat.raw— boolean; iftrue, no template is applied to the prompt.