TutorialModels & inference
How to run a local LLM with Ollama and call it from your code
Run a local LLM with Ollama on macOS, Windows or Linux, call it over its REST and OpenAI-compatible APIs, size models to your RAM and manage disk space.
To run a local LLM with Ollama, install it with one command, then type ollama run gemma4 to download a model and chat with it. Ollama also starts an HTTP server on localhost:11434, so the same model answers curl, Python, JavaScript and any OpenAI client you point at it. The parts most guides skip are below: the API, model sizing, disk locations and the errors you are likely to see.
How do you install Ollama?
The Ollama README (opens in a new tab) lists a one-line installer for each desktop platform. Ollama is MIT licensed.
macOS and Linux
curl -fsSL https://ollama.com/install.sh | sh
On macOS you can also download Ollama.dmg and drag the app into Applications. The macOS docs require Sonoma (version 14) or newer. Apple M-series Macs get CPU and GPU support; Intel Macs run on the CPU only.
Linux users can install manually from a tarball and run Ollama as a systemd service. The Linux guide covers separate packages for AMD ROCm and ARM64.
Windows
irm https://ollama.com/install.ps1 | iex
The alternative is OllamaSetup.exe. The Windows docs list Windows 10 22H2 or newer, NVIDIA driver 551.61 or newer for NVIDIA cards, and a ROCm v7 or Vulkan-capable driver for AMD Radeon. The installer does not need Administrator rights and puts Ollama in your home directory. Plan for at least 4 GB for the binaries, before any models.
Once installed, Ollama runs in the background on macOS and Windows. Check that the CLI works:
ollama -v
Pull and run your first model
ollama run downloads the model if it is missing, loads it and opens an interactive prompt:
ollama run gemma4
To download without chatting, use ollama pull. A name without a tag resolves to latest, so gemma4 and gemma4:latest are the same model. Pick a specific size by adding its tag, such as qwen3:8b.
ollama pull qwen3:8b
ollama ls
ollama ps
ollama ls lists what is on disk. ollama ps lists what is loaded in memory, how much memory each model takes and whether it sits on the GPU or CPU. Inside the chat prompt, wrap multi-line input in triple quotes (""").
Ollama keeps a model in memory for 5 minutes after the last request. ollama stop gemma4 unloads it immediately.
How much memory do you need to run a local LLM with Ollama?
Ollama's documentation does not publish a RAM table per model. What it does give you is the download size of every tag in its model library, and a tool (ollama ps) that shows where a loaded model ended up.
The tags for one model family show how wide the range is. Sizes below are as listed in the Ollama library for qwen3 on 4 October 2026, and are illustrative of how tags differ:
| Tag | Download size | Listed context window |
|---|---|---|
qwen3:0.6b | 523 MB | 40K |
qwen3:1.7b | 1.4 GB | 40K |
qwen3:4b | 2.5 GB | 256K |
qwen3:8b (also latest) | 5.2 GB | 40K |
qwen3:14b | 9.3 GB | 40K |
qwen3:32b | 20 GB | 40K |
qwen3:235b | 142 GB | 256K |
The download size is only the starting point. The context window needs memory on top of it, and the Ollama docs say a larger context length increases the memory a model requires.
Sizing checklist
Copy this and work through it before you pull a large model:
- To do: Note your free VRAM (GPU) or free system RAM (CPU only, or Apple silicon).
- To do: Pick a tag whose download size is clearly below that number, leaving room for context.
- To do: Check the default context: Ollama uses 4k tokens below 24 GiB of VRAM, 32k from 24 to 48 GiB, and 256k at 48 GiB or more.
- To do: If you raise the context (for agents and coding tools the docs suggest at least 64,000 tokens), budget more memory.
- To do: If you raise
OLLAMA_NUM_PARALLEL, budget more again: required RAM scales with parallel requests times context length. - To do: Load the model and run
ollama ps.100% GPUmeans it fits. A split such as48%/52% CPU/GPUmeans part of it spilled into system RAM and will run slower. - To do: If it does not fit, drop to a smaller tag or try a quantized K/V cache (
OLLAMA_KV_CACHE_TYPE=q8_0roughly halves cache memory compared with the defaultf16).
For supported cards, the Ollama hardware support page (opens in a new tab) lists NVIDIA GPUs from compute capability 5.0 with driver 550 or newer, plus AMD cards through ROCm and Vulkan.
Calling the Ollama REST API with curl
Ollama's API listens on http://localhost:11434. The two endpoints you will use most are /api/generate for a single prompt and /api/chat for a message list. Both stream JSON objects by default; set "stream": false to get one response object.
curl http://localhost:11434/api/chat -d '{
"model": "gemma4",
"messages": [{ "role": "user", "content": "Why is the sky blue?" }],
"stream": false
}'
Model parameters go in an options object. This request sets the context window for one call:
curl http://localhost:11434/api/generate -d '{
"model": "qwen3:8b",
"prompt": "Summarize the GPL in two sentences.",
"stream": false,
"options": { "num_ctx": 8192 }
}'
Other endpoints in the Ollama API reference (opens in a new tab) cover model management: GET /api/tags (local models), GET /api/ps (loaded models), POST /api/pull, DELETE /api/delete and POST /api/embed for embeddings. The keep_alive field controls how long the model stays loaded after a request: 0 unloads it straight away and -1 keeps it loaded.
For native clients, Ollama publishes pip install ollama for Python and npm i ollama for JavaScript.
Using the Ollama OpenAI-compatible endpoint
Ollama also serves a subset of the OpenAI API under /v1, so code written for the OpenAI SDK can run against a local model by changing two values. The client still requires an API key string, which Ollama ignores.
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:11434/v1/",
api_key="ollama", # required by the client, ignored by Ollama
)
resp = client.chat.completions.create(
model="qwen3:8b",
messages=[{"role": "user", "content": "Say this is a test"}],
)
print(resp.choices[0].message.content)
According to the OpenAI compatibility docs (opens in a new tab), the supported routes are /v1/chat/completions, /v1/completions, /v1/models, /v1/embeddings and /v1/responses. Chat completions support streaming, JSON mode, vision and tools; logprobs are not supported. The Responses API arrived in v0.13.3 and is stateless only, so previous_response_id does not work.
Two details trip people up. You must ollama pull the model first, because the OpenAI routes do not download anything. The OpenAI API also has no context-size field, so for a bigger window you create a variant with a Modelfile:
FROM qwen3:8b
PARAMETER num_ctx 32768
ollama create qwen3-32k -f Modelfile
Then call qwen3-32k as the model name. If a tool insists on an OpenAI model name, ollama cp qwen3:8b gpt-3.5-turbo makes a copy under that name.
Where Ollama stores models and how to remove them
Models live in these directories by default, per the Ollama FAQ (opens in a new tab):
| OS | Default model directory |
|---|---|
| macOS | ~/.ollama/models |
| Linux (standard installer) | /usr/share/ollama/.ollama/models |
| Windows | C:\Users\%username%\.ollama\models |
Set the OLLAMA_MODELS environment variable to move them, for example to a larger drive. On Linux with the standard installer, the ollama user needs read and write access: sudo chown -R ollama:ollama <directory>. On Windows, quit the tray app after setting the variable and start Ollama again.
Remove a model with the CLI or the API:
ollama rm qwen3:8b
curl -X DELETE http://localhost:11434/api/delete -d '{"model": "qwen3:8b"}'
The Windows uninstaller does not delete models stored in a custom OLLAMA_MODELS location, so clear that folder yourself if you want the space back.
Common Ollama errors and what they mean
| Symptom | Likely meaning | What to do |
|---|---|---|
curl cannot connect to localhost:11434 | The Ollama server is not running | Start the app, or run ollama serve in a terminal |
HTTP 404 with an error field | The model name does not exist locally | Check ollama ls, then ollama pull the exact tag |
HTTP 503 | Too many queued requests; the server is overloaded | Lower concurrency or raise OLLAMA_MAX_QUEUE (default 512) |
ollama ps shows 100% CPU on a GPU machine | GPU discovery failed or the model is too large | Update drivers, check the server log, try a smaller tag |
Linux AMD log shows failed to finish discovery before timeout | The kernel driver is older than ROCm 7 | Upgrade to the ROCm v7 driver and reboot |
| Errors about temporary executables on Linux | /tmp is mounted noexec | Set OLLAMA_TMPDIR to a writable directory |
| Other apps on your network cannot reach Ollama | Ollama binds to 127.0.0.1 by default | Set OLLAMA_HOST=0.0.0.0:11434 and restart |
Errors that happen mid-stream arrive as a final JSON line with an error property, and the HTTP status stays 200 because the response had already started. Check for that field in streaming code.
Logs are the next step. On macOS run cat ~/.ollama/logs/server.log. On Linux with systemd, use journalctl -u ollama --no-pager --follow --pager-end. Windows keeps server.log in %LOCALAPPDATA%\Ollama. Setting OLLAMA_DEBUG=1 adds detail, as described in the Ollama troubleshooting guide (opens in a new tab).
Frequently asked questions
Does Ollama send my prompts to ollama.com?
Not for local models. The Ollama FAQ says it does not see prompts or data when you run models locally; cloud-hosted models are processed on Ollama's servers. To turn cloud features off entirely, set `OLLAMA_NO_CLOUD=1` or add `"disable_ollama_cloud": true` to `~/.ollama/server.json`, then restart.
How do I update Ollama?
The macOS and Windows apps download updates automatically and apply them when you choose "Restart to update" from the menu bar or taskbar icon. On Linux, re-run the install script. To pin a version, pass it to the script, for example `OLLAMA_VERSION=0.5.7`.
Can I run Ollama in Docker?
Yes. The official image is `ollama/ollama` on Docker Hub. GPU acceleration in a container works on Linux and on Windows with WSL2 using the NVIDIA Container Toolkit, but Docker Desktop on macOS has no GPU passthrough, so models run on the CPU there.
Can Ollama run more than one model at once?
Yes, if memory allows. By default it loads up to three models per GPU (or three for CPU inference), controlled by `OLLAMA_MAX_LOADED_MODELS`. When a new model does not fit, Ollama queues requests and unloads idle models to make room.
How do I stop Ollama starting at login?
On Windows, disable the `ollama` entry under Startup apps in Task Manager. On macOS, open Settings, search for Login Items and turn off Ollama under "Allow in the Background". Ollama keeps that choice across upgrades.
Sources
- 1.GitHub - ollama/ollama: Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models. · GitHubRepositoryPrimarygithub.com
- 2.ollama/docs/api.md at main · ollama/ollama · GitHubRepositoryPrimarygithub.com
- 3.github.com/ollama/ollama/blob/main/docs/macos.mdxRepositoryPrimary
- 4.github.com/ollama/ollama/blob/main/docs/windows.mdxRepositoryPrimary
- 5.github.com/ollama/ollama/blob/main/docs/linux.mdxRepositoryPrimary
- 6.github.com/ollama/ollama/blob/main/docs/cli.mdxRepositoryPrimary
- 7.github.com/ollama/ollama/blob/main/docs/context-length.mdxRepositoryPrimary
- 8.github.com/ollama/ollama/blob/main/docs/faq.mdxRepositoryPrimary
- 9.github.com/ollama/ollama/blob/main/docs/gpu.mdxRepositoryPrimary
- 10.github.com/ollama/ollama/blob/main/docs/api/openai-compatibility.mdxRepositoryPrimary
- 11.github.com/ollama/ollama/blob/main/docs/api/errors.mdxRepositoryPrimary
- 12.github.com/ollama/ollama/blob/main/docs/troubleshooting.mdxRepositoryPrimary
- 13.github.com/ollama/ollama/releasesRepositoryPrimary
Spotted an error? See our corrections policy.
Enjoyed this? Get the weekly brief.
New guides, Project & Tool of the Week and the AI developments that matter. One email, no spam.
Read next
- TutorialModels & inference
Fine tune LLM LoRA adapters: data, training and a first test on one GPU
Fine tune LLM LoRA adapters on one GPU: check that fine-tuning fits, prepare data, train with PEFT and TRL or Unsloth, and compare against the base model.
6 min read
- GuideModels & inference
Prompt caching with the OpenAI, Claude and Gemini APIs: what is cached and what breaks it
Compare prompt caching API rules for OpenAI, Claude and Gemini, order prompts so the cache hits, avoid silent misses and measure savings from usage fields.
8 min read
NewsModels & inferenceIntel details the GPU D270, an air-cooled inference card with up to 480 GB
Intel detailed the GPU D270 inference card: 480 GB LPDDR5X on partner cards, 160 GB on its own, 350 W PCIe. No price or ship date yet for buyers.
4 min read