LiteLLM with Ollama

Connect Ollama-served models to a self-hosted LiteLLM gateway so team traffic gets virtual keys, budgets and logging. This page covers the routes, remote api_base settings and where Ollama fits.

On this page

How LiteLLM with Ollama routes team traffic to local models

LiteLLM calls Ollama through the ollama/ prefix with an api_base that points at the Ollama host, and ollama_chat is the recommended route when the workload is chat. A team that wants one governed entry point for models it runs itself can register each Ollama-served model in the LiteLLM proxy config, then give developers LiteLLM virtual keys instead of direct access to the Ollama port. Callers keep using the OpenAI request format, and LiteLLM translates the request to Ollama's API.

The split of responsibilities is the core of this design. Keys, budgets, model allow-lists, rate limits and request logs sit in LiteLLM, which needs its PostgreSQL database for virtual keys. Inference stays on Ollama hosts that the client controls, in its own machines or cloud accounts. Ollama states that when it runs locally it does not see your prompts or data, and the local API at localhost:11434 needs no authentication. That means the gateway, not Ollama, is the only place where identity and spend are enforced, so the LiteLLM side must be locked down before any Ollama host is reachable from it.

Before you rely on this pattern, confirm three things in your own environment: which Ollama host each model runs on, whether the route from the gateway to that host is private, and whether Ollama's cloud features are switched off on those hosts with OLLAMA_NO_CLOUD=1 or the server configuration file. Check the exact route names and parameters against the LiteLLM Ollama documentation for the release you deploy, since the gateway's configuration is what your reviewers will read.

What you need before connecting Ollama to LiteLLM

Connecting LiteLLM to Ollama touches three components: the LiteLLM proxy and its state, the Ollama host that serves the models, and the network path between them. Check each one before you write a single model route, because the Ollama side has no built-in authentication.

PostgreSQL for virtual keys

Virtual keys, per-key and per-team budgets, and spend tracking all need a PostgreSQL database behind the LiteLLM proxy. If you plan to issue keys to developers, provision the database before the first route goes live. Confirm the database is in a network zone your security team controls and that it is backed up. Without it, you can still test routes, but you cannot govern access to the Ollama models.

Virtual keys docs

Redis once instances scale out

A single proxy instance can run without Redis. Once you run more than one instance, shared rate limits, router state and cache need a common store, and LiteLLM's production guidance calls for Redis 7.0 or newer. Decide early whether the gateway will run as one instance or several, because adding Redis later changes the deployment layout. Confirm the Redis version your platform team supports before you size the cluster.

Production guide

Ollama host and model storage

Decide which machine runs Ollama and where its models live. Ollama stores models in a default folder per operating system, and the OLLAMA_MODELS variable moves them to another directory. Plan disk space for every model your teams will pull, and size memory and compute for the models you intend to serve concurrently. Ollama's concurrency settings, including OLLAMA_NUM_PARALLEL and OLLAMA_MAX_LOADED_MODELS, determine how many requests the host can handle at once.

Ollama FAQ

Network path to port 11434

Ollama listens on 127.0.0.1 port 11434 by default. Reaching it from a separate LiteLLM host means changing the bind address with OLLAMA_HOST, which exposes the API to any network that can route to it. Allow traffic on port 11434 only from the proxy's subnet or security group, and block it everywhere else. Confirm this with your network team before you set api_base in the LiteLLM configuration.

Controlling unauthenticated access

The local Ollama API at localhost:11434 does not require authentication. Anyone who can reach that port can run inference and list models without a LiteLLM key. Treat the Ollama port as an internal service, and make LiteLLM the only client allowed to reach it. Place a reverse proxy with its own access controls in front of Ollama if you must expose it beyond one host, and confirm that approach with your security team before go-live.

Ollama API authentication

Master key and secret storage

The LiteLLM master key, which must start with sk-, grants administrative control over keys, budgets and routes. Store it in a secret manager rather than in a configuration file or shell history. Because Ollama itself holds no credential in local mode, the master key and database credentials are the main secrets in this setup. Confirm who holds administrative access to the proxy before you issue the first team key.

