Urgent.News

What's breaking now, across thousands of outlets.

AI

Ollama API: A Practical Guide with Examples

Originally published on DevToolHub . Every Ollama install runs a local HTTP server on port 11434 , and that server is the real interface to the models. The ollama run command is a thin client on top of it. Once you know the two main endpoints, the streaming format, and the options object, you can wire a local model into any application. There is also an OpenAI-compatible route, so existing code…

The Ollama API is a simple RESTful interface that runs on port 11434 when an Ollama installation is active. This server acts as the primary method for interacting with the installed models. The core endpoints for the API include:

- `/api/generate`: Used for generating text based on a single prompt.

- `/api/chat`: Supports chat conversations with message history and tool invocation.

- `/api/embed`: Generates embeddings from input text.

- `/api/tags`: Lists the installed models.

- `/api/ps`: Shows the models currently loaded in memory.

- `/api/pull`: Downloads a model to the local system.

To verify the server is operational, you can send a request to `curl http://localhost:11434/api/version`. The API can be accessed using the `curl` command with appropriate JSON payloads for each endpoint. For generating text, `/api/generate` is suitable for a single prompt, while `/api/chat` is more versatile for multi-turn conversations or tool calls.

The default response format is streaming, returning newline-delimited JSON objects. However, you can set `stream` to `false` for a single response object. The API also supports options for customization, such as temperature, context window, and stopping sequences.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

More from Friday 4 September →