Skip to main content
Generate chat completions using locally hosted Ollama models. This function supports multi-turn conversations, tool calling, and structured output with complete data privacy.

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 chat
  • message: The assistant’s response with role and content
  • created_at: Response timestamp
  • done: Whether generation is complete
  • total_duration: Total time taken
  • prompt_eval_count: Number of tokens in prompt
  • eval_count: Number of tokens generated