Production guide

Configuring the ollama and ollama_chat routes step by step

This sequence takes an Ollama host from a pinned install to a LiteLLM gateway that serves a team through a restricted virtual key, with a budget confirmed to block overspend before anyone relies on it. Each step ends with a check so the platform owner knows the layer below works before the next one is added.

  1. Install and pin the Ollama version

    The platform engineer installs Ollama on the host that will serve models, using the package or container method your change process approves, and records the exact version string. Ollama ships frequent releases, so pinning avoids silent behavior changes between the test host and the shared host. Check the version against the Ollama GitHub releases page before you pin it, and confirm the install runs as a service that restarts after a reboot. Done means ollama --version returns the pinned value on every host that will serve traffic.

  2. Pull the models the team will use

    The engineer pulls each model the gateway will expose with ollama pull and runs a short local prompt against it to confirm it loads. Models are stored in the default directory for the operating system unless OLLAMA_MODELS points elsewhere, so set that variable first if the model volume is a separate disk. Record the model names and tags exactly, because the LiteLLM model entries must match them. Done means ollama list shows every planned model and each one answers a local prompt.

  3. Set OLLAMA_HOST only as far as the proxy needs

    By default Ollama binds to 127.0.0.1 on port 11434, which works when LiteLLM runs on the same host. If the proxy runs elsewhere, set OLLAMA_HOST to the narrowest interface that the proxy can reach, and restrict the port with host or network firewall rules rather than opening it to every interface. Ollama's local API does not require authentication, so network reachability is the only control at this layer. Done means the proxy host can reach the Ollama port and an unrelated network segment cannot.

  4. Add model entries with ollama/ and ollama_chat

    The engineer adds one entry per model to the LiteLLM proxy configuration, using the ollama/ prefix or the ollama_chat/ prefix with the model tag, and sets api_base to the Ollama address reachable from the proxy, such as the local default for a same-host install. LiteLLM recommends ollama_chat for better chat responses, so use it for chat workloads and keep the choice consistent per model. Store the configuration as code and reload the proxy. Done means the proxy starts without configuration errors and lists each model name.

  5. Test a direct call through the proxy

    Before any key exists, the engineer sends one chat request to the proxy's OpenAI-format endpoint using the master key and each configured model name. This separates routing faults from authorization faults. If a call fails, check the api_base value, the Ollama port reachability and the model tag spelling in that order. Done means every configured model returns a completion and the proxy log records the request against the expected model route.

  6. Issue a virtual key restricted to those models

    The platform owner creates a virtual key that lists only the Ollama models approved for the team, and optionally sets a per-key budget and rate limits. Virtual keys require a PostgreSQL database, so confirm that database is in place before this step. Keep the master key in a secret manager and out of developer hands. Done means a request with the new key succeeds for an approved model and is rejected for a model outside the key's list.

  7. Confirm a budget blocks overspend

    The owner sets a deliberately low test budget on the key, sends requests until the spend limit is reached, and confirms the proxy refuses further calls with a budget error. Use a low limit so the check finishes quickly, then raise it to the approved value. Note that local Ollama models have no provider charge, so the budget tests the gateway's accounting rather than a bill, and cost figures for local models depend on the pricing configured in LiteLLM. Done means the key is blocked at the limit, the block appears in the logs, and the approved budget is restored.

How a request moves from a team client to an Ollama host

The request starts at a team client that calls the LiteLLM proxy with a virtual key. The proxy checks that key against its PostgreSQL store for budgets and model access, and uses Redis for shared rate limits when more than one proxy instance runs. Only then does the proxy forward the call to the Ollama host on port 11434, which accepts requests without authentication. Check that the Ollama port is reachable only from the proxy, and that nothing outside the trust boundary can reach it directly.

Authentication happens at the proxy, while the Ollama API on port 11434 is unauthenticated.

