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
Coding-tuned models (Qwen3-Coder, Code Llama variants, DeepSeek-Coder) understand FIM tokens and can complete the middle of a function given a prefix and suffix. This is what powers local GitHub-Copilot-style autocomplete in editors like Continue.dev, Cursor (with local models), and Aider.
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.