Samples
Basic chat completion
Have a conversation with a local model:Multi-turn conversation
Continue a conversation with message history:Use with specific host
Connect to a custom Ollama server:Configure chat options
Customize the chat parameters:Structured output with JSON
Request JSON responses:Use tools (function calling)
Enable the model to call tools:Arguments
Returns
JSONB: The complete API response including:
model: Model used for the chatmessage: The assistant’s response withroleandcontentcreated_at: Response timestampdone: Whether generation is completetotal_duration: Total time takenprompt_eval_count: Number of tokens in prompteval_count: Number of tokens generated
Related functions
ollama_generate(): single-turn text completionollama_embed(): generate embeddingsollama_list_models(): see available models