When Ollama fits development versus shared production use

A single developer running Ollama on a laptop is the case Ollama is built for. The model runs on the machine, the local API at localhost:11434 needs no authentication, and Ollama states that when it runs locally it does not see your prompts or data. LiteLLM can sit in front of that local instance so the developer's code uses the same OpenAI-format calls it will use later, with the ollama_chat/ route and an api_base pointing at localhost.

  • Default concurrency: OLLAMA_NUM_PARALLEL defaults to 1, so one developer's requests are served one at a time per model.
  • No shared keys: the local API needs no key, so there is nothing to rotate, but also nothing to govern.
  • Model storage: models sit in the user's home directory unless OLLAMA_MODELS moves them.
  • Cloud features: set OLLAMA_NO_CLOUD=1 if the laptop should never reach cloud inference.
  • Limits of this tab: budgets, logs and per-person access do not apply to a laptop setup.

Before relying on a laptop setup for anything beyond prototyping, confirm that the model size fits the machine's memory and that developers understand the setup is not a shared service.

Mapping Ollama models, keys and teams in LiteLLM

This table maps each element of an Ollama route in LiteLLM to the setting that controls it, the owner who should approve it, and what to confirm in your own config. Read it as a checklist you complete per model before any team receives a key. The main takeaway is that LiteLLM enforces access and spend, while Ollama only sees the gateway's connection.

ElementWhere it is setWho owns itWhat to confirm
Model name for callersmodel_name in the LiteLLM config (the alias your teams call)Platform teamAlias is unique, stable and documented for callers
Upstream Ollama modellitellm_params model value using the ollama/ or ollama_chat/ prefixPlatform team with the model ownerExact tag matches a model pulled on the Ollama host
Route prefixollama/ for generate calls, ollama_chat/ for chat responsesPlatform teamChat-style clients use ollama_chat/ as LiteLLM recommends
Remote host addressapi_base pointing to the Ollama server, such as an internal address on port 11434Infrastructure teamGateway can reach the host, and the Ollama port is not exposed to other networks
Allowed team or keyVirtual key restricted to specific model names, assigned to a teamTeam lead or application ownerEach key lists only the aliases that team needs
Budget ownerPer-key, per-user or per-team budget in LiteLLMCost center or FinOps ownerBudget is set in LiteLLM, because Ollama has no spend limits of its own
Ollama identityNone: local Ollama API does not authenticate callersSecurity teamOnly the gateway should reach the Ollama port, and callers should never reach it directly
Shared Ollama capacityOLLAMA_NUM_PARALLEL and OLLAMA_MAX_QUEUE on the Ollama hostInfrastructure teamConcurrency limits suit the number of teams sharing each model

Securing the Ollama backend behind LiteLLM

LiteLLM is the only component your developers should reach, so the controls that matter sit between the gateway and the Ollama runtime and around the gateway's own master key. Each card covers one control you can verify before Ollama serves shared traffic. Check them in order: network exposure first, then secrets, then data handling.

Bind Ollama to a private interface

Ollama listens on 127.0.0.1 port 11434 by default, which works when LiteLLM runs on the same host. When LiteLLM runs on another machine, set the OLLAMA_HOST variable so Ollama listens on a private network interface only. Confirm with a connection test from the gateway subnet and a failed test from outside it. The local Ollama API does not require authentication, so anyone who can reach that port can call your models.

Ollama FAQ

Front Ollama with a reverse proxy

If Ollama must be reached across network segments, place a reverse proxy such as Nginx in front of it. The proxy can restrict source addresses, terminate TLS and log requests. Keep Ollama itself bound to a private address so the proxy is the only path in. Test that direct connections to the Ollama port fail once the proxy is in place, because a proxy that sits beside an open port protects nothing.

Store the LiteLLM master key in a secret manager

LITELLM_MASTER_KEY must start with sk- and grants administrative control of the gateway, including key creation and budget changes. Keep it out of configuration files and container images. Load it at runtime from a secret manager your platform team already operates, and rotate it on a schedule you define. Ollama itself has no key on local calls, so this master key is the credential that most needs protection.

