Why a shared Ollama server needs per-user API keys
A shared Ollama server used by several teams has no built-in way to tell one caller from another. The local API at localhost:11434 does not require authentication, so anyone who can reach the port can send prompts and consume the same hardware. Per-user keys in front of the server turn that anonymous access into attributable access, which is the control most organizations need before they can set limits, split costs or answer an audit question about who used a model.
A LiteLLM gateway is the usual place to add this layer. It issues virtual keys that teams and individuals hold instead of any shared credential, and it can attach budgets, requests-per-minute and tokens-per-minute limits, and model restrictions to each key, with usage logs recorded against it. Ollama itself is open source under the MIT license and offers no equivalent of these controls on your own hardware, and LiteLLM is dual licensed, with the enterprise/ directory under its own license and the rest under MIT. Confirm the license terms for the features you plan to use before you commit, because some controls such as SSO beyond the free user limit and audit logs sit in the Enterprise tier.
You need this layer when several teams share one server, when you intend to charge usage back to the teams that generate it, or when a regulator, customer or internal audit will expect a record of which identity called which model. If only one trusted team uses a single host on a private network, the added gateway may be more than the situation requires. Decide that before the build, because the gateway also needs its own database and, once more than one proxy instance runs, shared state, and those components carry operational work of their own.
Request flow from team keys to Ollama servers
The flow starts with team applications sending requests with their own virtual keys to the LiteLLM proxy inside the trusted gateway zone. The proxy checks each key against its budgets and rate limits in PostgreSQL, uses Redis for shared state when more than one proxy instance runs, and hands the request to the router. The router picks one of several Ollama servers on private addresses, which are reachable only from the gateway. Check that no Ollama port is reachable from client networks, and that the keys and usage logs stay within the gateway boundary.
Team keys reach only the gateway, which routes to private Ollama servers.
Which LiteLLM settings fit which access model
This table compares the LiteLLM controls available for Ollama access: per-key, per-user and per-team budgets, TPM and RPM limits, temporary budget increases and model-restricted keys. Read each row for the access model it fits and the infrastructure it needs before you rely on it in production.
| Setting | Best fit | What it needs | Watch for |
|---|---|---|---|
| Per-key budget | Service accounts or a single application calling Ollama | PostgreSQL for virtual keys | Spend is tracked per key, so shared keys hide who used the budget |
| Per-user budget | Individual engineers or analysts with their own identity | PostgreSQL and a user to key mapping | Users with several keys need a policy for how spend rolls up |
| Per-team budget | Departments that share a pool of capacity | PostgreSQL and team definitions in the proxy | Confirm how team and organization roles map to your identity provider |
| TPM and RPM limits | Protecting a shared Ollama server from bursts by one caller | PostgreSQL; Redis 7.0 or newer once more than one proxy instance runs | Limits are only shared across instances when Redis is in place |
| Temporary budget increase | A project that needs extra capacity for a fixed window | PostgreSQL and an approval step you run outside the proxy | Record who approved each increase and when it expires |
| Model-restricted keys | Keeping sensitive teams on approved models only | A model list that matches the names routed to your Ollama servers | A key with no model list may reach every model behind the router |
Routing across several Ollama servers
LiteLLM's router can spread requests for one model name across several Ollama deployments. Each deployment is a separate entry with its own api_base, so the router sees every Ollama server as an interchangeable target. The routing strategy decides how each new request picks one of them. The router documentation recommends simple-shuffle as the default, and it is a sound starting point when the servers are similar in size and hold the same models.
- Simple-shuffle (recommended): Picks a deployment at random, weighted by any configured weights. It needs little tuning and suits identical servers.
- Usage-based: Balances on recent token or request volume, which helps when traffic is bursty and one server handles more of it.
- Latency-based: Favors the deployment with the lowest recent response time. Useful when servers differ in GPU capacity, but it can concentrate traffic on one host.
- Least-busy: Sends work to the deployment with the fewest requests in flight, which matches Ollama's per-model parallel slots well.
- Cost-based: Prefers the cheapest deployment when cost differs between hosts, for example between your own hardware and a paid cloud target.
Before you pick one, confirm the strategy names and options against the routing documentation for the LiteLLM version you run.
Routing is only half of resilience. When a server is slow, out of memory or restarting, the gateway needs to retry the request elsewhere and stop sending traffic to a host that keeps failing. LiteLLM provides retries, cooldowns and priority ordering for this. Together they decide whether users see a clean failover or a hard error. Design the order of preference deliberately, because a failover target that is already full will only move the overload around.
- Retries: Resend a failed request to another deployment for the same model name, within the retry count you configure.
- Cooldowns: Remove a deployment from rotation for a period after repeated failures, so one broken host does not absorb every retry.
- Priority failover: Order deployments so a primary server is used first and standby servers take over only when the primary is unavailable or in cooldown.
- Capacity-aware ordering: Put the server with the most spare GPU memory first, and keep standby servers sized for the load they would receive.
- Test the failure path: Stop one Ollama server during a load test and confirm that requests move, that cooldown engages and that the logs show which deployment served each call.
Confirm the retry and cooldown parameter names in the routing documentation for your version before you write them into configuration.
Some applications send a conversation in several requests and benefit when each request reaches the same server. That matters for multi-turn chat, where the model may already hold the context in memory, and it matters when a model is loaded on only one host. Session affinity keeps a user or session pinned to one deployment. It makes load less even, so it is a trade-off to weigh against balance rather than a default to enable everywhere.
- When it helps: Long conversations, models that are loaded on only some servers, and workloads where reloading a model is costly.
- When it hurts: A pinned session keeps sending traffic to a server that has become overloaded or failed, so affinity must work with cooldowns.
- Per-user pinning: Tie affinity to the per-user key or team so that one heavy team cannot fill a single host while others sit idle.
- Model placement: Affinity only works well if the same model name is available on every server in the pool, or if the pool is split by model.
- Check the pool: Confirm with your LiteLLM version how session affinity is configured and whether it respects cooldown state.
The gateway cannot create capacity that an Ollama server does not have. Three Ollama settings define how much work each server accepts. Ollama processes one request per model slot by default, holds a limited number of models in memory and queues a limited number of waiting requests. When one of these limits is reached, requests wait or fail at the server, and the gateway sees that as slow responses or errors. Setting the gateway's limits and the server's limits together is what prevents queues from building silently.
- OLLAMA_NUM_PARALLEL: Sets parallel requests per model. The default is 1, so a busy model serializes requests unless you raise this value and have the memory for it.
- OLLAMA_MAX_LOADED_MODELS: Sets how many models stay loaded at once. The default is 3 times the number of GPUs, or 3 on CPU. Loading a model that does not fit causes unloads and reloads.
- OLLAMA_MAX_QUEUE: Sets how many requests can wait. The default is 512. A large queue hides overload from the gateway for longer.
- Uneven servers: A host with less GPU memory should get lower per-server concurrency, or a smaller share of traffic, so that it does not become the cause of every cooldown.
- Match gateway limits: Set per-deployment rate limits and the router's expectations to the server values, then confirm them under load.
Before you tune anything, confirm these defaults and variable names against the Ollama FAQ for the version you run.
How to set up the gateway, keys and budgets
This sequence puts a LiteLLM gateway in front of one or more private Ollama servers, so each team and user gets a key with its own budgets, limits and usage logs. The result is a tested setup where unauthenticated traffic is rejected and every accepted request is attributable.
Confirm Ollama binds to a private interface
The platform engineer checks the Ollama host before anything else is connected. Ollama binds to 127.0.0.1 on port 11434 by default, and its local API does not require authentication, so the gateway should be the only client that can reach that port over the network. If OLLAMA_HOST has been changed, confirm the bind address is a private interface and that a host firewall allows only the gateway's address to connect. Done when a request to port 11434 from any other machine fails and the gateway can reach it.
Deploy LiteLLM with PostgreSQL and Redis
The platform team deploys the LiteLLM proxy in infrastructure you control. Virtual keys, budgets and spend tracking require a PostgreSQL database, so provision that first. If you run more than one proxy instance, add Redis 7.0 or newer, because shared rate limits, router state and cache depend on it. Confirm the proxy starts, connects to the database and answers its health endpoint before moving on. The LiteLLM production guide also describes sizing per worker, which your team should review against its expected load.
Store the master key in a secret manager
The security or platform engineer generates LITELLM_MASTER_KEY, which must start with sk-, and places it in a secret manager rather than in a configuration file or shell history. The proxy reads it at startup, and only administrators should be able to read it. The master key creates and manages virtual keys, so treat it as the highest-privilege credential in this design. Done when the proxy starts with the key injected from the secret store and the key does not appear in version control or container image layers.
Register ollama_chat models for each server
The platform engineer adds one model entry per Ollama model in the LiteLLM configuration. Each entry uses the ollama_chat provider prefix, which LiteLLM recommends for better responses, and an api_base that points at the private address of the Ollama server that hosts that model. When several Ollama servers serve the same model, list each deployment under one model name so the router can spread requests across them. Confirm the registered model names match what each server reports, then send one test completion through the gateway using the master key.
Choose routing and failover behavior
The platform engineer selects the routing strategy for models that have more than one server. LiteLLM offers simple-shuffle, which its documentation recommends, along with usage-based, latency-based, least-busy and cost-based options, plus retries, cooldowns and priority ordering for failover. Set retry and cooldown values deliberately, because an overloaded Ollama server with a small queue will fail requests quickly. Done when stopping one Ollama server in a test causes requests to reach the remaining server and the gateway logs the failed attempts.
Create team and user keys with budgets
The administrator creates a team and then issues user or team virtual keys. Each key can carry a budget, requests-per-minute and tokens-per-minute limits, and a list of models it may call, so a key for one team cannot reach models assigned to another. Record which budget owner is responsible for each key and who approves increases. Confirm the limits in the admin view, then verify that the key list shows the model restrictions you intended. Budget values should come from your own capacity plan, not from defaults.
Test rejected and accepted requests
The quality or security engineer runs a short test script against the gateway. Requests with no key, an invalid key, a key calling a model it is not assigned, and a key that has exceeded its budget or rate limit should all be rejected. Requests with a valid key for an allowed model should succeed. Also confirm that a direct request to the Ollama port from outside the gateway still fails. Keep the results as evidence for your access review.
Confirm usage logs and spend records
The platform engineer checks that each accepted and rejected request appears in the gateway logs and that spend is recorded against the correct key, user and team. Confirm that spend updates reach PostgreSQL and that the attribution matches the test calls. If you run several instances, check that limits apply across them. Note that batching of spend updates to the database is a scale setting described in LiteLLM's production guidance, so confirm its behavior with your expected volume before relying on near-real-time totals.
Security gaps the gateway must close
Putting LiteLLM in front of Ollama adds keys and budgets, but only if the Ollama port is closed to everyone else. The cards below cover the gaps that remain after the gateway is deployed: direct access to the backend, how the master key is handled, what the free admin UI SSO allows, which audit and access controls sit behind the Enterprise license, and whether cloud features should be switched off.
Block direct access to Ollama
Ollama's local API at port 11434 has no authentication, and by default it binds to 127.0.0.1. Once you set OLLAMA_HOST to reach it from the gateway, any host that can route to that interface can skip LiteLLM entirely and avoid every key and budget. Restrict the Ollama port with firewall rules so that only the LiteLLM host can connect, and test from a second machine that a direct request is refused.
Protect the LiteLLM master key
The master key is the credential that creates and changes every virtual key, so it has to be handled as an administrator secret. LiteLLM's production guidance says it must start with sk- and belong in a secret manager, not in a config file or shell history. Confirm who can read it, how it rotates, and that application teams only ever receive virtual keys they can revoke.
Limit free admin UI SSO
LiteLLM's admin UI supports SSO with Google, Microsoft Entra ID, Okta and generic OIDC providers. From v1.76.0, SSO is free for up to 5 users, and an Enterprise license is required beyond that. Count the people who will administer budgets and keys before you design the login model, and confirm the current limit against the release you deploy.
Admin UI SSO docsPlan for Enterprise-only controls
Audit logs, IP allowlisting, organization and team RBAC, and SCIM sit in the LiteLLM Enterprise license rather than the open source core. If your review requires an access trail for who changed a budget or which key called which model, or requires a source address allowlist for the admin plane, treat that as a licensing decision made before go-live. Ask the vendor to confirm which features your license covers.
LiteLLM Enterprise docsDisable Ollama cloud features
If the deployment is meant to be local-only, the Ollama host should not send prompts to cloud models or web search. Set OLLAMA_NO_CLOUD=1 or the equivalent setting in the server configuration file, then confirm the setting in the server logs. Without this step, a gateway key can still route a request to a model that leaves your infrastructure.
Questions teams ask before adding a LiteLLM gateway
Does adding a LiteLLM gateway in front of Ollama cost money?
Both products are open source, so there is no license fee for the software itself. LiteLLM is dual licensed: content under its enterprise/ directory uses the license in enterprise/LICENSE, and everything else is under the MIT license, according to the BerriAI/litellm repository. The real costs are infrastructure and people. LiteLLM's production guide names PostgreSQL as the primary supported database for virtual keys and budgets, and requires Redis 7.0 or newer once more than one proxy instance runs, for shared rate limits and router state. Those servers recur every month. Staff time is the largest one-time cost: someone must design key scopes, budgets and model routing, then operate the gateway. Ask any quote to separate hosting, database and cache, and build and run labor.
How long does a LiteLLM gateway setup take, and what drives it?
No duration is fixed here, because the timeline depends on the environment. The main drivers are the number of Ollama servers and the model routing across them, how many teams need their own keys and budgets, whether you need SSO into the admin UI, and whether logs must reach an existing monitoring stack. Enterprise features such as SSO beyond the free limit and audit logs add approval steps that can slow delivery. Ask for a written scope with phases and milestones before work starts, and confirm which items depend on your identity provider or database team.
What does the work need from our team?
Expect to provide a named owner for each Ollama server, access to the network segments where the proxy and database will sit, and a decision on who approves keys and budgets. Your identity team should confirm how users sign in, and your security team should review which models each team may call. You will also need a PostgreSQL instance, a Redis 7.0 or newer instance once multiple proxy instances run, and a secret store for the master key, which must start with sk-. Ask the provider to list every input it needs before the first working session.
Can our in-house platform team set this up without a partner?
Yes, if the team has experience running PostgreSQL, a reverse proxy, container or Kubernetes workloads and identity integration. The LiteLLM docs cover virtual keys, routing and the production guide, so the build is well documented. The risk lies in the operating details: rate limits and budgets only hold across instances when shared state is correct, and keys must be scoped so that one team cannot call another team's models. Weigh your team's current capacity against the ongoing upkeep of upgrades, which LiteLLM ships frequently (v1.105.1 was published October 14, 2026).
When do we need the LiteLLM Enterprise license?
Only when a feature in the Enterprise tier is required. The free tier covers virtual keys with per-key, per-user and per-team budgets and rate limits. SSO for the admin UI is free for up to 5 users from v1.76.0, and an Enterprise license is needed beyond that. Audit logs, organization and team RBAC, IP allowlisting, SCIM and secret manager integrations also sit in the Enterprise tier, according to the LiteLLM Enterprise docs. Map each compliance requirement to a feature first, then request a license quote only for those items.
Does the Ollama Enterprise plan replace the need for a gateway?
Not necessarily. Ollama's pricing page lists an Enterprise plan with model access controls, cost budgets per user or API key, a dedicated support channel and custom security options, on top of the Team plan's features. Those controls apply to Ollama's cloud service. A self-hosted Ollama server on your own hardware is unlimited under the pricing page, but its local API does not require authentication. Confirm with Ollama which controls apply to your deployment before deciding whether a gateway is still needed.
How do we know the budgets and key limits actually work?
Test them before users depend on them. Create one test key per team, send requests that exceed the RPM and TPM limits, and confirm the gateway rejects them. Then check spend against a budget and confirm the logs record the key, user and model. Verify that a key scoped to one model cannot reach another. Because spend updates are batched to the database every 60 seconds at scale, expect small delays in budget totals. Ask your provider for a written test plan and a retest after each configuration change.
What to ask for in a written scope
A fixed-scope quote for this work should name every Ollama server in the design, with its hardware location, operating system, the OLLAMA_HOST binding, and the list of models each server will serve. The gateway side needs the same precision: the LiteLLM proxy instances, the PostgreSQL database that virtual keys depend on, and the Redis instance that shared rate limits require once more than one proxy runs. Ask whether the quote covers one gateway in front of several Ollama servers or separate gateways per team, because that choice changes the routing configuration, the failure domains and the number of components to test. Ask also how the identity and key issuance process will work: who approves a new key, whether keys are tied to a user or a team, how a key is restricted to specific models, and whether SSO through an identity provider is in scope or deferred. Confirm whether SSO on the LiteLLM admin UI is included, since the free tier and Enterprise licensing limits are set by LiteLLM, not by DeployOpen.
The budget policy should be written down before build, not discovered during testing. Ask the scope to state which limits are set per user, per key and per team, which of them use TPM or RPM limits, how temporary budget increases are approved and logged, and what happens when a budget is exhausted. Logging retention deserves its own line item: specify where request and spend logs are stored, how long they are kept, who can read them, and how they reach your security team. Ask for the network layout in writing, including which interface the gateway listens on, which hosts can reach the Ollama servers directly, and how firewall rules block any path that bypasses the gateway. Finally, require a test plan for key revocation. The quote should list the revocation steps, the evidence produced (for example, a rejected request after a revoked key is used), and a retest after any change to the gateway. Confirm with the LiteLLM and Ollama release notes which versions the design targets, since both projects ship frequently.
How DeployOpen scopes and delivers LiteLLM gateways for Ollama
DeployOpen plans, builds, documents and supports the LiteLLM gateway that sits in front of your Ollama servers, so each team gets its own keys, budgets and usage logs. Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
How we scope
- Inventory the Ollama servers, models and teams that the gateway must cover before any configuration starts.
- Agree in writing which budgets, TPM and RPM limits, and model restrictions apply per user, team or key.
- Confirm the PostgreSQL and Redis hosting, the identity provider for admin access, and where logs will be retained.
How we build
- Deploy the LiteLLM proxy in your infrastructure with the ollama_chat provider and each Ollama api_base defined.
- Configure routing across several Ollama servers, including retries, cooldowns and failover order, and test each path.
- Test key isolation, budget enforcement and blocked direct access to the Ollama ports before handover.
How we hand over
- Document key issuance, budget changes, model access requests and the rotation of the master key held in your secret manager.
- Provide runbooks for adding an Ollama server, moving a model between hosts and restoring the database.
- Walk your platform and security teams through the usage logs and the evidence they can use in reviews.
How we support
- Offer ongoing support, upgrades and continuous testing as a retainer after the initial handover.
- Plan LiteLLM version upgrades against the release line you choose and retest keys and routing after each change.
- Retest the gateway after changes to models, Ollama versions or network rules, and report findings with fixes.

