AI Agents with Ollama: Local LLMs Without API Keys
Ollama lets you run LLaMA 3, Mistral, Gemma on your VPS. Data never leaves your server, no per-token costs.
Install and Models
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3.2:3b # 2 GB
ollama pull mistral:7b # 4 GB
ollama run llama3.2:3bPython SDK
pip install ollamaimport ollama
response = ollama.chat(
model='llama3.2:3b',
messages=[{'role': 'user', 'content': 'How to optimize nginx for high load?'}]
)
print(response['message']['content'])Security: Never expose Ollama API directly to the internet. Use Nginx with authentication.