Disable cloud features for local-only data

Ollama states that when it runs locally it does not see your prompts or data. Set OLLAMA_NO_CLOUD=1 in the server environment or the server configuration file when your policy requires that cloud features stay off. Confirm after restart that no cloud model calls succeed. This setting governs the Ollama runtime, so verify it on every host that serves traffic, not only the first one you deploy.

Keep direct ollama.com keys off the gateway

Direct cloud inference at ollama.com/api and ollama.com/v1 requires an API key sent as a Bearer token. Adding that key to LiteLLM sends prompts from your gateway to a third party and bypasses the local-only path. Use the cloud route only as a deliberate decision with a named owner, a documented data flow and a separate key. Otherwise, confirm that no ollama.com credential exists in the gateway configuration.

Ollama API authentication

Why budgets ignore Ollama cost but still need limits

Running models on your own hardware carries no per-token bill from a model vendor, so a LiteLLM budget on an Ollama route does not track provider spend. Ollama's pricing page states that running models on your own hardware is always unlimited, and the cost you actually carry is the GPU, CPU, memory and power of the host. A budget on an ollama/ or ollama_chat/ route therefore works as an internal allocation: it caps how much of a team's share of a shared machine that team can consume, and it should be set with the platform owner who funds that hardware. Confirm with finance how the host is charged back, whether to a cost center, a platform budget or a per-team share, before you attach a dollar figure to any key.

The controls that protect shared hardware are the request limits, not the dollar budget. LiteLLM virtual keys support TPM and RPM limits per key, user or team, and these cap tokens and requests per minute before one caller can saturate a model that every team shares. Pair them with Ollama's own limits, which are set on the server: OLLAMA_NUM_PARALLEL defaults to 1 parallel request per model, OLLAMA_MAX_LOADED_MODELS and OLLAMA_MAX_QUEUE (default 512 queued requests) govern how much work waits behind the GPU. Set the LiteLLM TPM and RPM values so that the sum across teams stays inside what the host can serve at acceptable latency, and test that ceiling with your own models rather than copying a number.

Temporary budget increases give you a controlled way to let a team run a heavy job, such as a batch evaluation, without raising its standing allocation. Use them with an expiry and a named approver, and record why the increase was granted, because on your own hardware the real cost is contention with other teams. Ask your platform team to confirm three things in your environment: which hardware and power costs are chargeable, how usage in LiteLLM maps to the team that owns the hardware allocation, and who approves a temporary increase. The LiteLLM virtual keys documentation describes the budget and limit fields to configure for each key.

Common Ollama connection and routing failures in LiteLLM

This table lists the failures teams most often hit when LiteLLM calls Ollama, with the likely cause and the fix for each. Read it when a request fails or returns poor output, and check the causes in order from network to route to key settings.

FailureLikely causeFix
Connection refused on api_baseOllama is not running on the host, or it binds to 127.0.0.1 so a remote LiteLLM container or pod cannot reach itConfirm the Ollama service is up on the host. Set OLLAMA_HOST so it listens on an address the gateway can reach, and point api_base at that address on port 11434
Model not found on the hostThe model named in the LiteLLM config has not been pulled on the Ollama server, or the name or tag differs from what is pulledPull the exact model and tag on the Ollama host, then match the model name after the ollama/ prefix to the local name
Requests queue or time outConcurrency limits are reached: OLLAMA_NUM_PARALLEL defaults to 1 per model and OLLAMA_MAX_QUEUE defaults to 512 queued requestsSet OLLAMA_NUM_PARALLEL and OLLAMA_MAX_LOADED_MODELS to match hardware, add LiteLLM rate limits per key or team, and route overflow to a second Ollama host or another provider
Poor chat output or broken tool repliesThe ollama/ route is used for a chat workload where ollama_chat is the better fitChange the model to the ollama_chat/ prefix for chat completions, then rerun the same prompts to compare output
Key denied for a modelThe virtual key's allowed model list does not include the Ollama model name, or the name in the request differs from the config aliasAdd the exact model alias to the key or team allowed list, and check that callers send the alias defined in the LiteLLM config
Unexpected cloud calls or auth errorsA request reaches ollama.com instead of the local host, or a cloud API key is sent to a local endpointCheck api_base for each model entry, keep local models pointed at the local server, and turn off cloud features with OLLAMA_NO_CLOUD=1 where policy requires it
Budget shows spend on local modelsLocal Ollama inference has no provider bill, so budgets or cost maps may not reflect real hardware costConfirm how the cost map treats the model, and set cost fields in the config so budget reports match your chargeback policy

