Local Ollama API on Linux
In this setup Ollama runs as a local HTTP API on http://localhost:11434. On Linux it integrates with systemd for automatic startup. Local access via API requires no authentication and model runs on GPU.
Quick reference
Section titled “Quick reference”# Installcurl -fsSL https://ollama.com/install.sh | sh
# Servicesystemctl status ollamasudo systemctl start ollamasudo systemctl enable ollama
# Modelsollama pull qwen2.5:7b-instruct-q4_K_Mollama pull llama3.1:8b-instruct-q4_K_Mollama list
# API checkscurl http://localhost:11434/api/tagscurl http://localhost:11434/api/pscurl http://localhost:11434/api/generate -d '{ "model": "qwen2.5:7b-instruct-q4_K_M", "prompt": "Say hello world", "stream": false}'Install
Section titled “Install”curl -fsSL https://ollama.com/install.sh | shService management
Section titled “Service management”On Linux, Ollama runs as a systemd service. The API starts automatically on boot without needing to run ollama serve manually.
systemctl status ollama # check current statussudo systemctl start ollama # start nowsudo systemctl enable ollama # enable on bootjournalctl -u ollama --no-pager -n 50 # view logsIf ollama serve says the port is already in use, the systemd service is already running. Use the running service rather than starting a second server manually.
Pull models
Section titled “Pull models”ollama pull qwen2.5:7b-instruct-q4_K_Mollama pull llama3.1:8b-instruct-q4_K_Mollama listRun a model interactively from the terminal:
ollama run qwen2.5:7b-instruct-q4_K_Mollama run llama3.1:8b-instruct-q4_K_MCheck the API from curl
Section titled “Check the API from curl”Once Ollama is running the API is available immediately. Key endpoints: /api/generate for generation, /api/tags for installed models, /api/ps for currently running models.
curl http://localhost:11434/api/tags # installed modelscurl http://localhost:11434/api/ps # running modelscurl http://localhost:11434/api/generate -d '{ "model": "qwen2.5:7b-instruct-q4_K_M", "prompt": "Say hello world", "stream": false}'curl http://localhost:11434/api/generate -d '{ "model": "llama3.1:8b-instruct-q4_K_M", "prompt": "Say hello world", "stream": false}'Pretty-print the JSON response:
curl -s http://localhost:11434/api/generate -d '{ "model": "qwen2.5:7b-instruct-q4_K_M", "prompt": "Say hello world", "stream": false}' | python -m json.toolCheck from Python
Section titled “Check from Python”To call the models, no special Ollama Python package is needed. A plain HTTP request is enough since Ollama exposes a local HTTP API. Install requests in your venv:
pip install requestsimport requests
url = "http://localhost:11434/api/generate"payload = { "model": "qwen2.5:7b-instruct-q4_K_M", "prompt": "Say hello world", "stream": False}
response = requests.post(url, json=payload, timeout=60)response.raise_for_status()
print(response.json()["response"])Switch to Llama by changing only the model name:
payload = { "model": "llama3.1:8b-instruct-q4_K_M", "prompt": "Say hello world", "stream": False}Daily checklist
Section titled “Daily checklist”systemctl status ollamaollama listcurl http://localhost:11434/api/tagscurl http://localhost:11434/api/generate -d '{ "model": "qwen2.5:7b-instruct-q4_K_M", "prompt": "Say hello world", "stream": false}'