Why put a LiteLLM gateway in front of Ollama
Put a gateway in front of Ollama when several applications call it directly and the team needs one controlled endpoint to manage them. Ollama's local API listens on 127.0.0.1 port 11434 by default, and the local API does not require authentication. That default is safe for a single developer's machine, but it means a server shared over the network has no built-in identity check, usage record or per-client limit unless you add one. Sharing the server by changing OLLAMA_HOST and placing a reverse proxy such as Nginx in front is one option, and the Ollama FAQ describes that pattern. A gateway goes further by deciding who may call which model and recording what they did.
LiteLLM is an open source project that works as both a Python SDK and an AI gateway (proxy server). Its proxy accepts requests in the OpenAI request format and calls more than 100 LLM providers, so an application can use one endpoint for an Ollama model and for a hosted model. The code outside its enterprise/ directory is MIT licensed, while enterprise/ falls under its own license, so confirm which features your deployment uses before you adopt it. The gateway is worth its extra component when you need virtual keys, per-team budgets, fallbacks between servers, or a single audit point. For one application on one workstation, calling Ollama directly is usually simpler. Ask your team to list the applications, users and model consumers first, then decide whether a gateway's database and Redis dependencies are justified for that list.
How requests flow from applications through LiteLLM to Ollama
The flow starts with an application sending an OpenAI-style request with a virtual key to the LiteLLM proxy. The proxy checks the key against its budgets, rate limits and model allow-list, then hands the request to the router, which uses PostgreSQL for keys and spend records and Redis when more than one proxy instance runs. The router sends the call to one of several Ollama servers inside the private network, and falls back to an approved hosted provider only if policy allows it. Check that Ollama servers are reachable only from the proxy, and that the hosted path sits outside the private trust boundary.
Requests pass through the proxy, router and stores before reaching Ollama or a fallback provider.
Which LiteLLM routing and key options fit which setup
This table compares the LiteLLM routing strategies, failover controls and virtual key limits, and says when each fits a shared Ollama pool. It also notes what each option needs from PostgreSQL or Redis, so you can match the choice to your server count and governance needs before you configure the gateway.
| Option | Best fit for a shared Ollama pool | Needs from database or Redis | Watch for |
|---|---|---|---|
| Simple-shuffle routing | Several identical Ollama servers hosting the same models with similar hardware; the recommended default in the LiteLLM routing docs | Redis once more than one proxy instance runs, for shared router state | Ignores differences in GPU load, so a busy server can still receive requests |
| Usage-based routing | Pools where servers have different capacity and you want traffic weighted toward the ones with spare token throughput | Redis for shared usage state across proxy instances | Confirm the usage metrics behave as expected with your Ollama model names before relying on them |
| Latency-based routing | Mixed hardware, such as a GPU server beside a slower CPU host, where response time should steer traffic | Redis for shared latency state across proxy instances | Latency measurements shift with prompt length, so test with realistic prompts |
| Least-busy routing | Workloads with long generations where queue depth matters more than raw speed | Redis for shared in-flight request counts across proxy instances | Ollama's own queue (OLLAMA_MAX_QUEUE) still applies behind the gateway |
| Cost-based routing | Pools that mix local Ollama with paid hosted models, so local capacity is preferred | Redis for shared router state; cost values come from your model configuration | Local Ollama usually has no per-token cost, so set cost values deliberately |
| Retries, cooldowns and priority failover | Keeping service up when one Ollama server fails, with a fixed order of preferred servers | Redis for shared cooldown state across proxy instances | Failover to a server without the same model or context size can change answers |
| Virtual keys with budgets, RPM and TPM limits | Giving each team or application its own key with spending and rate caps over a shared server | PostgreSQL is required for virtual keys; Redis helps enforce limits across instances | Budgets track LiteLLM-recorded spend, so confirm how local Ollama usage is priced |
| Model restrictions on keys | Limiting sensitive teams to approved local models and keeping experimental models off their keys | PostgreSQL, because key settings are stored with virtual keys | Keys restrict models by name in the gateway, not by Ollama server access, so also restrict network paths |
How to set up LiteLLM in front of Ollama servers
This sequence places LiteLLM between your applications and one or more Ollama servers, so clients call a single OpenAI-style endpoint with virtual keys, while the Ollama servers stay off client networks. Each step ends with a check you can run before moving on.
Bind Ollama to the gateway network only
On each Ollama host, set OLLAMA_HOST so the server listens on a private interface reachable only from the LiteLLM host, instead of the default 127.0.0.1 binding on port 11434. Confirm that the network path is limited to the gateway with your firewall or security group rules, because the local Ollama API does not require authentication. Set OLLAMA_NO_CLOUD=1 or the equivalent server configuration entry if cloud features are not wanted for this server. Done means that a request from the gateway host reaches the Ollama API and a request from any other host is refused.
Define each Ollama server as a model deployment
In the LiteLLM proxy configuration, add one model entry per Ollama server and model pair, pointing each entry at that server's address and port. Use the same model name across servers when they serve the same model, so the router can balance and fail over between them. Keep the list of models to what your approval process has cleared. Done means the configuration file lists every intended Ollama backend, and the proxy starts without configuration errors.
Deploy the proxy with PostgreSQL and a managed master key
Deploy the LiteLLM proxy with PostgreSQL as its database, which virtual keys require. Generate LITELLM_MASTER_KEY, make sure it starts with sk-, and load it from a secret manager rather than a plain configuration file or shell history. For Kubernetes, LiteLLM recommends one Uvicorn worker per pod and scaling by adding pods. Done means the proxy health endpoint responds and an admin call that uses the master key succeeds while the same call without it is rejected.
Add Redis before running more than one proxy instance
Once you run more than one proxy instance, deploy Redis 7.0 or newer. Redis holds the shared state for rate limits, router state and cache, so the instances behave consistently. Point every proxy instance at the same Redis and PostgreSQL. Confirm the version your team deploys with the LiteLLM production guide before you go live. Done means two proxy instances report the same rate limit counters when a test client sends requests to each in turn.
Create virtual keys for each application and team
Using the master key, create virtual keys for each application, user group or team, and restrict each key to the models it is approved to call. Set per-key or per-team budgets and request limits where your policy requires them. Store the issued keys in the consuming application's secret store, not in source code. Done means a key can call its approved model, and the same key is refused for a model outside its list.
Verify routing, failover and spend records
Send test calls through the gateway using a virtual key and the OpenAI-format client you plan to use. Confirm that requests for a shared model are distributed across Ollama servers, then stop one server and confirm that calls still succeed through the remaining backend. Check that each call appears in the PostgreSQL spend records and the logs under the correct key. Done means routing, failover and spend tracking each show the expected result in a written test record that your security and operations teams can review.
How LiteLLM load balancing and fallbacks behave with Ollama
LiteLLM's router can spread requests across several Ollama servers and move traffic when one fails, but it cannot raise the capacity of any single server. Each Ollama instance still enforces its own limits: OLLAMA_NUM_PARALLEL defaults to 1 parallel request per model, OLLAMA_MAX_LOADED_MODELS caps how many models stay resident (three times the GPU count, or 3 on CPU, by default), and OLLAMA_MAX_QUEUE holds up to 512 queued requests before it rejects more. Treat these values as the ceiling the gateway must respect. Set the LiteLLM concurrency and rate limits per deployment so that the gateway sends no more concurrent work to one server than that server can queue and serve, and confirm the current defaults for your Ollama version in the Ollama FAQ before you tune anything.
LiteLLM's routing options decide how failure is handled. Retries re-send a failed call, cooldowns temporarily remove a deployment after repeated errors, and priority ordering sends traffic to a primary Ollama server and only uses secondaries when it fails. Simple-shuffle is the recommended strategy for even distribution, while usage-based, latency-based and least-busy routing suit uneven hardware. Session affinity keeps a user's requests on one server, which can help with warm model caches, but it can also pin a busy user to an overloaded machine. Test each strategy with realistic concurrency on your own GPUs, and confirm the retry and cooldown settings in the LiteLLM routing docs.
A fallback from a local Ollama model to a hosted model is a data handling decision, not only an availability one. Once a request leaves your servers for a provider, your prompts, outputs and logs follow different terms and may land in another jurisdiction. Write a policy that lists which fallbacks are permitted, which data classes may use them, and who approves changes, and enforce it with model-level restrictions on virtual keys. Where the policy forbids external fallback, the correct behavior is a clear error or a queue, not a silent reroute. Confirm with your security and compliance teams before enabling any fallback route.
Security controls the gateway must add in front of Ollama
Ollama's local API has no authentication, so the controls that protect it sit in front of it. The gateway becomes the single point where keys, network paths and administrator access are enforced, and each control below closes a gap the gateway does not close on its own.
Keep Ollama off the public network
Ollama binds to 127.0.0.1 on port 11434 by default, and the OLLAMA_HOST variable changes that bind address. Keep the bind address on a private interface reachable only by the LiteLLM proxy, and confirm with a port scan from outside that the Ollama port is closed. Any path that reaches Ollama without passing through the gateway bypasses every key, budget and log in this design.
Scope and rotate virtual keys
Issue one virtual key per application or team rather than sharing a master key, and restrict each key to the models it needs. Set per-key budgets and request limits so a leaked key has a bounded blast radius. Define a rotation schedule and test that revoking a key stops traffic within your change process.
Virtual keys docsStore the master key in a secret manager
LITELLM_MASTER_KEY must start with sk- and grants administrative control of the proxy, so it should never appear in a container image, Git repository or shared shell history. Inject it at runtime from a secret manager and limit who can read it. Ask your team who holds the key, how it is rotated and how a rotation is rolled out across proxy instances.
SSO for the admin UI
The admin UI supports SSO with Google, Microsoft Entra ID, Okta and generic OIDC providers, so administrators sign in with corporate identities rather than shared credentials. SSO is free for up to 5 users from v1.76.0, and an Enterprise license is required beyond that. Count your administrators before choosing an identity model, and confirm the license terms in writing.
Admin UI SSO docsAudit logs and IP allowlisting
Audit logs and IP allowlisting are listed as Enterprise features, so they are not part of the open source deployment. Audit logs show who changed keys, budgets and routes, and IP allowlisting limits where administrative and API calls can originate. If your control set requires either, confirm the feature exists in the license you buy before the design is final.
Enterprise docsKeep Ollama cloud keys out of local config
Direct cloud inference at ollama.com requires an API key sent as a Bearer token, and that key grants paid access under your account. Keep it in the gateway's secret store, not in the Ollama host's environment or client config files, and disable cloud features on local servers with OLLAMA_NO_CLOUD=1 where cloud models are not approved. Ask who owns the Ollama account and how key usage is reviewed.
Questions teams ask before adding a LiteLLM gateway to Ollama
Does adding a LiteLLM gateway in front of Ollama cost money?
LiteLLM's core code is open source under the MIT license, so the software itself has no license fee for the parts outside the enterprise/ directory. The license file in the LiteLLM repository splits the two: enterprise/ content uses its own license. Enterprise features such as SSO and SCIM beyond the free limit, audit logs, organization and team RBAC, IP allowlisting and secret manager integrations require an Enterprise license. Running models on your own hardware through Ollama is unlimited according to Ollama's pricing page, so the recurring costs sit in what you run: compute for the gateway, a PostgreSQL database (required for virtual keys), Redis once more than one proxy instance runs, logging storage, and the engineering time to operate them. Ask any implementation partner for a written quote that separates one-time setup from recurring infrastructure and support.
How long does a LiteLLM gateway setup take for Ollama?
Duration depends on how many Ollama servers, applications and identity sources are involved, and on how much of the routing and budget design is decided before build starts. A single gateway in front of one Ollama server with one application is a much smaller job than a multi-server pool with per-team budgets, SSO and audit logging. The main drivers are the database and secrets setup, the number of model aliases and routing rules, whether SSO and Enterprise controls are needed, the network path from the gateway to each Ollama host, and testing with every client that will connect. We do not publish a fixed duration. Ask for a timeline tied to a written scope that lists these items.
Can our own team set up LiteLLM in front of Ollama without outside help?
Yes, a team with container, Kubernetes or Linux operations experience and some familiarity with PostgreSQL and reverse proxies can set up a basic gateway from the LiteLLM documentation. The harder parts are production settings: a secret manager for the master key, one Uvicorn worker per pod with horizontal scaling on Kubernetes, batched spend updates, shared Redis state, and network controls so that clients reach only the gateway and the gateway reaches only approved Ollama hosts. Because Ollama itself has no authentication on localhost:11434, the gateway often becomes the only protected entry point, which makes its configuration a security decision. Teams that want an outside review of that design can scope it as a separate, fixed engagement with DeployOpen.
What does our organization need to provide for a LiteLLM gateway project?
Expect to provide the following before build starts:
- Cloud accounts or data center access where the gateway, database and Redis will run.
- A PostgreSQL database and, if you run several proxy instances, Redis 7.0 or newer.
- Network design: which applications reach the gateway, which Ollama servers it may call, and whether any hosted providers are approved for use.
- A model inventory listing each Ollama model, its approved users, and the aliases applications will call.
- Identity decisions: whether admin UI SSO is needed, which provider you use, and how teams map to budgets.
- Secret storage for the master key and provider credentials.
The model inventory is often the slowest item because it requires decisions from data owners, not only engineers.
How do we track LiteLLM upgrades against its release line?
LiteLLM publishes releases on its GitHub releases page, and its enterprise documentation states that it maintains support for the four most recent stable minor versions for both open source and Enterprise deployments. Plan a scheduled review of that page, pin the proxy image to a tested version, and test each candidate against your routing rules, virtual keys and logging before promotion. Check that the database schema migrations and any Redis or Python dependency changes are included in the test plan. Record which version each environment runs so that security patches can be applied within the support window. Ask any partner to define the upgrade cadence, test scope and rollback steps in the written scope.
What happens to our data when requests pass through LiteLLM and Ollama?
Ollama states that when it runs locally it does not see your prompts or data, and cloud features can be turned off with OLLAMA_NO_CLOUD=1 or the server configuration file. LiteLLM sits in the request path, so it handles prompts and responses, and it can write request logs, spend records and virtual key data to your database. Decide what is logged, how long logs are kept, who can read them, and whether any requests are routed to hosted providers. Restrict routing so that sensitive model aliases can only reach approved Ollama hosts. Confirm these choices with your compliance and security teams before go-live.
Does a LiteLLM gateway make our Ollama servers highly available?
Not by itself. LiteLLM's router can spread requests across several Ollama deployments, retry failed calls, place failing deployments in cooldown and fail over by priority, which helps when one server is unavailable. However, the gateway, PostgreSQL and Redis become their own points of failure, and each Ollama host still has its own capacity limits, such as OLLAMA_NUM_PARALLEL and OLLAMA_MAX_QUEUE. Confirm the failover design with a test that stops one Ollama host and checks what applications see, and make sure the database and gateway tier have their own redundancy plan.
Limits to confirm in your environment before rollout
A LiteLLM gateway in front of Ollama adds a database, a cache, proxy workers and a provider configuration layer, and each one has limits that depend on your traffic and version. The cards below list the items to confirm with the LiteLLM documentation and your own load tests before you route production traffic through it.
PostgreSQL as the database
Virtual keys, budgets and spend tracking all need a database, and LiteLLM names PostgreSQL as the primary supported database. Confirm that your platform team will run it with backups and high availability, and that the schema for your chosen LiteLLM version is applied before the proxy starts. Ask how spend records will be retained for your audit needs.
Production guideRedis 7.0 for multiple instances
Once more than one proxy instance runs, shared rate limits, router state and cache depend on Redis. The production guide requires Redis 7.0 or newer for that setup. Confirm the Redis version your platform offers, decide whether it is highly available, and test what happens to rate limits if Redis is unavailable.
Per-worker sizing guidance
The production guide suggests 1 vCPU and 4 GiB memory per worker. Treat that as a starting point, not a capacity plan. Your numbers depend on request size, streaming, logging callbacks and how many Ollama backends you route to. Run a load test with your own prompts and record CPU and memory per worker before you set limits.
One Uvicorn worker per pod
On Kubernetes, LiteLLM recommends one Uvicorn worker per pod and scaling horizontally with more pods. Confirm that your deployment manifests set the worker count this way, that autoscaling targets are tied to request load, and that each pod's resource limits match the per-worker sizing you tested.
Production guideSpend batching at scale
At high volume, LiteLLM batches spend updates to the database every 60 seconds. Spend figures on dashboards and budget checks may therefore lag behind live traffic by up to that interval. Confirm whether your budget enforcement can tolerate that lag, and agree with finance how spend reports will be reconciled against Ollama usage.
Ollama version and endpoint compatibility
Each client calls a specific endpoint and uses specific request fields, and the LiteLLM provider settings for Ollama must support them. Confirm the Ollama version you run (for example, from the GitHub releases page) and test each client's calls through the gateway. Record which endpoints and fields pass, and retest after any upgrade of either product.
Ollama releasesOperating the LiteLLM gateway and Ollama pool over time
Once the gateway is serving traffic, the operating work is watching three things: what the gateway logs and what it spends, how each Ollama server behaves under load, and what changes when either side is upgraded. Treat the LiteLLM database as the system of record for spend and key activity, because the virtual keys, per-key and per-team budgets and TPM and RPM limits described elsewhere on this page all depend on it. Confirm with your team how long request metadata is retained, who can read it, and whether prompt and response content is logged at all, since the logging settings decide what sensitive data ends up in the database. Batched spend updates mean recent spend figures may lag slightly, so budget alerts should use margins that account for that delay.
Per-server health is the signal that tells you a backend is failing before users complain. Watch for the router placing a server into cooldown after repeated failures, and for retries that succeed only on a second server, because both point to a degraded Ollama host rather than a bad request. Compare which models each server has loaded against the concurrency settings you chose, using OLLAMA_NUM_PARALLEL, OLLAMA_MAX_LOADED_MODELS and OLLAMA_MAX_QUEUE on the Ollama side, so queueing shows up in your dashboards rather than as timeouts. Confirm how your LiteLLM version exposes cooldown and failure events in logs or metrics before you build alerts on them.
Ollama upgrades need a test cycle before rollout. The Ollama GitHub releases page listed v0.40.5 on 14 October 2026 and v0.40.6 as a pre-release on 16 October 2026, so a canary Ollama server should run the candidate version against the same models, prompts and tool-calling workloads your applications use, with latency and error rates compared to the current pool. Keep at least one server on the previous version until the canary passes. Pin LiteLLM as well: upgrade within the four most recent minor versions it supports, as stated in its enterprise documentation, and check the LiteLLM releases page for the current list, where v1.105.1 was published on 14 October 2026. Read the release notes for schema migrations before each upgrade, and rehearse them against a copy of the database.
How DeployOpen scopes and delivers a LiteLLM gateway for Ollama
DeployOpen plans, builds, tests and documents a LiteLLM gateway in front of your Ollama servers, inside your own infrastructure. Each engagement starts with a written scope that names the applications, Ollama hosts, providers and controls involved, so the team knows what is delivered before work begins.
How we scope
- We inventory the applications and user tools that will call the gateway and the models each one needs.
- We map which Ollama servers, cloud providers and private models sit behind the gateway and how each is reached.
- We agree in writing how keys, budgets, logging and access reviews will work before any build starts.
How we build
- We deploy the LiteLLM proxy with PostgreSQL and, when more than one proxy instance runs, Redis, in your environment.
- We configure model routes, load balancing, retries and fallbacks across the Ollama servers in scope.
- We set up virtual keys, per-team budgets and rate limits, then test that restricted models stay unavailable to other teams.
How we hand over
- We document the gateway configuration, routing rules, key ownership and the procedure for adding or removing an Ollama server.
- We walk your platform and security staff through logging, spend reports and the master key storage approach.
- We test failover and key revocation against the agreed scope, then provide a findings list and fixes for review.
How we support
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
- Upgrades to LiteLLM and Ollama, configuration changes and continuous testing can be covered by a retainer.
- Ask for the support boundaries, response arrangements and upgrade process in writing as part of the quote.

