Skip to main content
Ollama is a local wrapper that makes running and interacting with large language models (LLMs) easy and secure on your machine. You can use Ollama in three primary ways:
  • GUI (Windows and macOS) — a simple chat window similar to ChatGPT, Claude, or Gemini.
  • CLI — a terminal-based chat interface for quick interactions and scripting.
  • REST API — a programmatic HTTP interface for building applications that generate text or conduct multi-turn chats.
The image is about interfacing with Ollama, featuring a cartoon llama icon and descriptions of GUI, CLI, and REST API interfaces for chat and API access.
Quick overview (why choose each):
Ollama exposes a local REST endpoint at http://localhost:11434. Make sure the Ollama server is running before making API requests.
Below are the basic steps to call Ollama’s local REST API and handle both streaming and non-streaming responses.

1) Ensure the Ollama server is running

Start (or check) the server from your terminal:
If Ollama is already running (for example, started automatically on boot), you may see an address-in-use error:
To see which models are available locally:

2) Test the REST API with curl (streaming)

Ollama’s generate endpoint is http://localhost:11434/api/generate. By default the API streams partial tokens as newline-delimited JSON events. This is ideal for low-latency UIs that render tokens as they arrive. Example curl request (default behavior: streaming):
Sample streaming output (newline-delimited JSON events):
Each line is a partial event; a client can stream these and assemble the final output progressively.
Streaming is useful for low-latency UIs. If you prefer a single complete result (for easier parsing or logging), disable streaming in the request body by setting "stream": false.

3) Receive the full response in a single JSON object (non-streaming)

To get one complete response instead of token-by-token events, include "stream": false in the request body. Request body (example for curl or Postman):
Example curl with non-streaming:
Sample non-streamed JSON response:

4) Using Postman (or other HTTP clients)

You can replicate the same POST request from Postman, Insomnia, or any HTTP client:
  • Method: POST
  • URL: http://localhost:11434/api/generate
  • Body: raw JSON (example below)
Postman will format the returned JSON and make it easier to inspect the full response.

Why this matters

Using the Ollama REST API lets you integrate locally hosted LLMs into web servers, desktop apps, and backend services using any language that can make HTTP requests (Python, JavaScript, C#, Java, etc.). Running models locally improves privacy, reduces latency, and allows offline capabilities where appropriate. If you’re new to this, try the following next steps:
  • Experiment with both streaming and non-streaming modes to see which fits your UI/UX.
  • Build a simple backend client in your preferred language to handle token streaming.
  • Use ollama list to manage and choose models for different tasks (summarization, code generation, chat).
If anything here is unclear, or you want example client code (Python, Node.js) to consume the streaming API and assemble tokens into text, ask and I’ll provide step-by-step examples.

Watch Video