Comparing LiteLLM Proxy and Ollama as direct substitutes misses a layer boundary: Ollama is a model execution runtime that loads weights onto GPUs and CPUs, while LiteLLM Proxy is an API gateway that routes, authenticates, meters, and falls back across inference backends. For one developer on a laptop, direct Ollama /v1 is simpler and faster to operate. Once multiple teams, agents, or environments share GPUs and mix local weights with OpenAI or Anthropic APIs, LiteLLM Proxy belongs in front of Ollama and vLLM rather than instead of them.
Teams ask about LiteLLM vs Ollama because both expose an OpenAI-compatible /v1/chat/completions endpoint. That shared HTTP surface hides completely different responsibilities: Ollama manages VRAM allocation and token generation, whereas LiteLLM Proxy manages callers, quotas, secrets, retries, and spend attribution. For how Ollama itself compares to llama-server and vLLM at the execution layer, see the local LLM inference servers guide.
Runtime vs gateway: why they sit at different layers
Ollama owns hardware execution on a single node. It pulls GGUF models, loads them into VRAM on demand, schedules parallel slots via OLLAMA_NUM_PARALLEL, and unloads idle weights after five minutes by default according to the Ollama FAQ. What Ollama intentionally omits is multi-tenant governance: its local server has no built-in API keys, no per-project spend caps, no Redis-backed rate limiting, and no routing to external cloud models when local GPUs saturate.
LiteLLM Proxy does not run weights or touch CUDA kernels. As documented in the LiteLLM Proxy documentation, it sits as an HTTP control plane in front of 100+ providers, translating a single OpenAI SDK request into calls to Ollama (/api/chat or /v1), vLLM (hosted_vllm/), OpenAI, Anthropic, or AWS Bedrock. Because every caller points at one gateway URL (http://127.0.0.1:4000/v1), applications never embed upstream provider keys or hardcode hostnames of individual GPU servers.
When direct Ollama /v1 is enough vs when to add LiteLLM Proxy
Adding a proxy, PostgreSQL, and Redis introduces moving parts you should not pay for prematurely. Keep direct Ollama when all of the following hold:
- Single user or trusted localhost: Only your IDE, local scripts, or a single backend process on the same host reaches
127.0.0.1:11434. - Uniform model access: Every caller can use the same local model tags without per-service quotas or chargeback.
- No cross-provider fallbacks: If the local GPU restarts or queues up, the caller can wait or fail rather than failing over to a cloud API.
Note that the Ollama OpenAI compatibility docs mark its /v1/responses support as non-stateful and focused on core chat, embeddings, and models endpoints.
Move to LiteLLM Proxy in front of Ollama, vLLM, and cloud providers as soon as any multi-tenant or reliability requirement appears:
- Multiple teams or agents: CI runners, internal tools, and developer IDEs need separate virtual API keys that can be rotated or revoked without touching backend servers.
- Mixed local and cloud routing: Routine summarization hits local Ollama or vLLM (
docs.vllm.aidescribes high-throughput serving in the vLLM documentation), while complex reasoning or overflow traffic falls back to Anthropic or OpenAI automatically. - Hard budget and rate guardrails: Runaway agent loops must hit a token or dollar ceiling before exhausting GPU capacity or cloud credits.
- Centralized audit and telemetry: Security and platform teams want one OpenTelemetry pipeline rather than scraping disparate logs across five inference hosts.
Virtual API keys, PostgreSQL budgets, and Redis rate limits
Exposing raw Ollama over a LAN or sharing one master OpenAI key across microservices makes cost attribution and revocation painful. LiteLLM Proxy solves this by backing virtual keys and usage ledgers with PostgreSQL while enforcing low-latency rate limits and backend health state in Redis.
When PostgreSQL (DATABASE_URL) is connected, administrators use the /key/generate management endpoint with a LITELLM_MASTER_KEY to issue scoped virtual keys (sk-...) per project, environment, or user. Each key can carry an allowed model list, a max_budget, a reset window (budget_duration: "30d"), and explicit requests-per-minute (rpm_limit) or tokens-per-minute (tpm_limit) caps. Even for local Ollama or vLLM calls where token marginal cost is zero on owned hardware, assigning internal token pricing (input_cost_per_token) inside model_list lets platform teams track compute consumption per team in the same dashboard alongside cloud API spend.
# Issue a scoped virtual key for a staging agent with a $25/month cap and 60 RPM
curl -sS http://127.0.0.1:4000/key/generate \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{
"key_alias": "staging-coding-agent",
"models": ["qwen-local", "coder-fallback"],
"max_budget": 25.0,
"budget_duration": "30d",
"rpm_limit": 60,
"tpm_limit": 120000,
"metadata": {"team": "platform", "env": "staging"}
}'
Redis keeps multi-worker LiteLLM containers synchronized. Without Redis, two proxy replicas maintain separate in-memory RPM counters and separate cooldown timers when an upstream node hangs. With REDIS_HOST configured, rate limits stay accurate across workers, and the router tracks consecutive errors (allowed_fails) to place an overloaded Ollama or vLLM instance into a temporary cooldown_time window instead of hammering a dead GPU process.
Fallback chains, load balancing, and OpenTelemetry
Self-hosted GPUs go down for driver updates, OOM restarts, or queue spikes during batch jobs. LiteLLM's router handles this in configuration so agent code stays unchanged.
Inside config.yaml, multiple deployments can share the same logical model_name (such as qwen-local) pointing at two separate Ollama or vLLM hosts, letting the router load-balance using simple-shuffle or least-busy. Alongside load balancing, fallbacks define an ordered escape hatch: if qwen-local returns timeouts, 503 queue-full errors, or enters cooldown, LiteLLM retries against a secondary vLLM server or a hosted cloud model like claude-sonnet or gpt-4o-mini. Set aggressive timeout and num_retries values per route so an agent does not block for minutes on a stalled GPU. For broader resilience patterns around retries, circuit breakers, and approval gates, see the production AI agent architecture guide.
Observability sits in the same layer. Enabling callbacks: ["otel"] emits OpenTelemetry spans and metrics for every routed completion—capturing model alias, latency, prompt and completion token counts, cache hits, and fallback transitions—into any OTLP collector. In environments handling sensitive source code or customer records, disable raw prompt and completion body logging in telemetry attributes (turn_off_message_logging: true in litellm_settings) so traces record latency, status, and token accounting without leaking confidential payloads. More detail on GenAI span design and SLO alerting lives in the AI agent observability guide.
Production Docker Compose and config.yaml setup
Below is a minimal, self-contained gateway stack combining LiteLLM Proxy, PostgreSQL for virtual keys and budgets, Redis for distributed rate limits and cooldowns, and an Ollama upstream bound strictly to localhost or an internal Docker network. Notice that LiteLLM binds 127.0.0.1:4000 so an external reverse proxy (Nginx or Caddy with TLS) controls public ingress.
Save the gateway routing and governance rules in config.yaml:
model_list:
- model_name: qwen-local
litellm_params:
model: ollama_chat/qwen3:8b
api_base: http://ollama:11434
rpm: 60
timeout: 30
model_info:
input_cost_per_token: 0.0000001
output_cost_per_token: 0.0000002
- model_name: qwen-team-vllm
litellm_params:
model: hosted_vllm/Qwen/Qwen3-32B-FP8
api_base: http://10.0.10.24:8000/v1
api_key: os.environ/VLLM_API_KEY
timeout: 45
- model_name: cloud-fallback
litellm_params:
model: openai/gpt-4o-mini
api_key: os.environ/OPENAI_API_KEY
timeout: 30
- model_name: anthropic-fallback
litellm_params:
model: anthropic/claude-sonnet-4-20250514
api_key: os.environ/ANTHROPIC_API_KEY
timeout: 45
router_settings:
routing_strategy: least-busy
num_retries: 2
allowed_fails: 3
cooldown_time: 60
fallbacks:
- qwen-local: ["qwen-team-vllm", "cloud-fallback"]
- qwen-team-vllm: ["anthropic-fallback"]
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
database_url: os.environ/DATABASE_URL
store_model_in_db: true
litellm_settings:
drop_params: true
turn_off_message_logging: true
callbacks: ["otel"]
Pair that configuration with docker-compose.yml, pinning image tags rather than floating :latest tags in production:
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: litellm
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: litellm
volumes:
- pg_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U litellm"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
restart: unless-stopped
command: ["redis-server", "--save", "60", "1", "--loglevel", "warning"]
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
ollama:
image: ollama/ollama:latest
restart: unless-stopped
environment:
OLLAMA_CONTEXT_LENGTH: "32768"
OLLAMA_NUM_PARALLEL: "2"
OLLAMA_KEEP_ALIVE: "15m"
volumes:
- ollama_data:/root/.ollama
litellm:
image: ghcr.io/berriai/litellm:main-stable
restart: unless-stopped
ports:
- "127.0.0.1:4000:4000"
volumes:
- ./config.yaml:/app/config.yaml:ro
environment:
LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
DATABASE_URL: postgresql://litellm:${POSTGRES_PASSWORD}@postgres:5432/litellm
REDIS_HOST: redis
REDIS_PORT: "6379"
VLLM_API_KEY: ${VLLM_API_KEY}
OPENAI_API_KEY: ${OPENAI_API_KEY}
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
OTEL_EXPORTER: otlp_http
OTEL_ENDPOINT: ${OTEL_ENDPOINT}
command: ["--config", "/app/config.yaml", "--port", "4000", "--num_workers", "2"]
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ollama:
condition: service_started
volumes:
pg_data:
redis_data:
ollama_data:
Notice that ollama does not publish port 11434 to the host at all—only litellm talks to http://ollama:11434 over the private Compose network, eliminating unauthenticated port exposure. When running Ollama with NVIDIA GPUs, add deploy.resources.reservations.devices with driver: nvidia and capabilities: [gpu] to the ollama service.
Verify the running gateway with a standard OpenAI SDK call using one of the virtual keys generated earlier:
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:4000/v1",
api_key="sk-your-generated-virtual-key",
)
reply = client.chat.completions.create(
model="qwen-local",
messages=[{"role": "user", "content": "Summarize why Redis cooldowns protect GPUs."}],
temperature=0.2,
)
print(reply.choices[0].message.content)
If you pull the ollama container down during testing, qwen-local fails over transparently to qwen-team-vllm or cloud-fallback without changing client code.
Side-by-side comparison: Ollama vs LiteLLM Proxy
| Capability | Ollama (/v1) |
LiteLLM Proxy |
|---|---|---|
| Core role | Local model execution runtime | Multi-provider LLM API gateway |
| Model execution | Runs GGUF weights on GPU/CPU | None; delegates to Ollama, vLLM, OpenAI, Anthropic |
| Authentication | None built-in; relies on reverse proxy | Virtual sk- API keys per team, app, or user |
| Spend and token budgets | None | PostgreSQL per-key budgets with timed resets |
| Rate limits and cooldowns | OLLAMA_MAX_QUEUE only (global 503) |
Redis-backed RPM/TPM limits and node cooldowns |
| Load balancing and fallbacks | Single node only | Weighted, least-busy routing and fallback chains |
| Observability | ollama ps and per-response timings |
OpenTelemetry spans, callbacks, spend database |
| Operational footprint | Single binary or container | Proxy plus PostgreSQL and Redis for production |
Practical rollout path
Start with the smallest stack that matches your team boundary. Use direct Ollama bound to 127.0.0.1:11434 for single-developer laptops and isolated prototypes. The moment a second developer, a shared CI pipeline, a production agent, or a fallback cloud model enters the picture, keep Ollama (and vLLM) on a private network behind LiteLLM Proxy with PostgreSQL budgets, Redis cooldowns, and OpenTelemetry traces turned on from day one.