Detailed comparison of running local LLMs with Ollama vs cloud APIs.
Choosing between local LLMs (Ollama) and cloud APIs (OpenAI, Anthropic, Google) involves trade-offs across cost, privacy, performance, and control. This guide provides a detailed comparison to help you decide based on your specific requirements.
Quick Comparison
Factor
Ollama (Local)
Cloud APIs
Privacy
✅ Data never leaves your machine
⚠️ Sent to provider (check policies)
Cost
Hardware + electricity only
Per-token pricing, scales with usage
Latency
Low (local), depends on hardware
Network + provider queue
Model Choice
Limited to open weights
Latest proprietary models
Scaling
Vertical (bigger GPU)
Horizontal (API handles scale)
Maintenance
Self-managed
Provider managed
Offline
✅ Full offline
❌ Requires internet
Compliance
✅ Easy data residency
⚠️ Depends on provider regions
Cost Analysis
Ollama — Hardware Costs
Setup
GPU
VRAM
Models Supported
Est. Cost
Consumer
RTX 3060
12 GB
7B-13B q4
$300-400
Enthusiast
RTX 3090/4090
24 GB
30B-70B q4
$800-2000
Dual GPU
2x 3090/4090
48 GB
70B+ q4, 30B q8
$1600-4000
Apple Silicon
M2/M3 Max/Ultra
64-192 GB
70B+ q4, 30B q8
$2000-6000
Server
A100 40/80GB
40-80 GB
Any open model
$1-3/hr cloud
Rule of thumb: Model size (params) × quantization bits ÷ 8 = VRAM needed. Add 2-4 GB for context/KV cache.
# Examples:
# 7B q4 = 7×4/8 = 3.5 GB + 2 GB = ~5.5 GB VRAM
# 13B q4 = 13×4/8 = 6.5 GB + 2 GB = ~8.5 GB VRAM
# 30B q4 = 30×4/8 = 15 GB + 4 GB = ~19 GB VRAM
# 70B q4 = 70×4/8 = 35 GB + 8 GB = ~43 GB VRAM
Cloud API — Per-Token Costs (2026)
Provider
Model
Input (1M tokens)
Output (1M tokens)
Context
OpenAI
GPT-4o
$2.50
$10.00
128K
OpenAI
GPT-4o-mini
$0.15
$0.60
128K
Anthropic
Claude 3.5 Sonnet
$3.00
$15.00
200K
Anthropic
Claude 3.5 Haiku
$0.80
$4.00
200K
Google
Gemini 1.5 Pro
$1.25
$5.00
1M/2M
Google
Gemini 1.5 Flash
$0.075
$0.30
1M
Together.ai
Llama-3.1-70B
$0.90
$0.90
128K
Fireworks
Llama-3.1-70B
$0.90
$0.90
128K
Break-Even Calculation
# Monthly tokens needed to justify $2000 GPU (3-year amortization = $55/mo)
gpu_monthly = 55
# Cloud cost per 1M tokens (blended input/output)
cloud_cost_per_m = 3.00 # e.g., GPT-4o-mini blend
break_even_tokens = gpu_monthly / cloud_cost_per_m * 1_000_000
# = 18.3M tokens/month
# For a team of 5 developers, ~3.6M tokens each/month
# ~120K tokens per developer per day
Verdict: If your team processes <20M tokens/month, cloud APIs are cheaper. Above that, local hardware wins.
Privacy & Compliance
Requirement
Ollama
Cloud APIs
GDPR / Data Residency
✅ Trivial
⚠️ EU regions only
HIPAA / PHI
✅ No data leaves
⚠️ BAA required, limited providers
SOC 2 / ISO 27001
✅ Your controls
✅ Provider certified
ITAR / Export Control
✅ Air-gapped OK
❌ Generally prohibited
Corporate IP Protection
✅ Zero egress
⚠️ Contractual only
Government / Classified
✅ Required
❌ Prohibited
Performance Benchmarks
Latency Comparison (Typical)
| Scenario | Ollama (RTX 4090) | Cloud API (US-East) |
|———-|——————-|———————|
| First token (7B) | 50-100 ms | 200-500 ms |
| First token (70B) | 200-400 ms | 300-800 ms |
| Throughput (7B) | 80-120 tok/s | 50-100 tok/s |
| Throughput (70B) | 20-30 tok/s | 30-60 tok/s |
Quality Comparison
Task
Best Local (70B)
Best Cloud
Verdict
Code generation
DeepSeek-Coder-V2, CodeLlama-70B
GPT-4o, Claude 3.5 Sonnet
Cloud wins
Reasoning/Logic
Nemotron-3-Ultra, Qwen2.5-72B
o1, Claude 3.5 Sonnet
Cloud wins
Creative writing
Qwen2.5-72B, Llama-3.1-70B
GPT-4o, Claude 3.5 Sonnet
Tie
Multilingual
Qwen2.5, Aya-23
GPT-4o, Gemini 1.5
Cloud wins
Structured output
Limited (via grammar)
Native JSON mode
Cloud wins
Function calling
Limited (via prompts)
Native
Cloud wins
Hybrid Architecture (Recommended)
Use both: route by sensitivity and task type.
# router.py - Simple privacy-aware router
import os
import ollama
import openai
import anthropic
def route_request(prompt: str, context: dict) -> str:
"""
Route to local or cloud based on sensitivity.
"""
# Sensitivity flags
has_secrets = any(k in prompt.lower() for k in ['api_key', 'password', 'secret', 'token', 'private_key'])
has_pii = any(k in prompt.lower() for k in ['ssn', 'email', 'address', 'phone', 'medical'])
is_proprietary = context.get('repo_private', False)
# High sensitivity → local only
if has_secrets or has_pii or is_proprietary:
return ollama_generate(prompt, model='deepseek-coder:33b')
# Coding tasks → prefer local for speed/privacy balance
if any(k in prompt.lower() for k in ['function', 'class', 'debug', 'refactor', 'test']):
return ollama_generate(prompt, model='codellama:34b')
# Complex reasoning, large context → cloud
if len(prompt) > 8000 or context.get('needs_reasoning', False):
return claude_generate(prompt, model='claude-3-5-sonnet')
# Default: local
return ollama_generate(prompt, model='llama3.1:8b')
def ollama_generate(prompt: str, model: str) -> str:
response = ollama.generate(model=model, prompt=prompt, stream=False)
return response['response']
def claude_generate(prompt: str, model: str) -> str:
client = anthropic.Anthropic(api_key=os.getenv('ANTHROPIC_API_KEY'))
response = client.messages.create(
model=model, max_tokens=4096, messages=[{'role': 'user', 'content': prompt}]
)
return response.content[0].text
Model Recommendations by Use Case
Use Case
Local (Ollama)
Cloud
Daily coding assistant
CodeLlama-34B, DeepSeek-Coder-V2
GPT-4o-mini, Claude Haiku
Complex architecture
Nemotron-3-Ultra, Qwen2.5-72B
GPT-4o, Claude 3.5 Sonnet
Code review
CodeLlama-34B, Starcoder2-15B
GPT-4o, Claude 3.5 Sonnet
Documentation
Llama-3.1-70B, Qwen2.5-72B
GPT-4o, Gemini 1.5 Flash
Data analysis
Nemotron-3-Ultra, Qwen2.5-72B
GPT-4o, Claude 3.5 Sonnet
Creative/Marketing
Llama-3.1-70B, Qwen2.5-72B
GPT-4o, Claude 3.5 Sonnet
High-security/Compliance
Local only
Not recommended
Ollama Production Checklist
Item
Details
GPU Monitoring
nvidia-smi, DCGM, Prometheus exporters
Model Updates
Pin versions, test before rolling out
Request Queuing
Use ollama serve with multiple workers
Context Length
Configure num_ctx (default 4K, max 128K+)
Quantization
q4_K_M for balance, q8_0 for quality
KV Cache
Monitor VRAM, enable flash attention
Load Balancing
nginx + multiple ollama instances
Logging
Structured JSON, ship to Loki/Elastic
Backups
Model registry, config version control
Related Tools on DevStackIO
References
Post navigation