Managing Ollama models through the REST API with curl
Ollama exposes model management and chat through a small REST API, so IT teams can script what runs on a local server. This tutorial lists models, loads and unloads one, and tests the chat endpoint with curl.

What you will have at the end and what you need
At the end you can see which models a local Ollama server holds, place one in memory, release it again and send a test chat request. Every step uses plain curl calls against the API documented in the Ollama API reference. The reference notes that its docs are moving to docs.ollama.com/api, so check there for newer changes.
You need a running Ollama server that listens on localhost at port 11434, curl on the machine, and at least one model already present. The examples use llama3.2. Model names follow the pattern model:tag, and the tag defaults to latest when you leave it out. If you are weighing local models in general, our page on running AI locally gives the background.
Listing local models through the API
The endpoint GET /api/tags returns the models available on the server. The following call needs no body and returns a single JSON object.
curl http://localhost:11434/api/tagsThe response contains a models array. Each entry has a name, a model, a modified_at timestamp, a size, a digest and a details object. The details give the format, the family, the parameter size and the quantisation level. An administrator can use them to compare what is installed across several servers.
Loading a model into memory and unloading it again
The chat endpoint loads a model when the messages array is empty. The next request sends exactly that for llama3.2 and returns an object whose done_reason is load.
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": []
}'To release the model, send the same empty request with keep_alive set to 0. The response then reports done_reason as unload. Without this setting a model stays in memory for five minutes after a request, which is the documented default for keep_alive.
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [],
"keep_alive": 0
}'The generate endpoint behaves the same way with an empty prompt instead of an empty messages array. The documentation also describes endpoints to pull, copy and delete a model. The part of the reference supplied here is cut off before those sections, so this article does not show their request formats.
Calling the chat endpoint and checking the result
A real chat request fills the messages array with at least one user message. Setting stream to false returns one JSON object instead of a stream of partial objects, which is easier to read in a terminal.
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [
{"role": "user", "content": "Nenne drei Vorteile lokaler Modelle."}
],
"stream": false
}'The call works if the answer contains done set to true and a message with the role assistant and some content. The final object also carries statistics such as load_duration, eval_count and eval_duration. All durations are in nanoseconds, and dividing eval_count by eval_duration and multiplying by 10^9 gives tokens per second. A high load_duration on the first call shows that the model had to be loaded first.
Typical pitfalls from the documentation
Streaming is on by default for the chat and generate endpoints. Scripts that expect one JSON document then receive a series of objects, so set stream to false when you parse the result.
Memory handling follows keep_alive. A model that you loaded stays resident for five minutes unless you send another value, and an empty request with keep_alive set to 0 is the documented way to free it. For JSON output the documentation advises telling the model in the prompt to answer in JSON, otherwise it may produce large amounts of whitespace. Model names without a tag resolve to latest, so pin the tag when a specific version matters.
Where this fits in a company
The API listens on localhost in the examples. Anyone who exposes it to other machines has to decide who may reach it, because the reference shown here describes no authentication. Clarify that with your network and security team, and with the Betriebsrat (works council) where employee data could appear in prompts. Our pages on security and GDPR and AI cover the questions companies commonly check.
Someone in IT should own the model list, the tags in use and the unload routine, much like any other service. Scripts based on /api/tags and the load calls make that routine repeatable. souveraen.ai runs the same software hosted in Germany or on-premise, and its developer API is OpenAI-compatible. The model catalogue includes local models.
Sources
- Ollama API reference, Ollama


