LiteLLM and Ollama: Set Up a Local-Only Model Gateway
TL;DR: Add LiteLLM when several clients need a stable model alias or a shared routing layer. For one application and one Ollama model, direct access is simpler. Start with one local backend, no cloud fallback, and a loopback listener. Verify the actual route before describing the stack as private.
What you’ll be able to do:
- Separate the gateway’s license and responsibilities from those of the model server and weights.
- Configure a single client-facing alias that points to a local Ollama chat model.
- Check authentication, model naming, and backend failure without silently introducing a cloud route.
What does LiteLLM add to an Ollama setup?
LiteLLM can sit between your application and the server that runs the model. Your application calls a gateway alias, such as local-assistant; the gateway maps that name to a provider-specific model identifier. Ollama still loads the weights and performs inference. Adding a gateway does not make the model smaller, improve its reasoning, or create more GPU memory.
The configuration boundary can be useful when several applications should share the same backend selection. You can change the mapping centrally instead of editing every client’s settings. That convenience also introduces another process, another configuration file, and another place where a request can fail. Treat those as operating costs, even when the software itself has no license fee for this use.
Ollama already provides a subset of the OpenAI-compatible API. Its compatibility documentation includes direct local access at http://localhost:11434/v1/. If that satisfies your application, try it first. Our Ollama guide covers the backend itself; this article concentrates on the additional gateway boundary.
| Requirement | Direct Ollama | LiteLLM in front of Ollama |
|---|---|---|
| One client and one local model | Fewer components | Often unnecessary |
| Shared client-facing alias | Configure clients around your backend naming | Central mapping in the gateway |
| Diagnose a failed generation | Inspect client and Ollama | Inspect client, gateway, and Ollama |
| Keep inference local | Choose a local model and verify server behavior | Verify both routing and backend behavior |
| Reduce model memory use | Change model or runtime settings | A proxy alone does not help |
Which parts are actually open source?
The LiteLLM license applies MIT terms to code outside its stated enterprise-directory exception. The enterprise directory has its own license. Do not describe every feature under the product name as MIT-licensed simply because the repository has an MIT section.
Ollama’s server license is MIT. Model weights have their own terms, which are not replaced by the server’s license or by a gateway. Check the exact model card and license for the tag you deploy, especially if you redistribute weights or offer a service to other people. This tutorial does not select a particular weight license on your behalf.
The setup below uses a local process, one model alias, and a gateway master key. It does not require a paid hosted gateway or a cloud inference account. An organization that needs advanced access controls should check the current edition boundaries before assuming a feature is included. License availability and operational suitability are separate decisions.
What should you prepare before installing the gateway?
First establish a working local Ollama model. Run ollama list, choose an exact installed tag, and verify a simple prompt directly. Do not copy a model name from an unrelated benchmark and assume that its weights are present. Ollama also documents the /api/tags endpoint for listing models programmatically.
Second, record the versions you intend to use. On November 4, 2026, PyPI’s package metadata identified LiteLLM 1.106.6, with a Python requirement of at least 3.10 and below 3.15. The versioned package page and project releases are the references for that snapshot. A package version is not a guarantee that every optional dependency works on every platform.
Use a separate Python environment for the proxy. After activating it, a version-specific installation looks like this:
python -m pip install "litellm[proxy]==1.106.6"
python -m pip show litellm
Review the current release and security notes before deploying a version after this article’s verification date. Keep the working environment or a dependency lock so an unrelated installation does not silently change the gateway. Avoid starting with a moving container tag when you need to reproduce a failure later.
The gateway does not need a GPU to route requests. The inference hardware requirement belongs to your chosen model, quantization, context length, and concurrency. We are not asserting a universal RAM floor for the full stack. Use your existing working Ollama setup as the baseline, then measure the extra process on your own machine before sizing a shared service.
How do you keep the initial route local?
Use a local Ollama model and disable cloud features on the Ollama server. The Ollama FAQ documents OLLAMA_NO_CLOUD=1 and the corresponding server configuration option. The environment setting must reach the process that actually starts Ollama, and the server must be restarted for it to take effect. Setting a variable in an unrelated terminal does not reconfigure an already-running desktop app or service.
For this walkthrough, run the client, LiteLLM, and Ollama on the same host. Use 127.0.0.1 explicitly. In a container, that address refers to the container itself, so this host-process configuration cannot be copied unchanged into Docker. Diagnose that addressing difference before changing authentication or adding external endpoints.
Do not configure a cloud fallback, wildcard model route, remote logging callback, or a database-backed routing configuration while establishing this baseline. Those are separate features with separate data paths. A loopback address describes where the first connection goes; it does not prove that every downstream component remains offline. Our Ollama cloud proxy guide explains why the model choice also matters.
What belongs in the minimal config.yaml?
Create config.yaml in your dedicated gateway directory:
model_list:
- model_name: local-assistant
litellm_params:
model: ollama_chat/REPLACE_WITH_INSTALLED_TAG
api_base: http://127.0.0.1:11434
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
Replace REPLACE_WITH_INSTALLED_TAG with the exact tag you verified. Keep the ollama_chat/ provider prefix. LiteLLM’s Ollama provider documentation explains that this prefix sends chat requests to Ollama’s /api/chat endpoint. The backend base URL here ends at the port; it is not the client’s /v1 compatibility URL.
The client uses local-assistant, not the full provider-prefixed string. LiteLLM’s configuration reference distinguishes the public model_name from litellm_params.model and documents environment references for secrets. Keep the key out of the YAML file and out of source control.
In PowerShell, generate a temporary gateway key in the current session and start the proxy:
$env:LITELLM_MASTER_KEY = 'sk-' + (python -c "import secrets; print(secrets.token_hex(32))")
litellm --config config.yaml --host 127.0.0.1 --port 4000
Run your client from an environment that receives the same key without printing it or committing it. For a persistent deployment, use your normal secret-management mechanism. The CLI reference documents the host and port flags; explicitly binding loopback avoids relying on the CLI’s broader default listener.
How do you test the client without hiding HTTP failures?
Save this Python client as probe_gateway.py. It uses the standard library, reads the gateway key from the environment, and prints an HTTP error body if the server rejects the request. Use only the synthetic prompt shown here while diagnosing the route.
import json
import os
from urllib.error import HTTPError
from urllib.request import Request, urlopen
payload = {
"model": "local-assistant",
"messages": [{"role": "user", "content": "Reply with the word ready."}],
"stream": False,
}
request = Request(
"http://127.0.0.1:4000/chat/completions",
data=json.dumps(payload).encode("utf-8"),
headers={
"Content-Type": "application/json",
"Authorization": "Bearer " + os.environ["LITELLM_MASTER_KEY"],
},
)
try:
with urlopen(request, timeout=120) as response:
result = json.load(response)
except HTTPError as error:
print(error.read().decode("utf-8", errors="replace"))
raise
print(result["choices"][0]["message"]["content"])
The timeout is an example client limit, not a performance promise. A successful response proves that this request completed; it does not establish that your model supports tools, images, structured outputs, or every feature your final application expects. Add those tests individually after basic chat works.
Check the gateway and backend logs to establish which route handled the request. Avoid verbose prompt logging with real private data. Keep the configuration minimal until you can explain the relationship between the alias, provider prefix, host, and endpoint without relying on a successful-looking UI response.
Which failure checks should pass before connecting an app?
Test an incorrect gateway key and confirm that the request is rejected. Then restore the correct key and request an alias that does not exist. Finally, stop only the disposable test backend or point a disposable configuration at an unused local port. The last request should fail, not return an answer from a different provider.
| Symptom | First place to inspect | Avoid this shortcut |
|---|---|---|
| Connection refused on port 4000 | Gateway process and listener | Removing authentication |
| Authentication rejected | Client key and gateway environment | Embedding a real key in shared YAML |
| Unknown model alias | Client model versus model_name | Adding a wildcard route |
| Backend connection error | Ollama process and api_base | Adding cloud fallback to hide the error |
| Backend says model is missing | Exact installed tag | Guessing another model name |
| Chat works but an app fails | The app’s actual request features | Assuming complete API compatibility |
These checks test different boundaries. A listed alias is not proof that weights are installed, and a valid gateway key is not proof that the backend is reachable. Keep the failure output with the configuration version so the next change has a useful baseline.
Our local routing check: On November 4, we installed LiteLLM 1.106.6 in an isolated Python 3.14 environment on Windows and ran its actual HTTP proxy against a small synthetic Ollama-shaped server. The alias reached /api/chat with the expected backend model name and returned the fixture text. An incorrect key returned HTTP 400 in this database-free setup, an unknown alias returned 400, and a stopped backend returned 500 with no fallback attempted. The test used temporary loopback ports and disabled retries to keep the failure check bounded. These are gateway routing results, not a real Ollama inference test, a privacy audit, or measurements of model quality and speed. Your application should handle the error body rather than assume that every authentication rejection is necessarily HTTP 401.
Honest take: when is the extra gateway worth maintaining?
Use the gateway when central alias management solves a real coordination problem across clients. Skip it when direct Ollama already supplies the API you need and there is no shared routing policy to maintain. For a different serving backend, our vLLM guide covers another layer of that decision; a gateway does not erase backend-specific behavior.
Local inference avoids a cloud model invoice for these requests, but it is not costless. Hardware, electricity, updates, storage, and your troubleshooting time remain. We have not measured a latency penalty, memory overhead, or break-even point for this setup, so there is no invented performance table or universal savings claim.
Keep the first deployment small enough to understand. Once a single route behaves correctly on both success and failure, decide whether you actually need additional backends, persistence, or multi-user controls. Each addition should come with a clear reason and a new verification step. That is a more useful standard for a self-hosted stack than the number of providers a gateway can theoretically connect.
Sources
- LiteLLM repository license and enterprise exception
- Ollama repository license
- LiteLLM 1.106.6 package
- LiteLLM releases
- LiteLLM Ollama provider
- LiteLLM configuration
- LiteLLM CLI options
- Ollama API compatibility
- Ollama FAQ and local-only mode
- Ollama model listing API
Last updated November 4, 2026. Configuration guidance was checked against official documentation and the gateway was exercised with a synthetic local backend. No real-model inference, model-quality, or hardware-performance measurement is claimed.
Was this article helpful?
Thanks for the feedback — it helps improve future articles.
Need hands-on help?
I offer 1-on-1 technical consulting for local AI setup, GPU selection, and AI coding tool configuration — same topics covered on this site.
Book a session — $49 / hour →What self-hosting actually costs
Real cost breakdowns for self-hosted AI: hardware floors, power, maintenance hours, and the honest comparison against paying for it. No spam, unsubscribe anytime.