Tutorial
Run a Local LLM with Ollama: Setup, Models and API
Run a local LLM with Ollama in about ten minutes. Install it, pull a model, chat in the terminal, then call the local API from Python.
Quick answer
You can run a large language model on your own computer with Ollama, and the whole setup takes about ten minutes. There is no API key and no per-token bill, and when you run a local model your prompts stay on your machine. (Models with a :cloud tag run on Ollama’s servers instead, so stick to local ones if privacy matters.) This tutorial walks through installing Ollama, downloading a model, chatting with it in the terminal, and calling it from Python.
Running a local LLM is also the cheapest way to learn how these systems behave. You can break things, retry a thousand times, and it costs you nothing but electricity.
What you need before you start
- A computer running Windows, macOS or Linux.
- A few gigabytes of free disk space. The
llama3.2model used here is roughly a 2 GB download, according to the Ollama model library. - A few gigabytes of free RAM. Smaller models run fine on a modern laptop without a dedicated GPU, just more slowly.
- Python 3.9 or newer, and the
requestspackage, if you want to follow the code section (pip install requests).
Model sizes and defaults change as new versions ship, so check the library page if something below looks different on your machine.
Step 1: Install Ollama
Download the installer for your operating system from ollama.com and run it. On Linux, the project provides an install script on the same page.
Ollama starts a small background service that listens on http://localhost:11434. You can confirm it is running by opening that address in a browser. It should respond with a short “Ollama is running” message.
Step 2: Pull and run your first model
Open a terminal and run:
ollama run llama3.2
The first time, Ollama downloads the model and then drops you into an interactive chat. Ask it anything. Type /bye to exit.
A few commands you will use constantly:
ollama list # models you have downloaded
ollama pull llama3.2 # download or update a model
ollama rm llama3.2 # delete a model to free disk space
Which model should you pick?
Start small. A 3 billion parameter model like llama3.2 answers quickly and fits on almost any machine. If the answers feel too shallow, try a larger model from the library and compare speed against quality yourself. Bigger models are usually smarter and usually slower, so the right choice depends on your hardware and your task.
Step 3: Call the local API from curl
Everything the terminal chat does is also available over HTTP. This request asks for a single, non-streamed answer:
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [{"role": "user", "content": "Explain embeddings in one sentence."}],
"stream": false
}'
The reply is a JSON object, and the text lives in message.content.
On Windows, this bash-style command will not work as written. In PowerShell, curl is an alias for a different command, and single quotes behave differently in cmd.exe. Skip to the Python version in the next step, which works the same on every system, or use PowerShell’s own command:
Invoke-RestMethod -Uri http://localhost:11434/api/chat -Method Post -ContentType "application/json" -Body '{"model":"llama3.2","messages":[{"role":"user","content":"Explain embeddings in one sentence."}],"stream":false}'
The full list of endpoints and options is in the official API documentation.
Step 4: Use your local LLM from Python
Install requests, then save this as chat.py:
import requests
response = requests.post(
"http://localhost:11434/api/chat",
json={
"model": "llama3.2",
"messages": [
{"role": "user", "content": "Explain embeddings in one sentence."}
],
"stream": False,
},
timeout=120,
)
response.raise_for_status()
print(response.json()["message"]["content"])
Run it with python chat.py. That is the entire integration: one POST request, one JSON field. Because the API is plain HTTP, it works from any language and any tool.
Why stream is set to false
By default Ollama streams the answer back token by token, as a series of JSON lines. That is great for chat interfaces and awkward for quick scripts. Setting "stream": false returns one complete response instead.
Common problems
- Connection refused. The Ollama service is not running. Start the Ollama app, or run
ollama servein a terminal. - Very slow answers. The model is probably too large for your graphics card or memory, so part of it runs on the CPU. Run
ollama psto see how the model is split, then try a smaller one. - First request is slow, later ones are fast. Ollama loads the model into memory on first use and keeps it loaded for five minutes by default.
FAQ
How do you run a local LLM with Ollama?
Download the installer for your operating system from ollama.com and run it, then open a terminal and run ollama run llama3.2. The first time, Ollama downloads the model and drops you into an interactive chat. Type /bye to exit.
Is running a local LLM with Ollama free and private?
There is no API key and no per-token bill, and when you run a local model your prompts stay on your machine. Models with a :cloud tag run on Ollama’s servers instead, so stick to local ones if privacy matters.
What hardware do you need to run a local LLM?
You need a computer running Windows, macOS or Linux, a few gigabytes of free disk space and a few gigabytes of free RAM. Smaller models run fine on a modern laptop without a dedicated GPU, just more slowly. Model sizes and defaults change as new versions ship, so check the Ollama library page if something looks different.
Why is your local LLM so slow in Ollama?
The model is probably too large for your graphics card or memory, so part of it runs on the CPU. Run ollama ps to see how the model is split, then try a smaller one. A slow first request is normal, because Ollama loads the model into memory on first use and keeps it loaded for five minutes by default.
How do you call a local Ollama model from Python?
Send a POST request to http://localhost:11434/api/chat with the model name and your messages, and set "stream": false to get one complete response. The text lives in message.content. You need Python 3.9 or newer and the requests package, and if you get a connection refused error, start the Ollama app or run ollama serve.
Where to go next
Now that a model is running on your own machine, you can build real things on top of it:
- Give it tools and let it make decisions in Build an AI Agent in Python With Tool Calling.
- Search your own notes by meaning with Semantic Search in Python With Embeddings.
- Measure how fast your hardware really is with Measure Ollama Tokens Per Second.