Questions buyers ask about LiteLLM with Ollama

How much effort does it take to route Ollama models through LiteLLM?

Connecting one Ollama host to a LiteLLM proxy is a small configuration change, but the effort grows with the number of hosts, models, teams and controls around it. The main work is deciding where Ollama runs, adding the ollama/ or ollama_chat/ model entries with the right api_base, then setting up virtual keys, budgets and logging so the route is governed. Effort also rises with network exposure, since Ollama has no built-in authentication on its local API and must be fronted by something that enforces access. Ask any partner for a written scope that lists each host, model, team and control, because the quote follows from that list.

Can our team set up LiteLLM with Ollama without outside help?

A team with working knowledge of Linux, containers, reverse proxies and LiteLLM configuration can build a development setup alone. Shared use is harder: it needs a PostgreSQL database for virtual keys and spend, a Redis instance once more than one proxy runs, an authenticated path in front of Ollama, secret handling for LITELLM_MASTER_KEY, and tested backups. Check whether your team has owners for each of these, who will review the design, and who will handle upgrades. DeployOpen implements, hardens and documents these pieces inside your infrastructure, and most engagements are fixed-scope with the scope agreed in writing before work starts.

What do we need to provide before the work starts?

You need to provide the environment and the decisions. Typical inputs are the hosts where Ollama will run (CPU or GPU, operating system, storage for models), the network zones that can reach them, the identity provider your staff use, the list of models and the teams who will use them, and the budget and rate limit policy you want enforced. You also need named owners for the PostgreSQL database, the secret manager and the reverse proxy. Confirm with your security team which data classes may reach these models, because that decision determines the logging, retention and access controls the design needs.

What drives the time needed for a LiteLLM and Ollama project?

Duration depends on the number of Ollama hosts, how many model routes you need, whether you run more than one LiteLLM proxy instance, and how far the access model goes. Time also depends on your change process, environment approvals and how quickly your team can review the configuration. Hardware lead times can dominate if GPUs must be ordered. Ask for a schedule tied to milestones such as environment access, first working route, key and budget test, and handover, rather than a single overall estimate.

Is Ollama suitable for production use with LiteLLM?

Ollama fits development, evaluation and small internal use well, and it is also the simplest way to run models on hardware you control. For shared production use, check its concurrency limits before you commit: by default OLLAMA_NUM_PARALLEL is 1 parallel request per model, OLLAMA_MAX_LOADED_MODELS defaults to 3 times the number of GPUs (or 3 on CPU), and OLLAMA_MAX_QUEUE defaults to 512 queued requests. Load tests against your expected traffic will show whether these settings hold. Also confirm that the local API is placed behind authentication, that OLLAMA_NO_CLOUD=1 is set where cloud features are not wanted, and that upgrades follow a tested process, since Ollama releases frequently.

What do hosted Ollama cloud plans cost, and what is the difference from self-hosting?

Running models on your own hardware is listed as unlimited on Ollama's pricing page, so the cost of a self-hosted route is hardware, power, storage, operations time and any outside services you buy. The pricing page lists paid plans for cloud models: Pro at $20 per month ($200 per year), Max at $100 per month, Team at $500 per month and Enterprise at custom pricing. Confirm current prices on the Ollama pricing page before you budget, because plans change. Decide early which models must stay on your hardware, since direct cloud inference requires an API key sent as a Bearer token.

What does LiteLLM Enterprise add for SSO and support?

LiteLLM's admin UI supports SSO with Google, Microsoft Entra ID, Okta and generic OIDC providers, and from v1.76.0 SSO is free for up to 5 users. Beyond that limit an Enterprise license is needed, which also adds SCIM, JWT authentication, audit logs, organization and team RBAC, IP allowlisting and secret manager integrations. Enterprise support includes a dedicated channel with the engineering team and optional 24/7 SLAs, with a 1 hour response for critical issues and 72 hours for security patches, per the LiteLLM Enterprise documentation. Confirm current terms with LiteLLM before you buy, and note that Ollama's own Enterprise plan is a separate product with its own features.

What DeployOpen scopes before connecting Ollama

The written scope comes before any configuration change, and it fixes the hosts, models, teams and keys that the work covers. For an Ollama integration, the first decisions are which Ollama hosts will serve traffic, which models each host must run, and which teams and keys may reach each model. Each Ollama host is a separate inference endpoint with its own OLLAMA_HOST binding, model directory and concurrency settings, so the scope should list every host by name, the models it serves, and the LiteLLM model names that point at it. Anything not listed stays out of the routing configuration.

The network and access decisions carry most of the risk. The local Ollama API at port 11434 has no authentication, and by default Ollama binds to 127.0.0.1, so a remote host only becomes reachable when someone changes the bind address and places a proxy in front of it. The scope should state which network path the LiteLLM proxy uses to reach each api_base, who can reach the Ollama port, whether OLLAMA_NO_CLOUD=1 is set on hosts that must stay local, and whether any host is allowed to call direct cloud inference, which requires an API key. Confirm these choices with your network and security teams before the work starts, not after the first connection fails.

The deliverable is the test evidence that proves the scope was met. Expect the record to show the LiteLLM model entries, a request that succeeds through the ollama_chat route for each model, a key that is denied a model outside its allowed list, a budget that stops a key once it is exhausted, and the logs that show the request reached the expected host. Most engagements are fixed-scope, so DeployOpen agrees the scope, deliverables and timeline in writing before work starts, and the quote follows from that written scope. Ask any provider for the same written scope so that you can compare quotes on the same items.

How DeployOpen works on this

DeployOpen plans, builds, documents and supports the connection between a self-hosted LiteLLM gateway and Ollama models in infrastructure you control. We start from which teams use which models, where each Ollama host runs and what the gateway must govern before any route goes live.

How we scope

  • We confirm which Ollama hosts, models and API base addresses the gateway will reach, and whether each host is for development or shared use.
  • We agree in writing which teams receive keys, which budgets and TPM or RPM limits apply, and which models each key may call.
  • We record network paths between the gateway and each Ollama host, including whether traffic crosses a proxy such as Nginx, before the build starts.

How we build

  • We configure the ollama/ and ollama_chat/ routes in the LiteLLM config and test each model with a real request from the gateway.
  • We set api_base for remote Ollama hosts and confirm that OLLAMA_HOST binds only to the addresses the design allows.
  • We pair Ollama routes with virtual keys and budgets in PostgreSQL, then test that restricted keys are refused for models they should not reach.

How we hand over

  • We document the model inventory, route definitions, key and budget assignments, and the Ollama concurrency settings the team chose.
  • We provide a runbook covering how to add a model, rotate keys, move the model directory with OLLAMA_MODELS and disable cloud features.
  • We walk your platform and security teams through the configuration so they can review it and operate it after handover.

How we support

  • Ongoing support, upgrades of LiteLLM and Ollama, and continuous testing are available as retainers, with scope agreed in writing.
  • We plan upgrades against the LiteLLM supported release lines and the Ollama release notes before changing a running gateway.
  • We retest routes, keys and budgets after each upgrade or change to an Ollama host so governance controls keep working.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.