Run a Local AI Gateway for Multiple Models

One address for several models: Ollama's multi-model server, llama.cpp's router mode, a LiteLLM proxy and Open WebUI's model router compared.

Most local AI setups end up with one model server on one address, and every additional model you want to try means another port, another base URL and another round of reconfiguring whatever app you use. The choice of runtime is covered in Best Local LLM Runners, and the API plumbing in How to Call a Local LLM API from Your App. A gateway removes that work: your apps talk to one address, models get names, and something decides which model answers each request. There is no single product called a local AI gateway. Four separate mechanisms solve the same problem at different layers, and they differ in what they cost you to run.

Ollama already keeps more than one model in memory

The simplest version needs no new software. The Ollama FAQ documents that “multiple models can be loaded at the same time” when memory allows, with OLLAMA_MAX_LOADED_MODELS defaulting to “3 * the number of GPUs or 3 for CPU inference” and OLLAMA_NUM_PARALLEL setting how many requests one loaded model serves at once. For GPU inference the docs add a hard condition: “new models must be able to completely fit in VRAM to allow concurrent model loads”. If a new model does not fit, requests queue until it can load and idle models are unloaded to make room.

Two more defaults matter when several models share the machine. OLLAMA_MAX_QUEUE defaults to 512, past which the server “responds with a 503 overloaded error”. And a model stays resident for “5 minutes before being unloaded” by default, which is why ollama ps is the command worth memorising: it shows what is loaded and whether the processor column reads “100% GPU”, “100% CPU” or a split.

What Ollama does not do is route. The client still names the model, and Ollama serves that name. Swapping between a fast model and a large one is the client’s problem, which is exactly what the next three options take off it.

llama.cpp’s server has a router mode

The llama.cpp server documentation describes a router that serves several models from one process. Model files come from three sources: the Hugging Face cache controlled by LLAMA_CACHE, a directory passed with --models-dir, or an INI preset file passed with --models-preset. By default the router looks in the cache, and the README warns: “The server must be restarted after adding a new model.”

Four flags set the behaviour. --models-max N is “for router server, maximum number of models to load simultaneously (default: 4, 0 = unlimited)”. --models-memory-margin N keeps a set amount of “device memory to keep free per device, unload LRU models until a new one fits (default: 0, 0 = disabled)”. --models-autoload decides whether models load automatically and is enabled by default. And the router speaks the OpenAI-compatible paths /v1/chat/completions, /v1/completions, /v1/embeddings, /v1/models and /v1/health, plus an Anthropic-compatible /v1/messages.

The defaults are conservative and worth noting before you open a port: --host listens on 127.0.0.1, --port is 9931, and --api-key defaults to none.

A proxy in front: LiteLLM

LiteLLM is the mature answer if the gateway has to sit in front of several servers rather than inside one. The repository’s LICENSE file is headed “Portions of this software are licensed as follows:”, carves the litellm/enterprise/ directory out to its own licence, and puts everything else under the MIT licence, “Copyright (c) 2023 Berri AI”. The GitHub API reported 64,363 stars and 13,750 forks when this page was written.

The quick start installs it with pip install 'litellm[proxy]' and starts it with litellm --model <provider>/<model>, listening on port 4000 on all interfaces by default. The config reference is where the real work happens. model_list holds the models, model_name is the alias clients send, and litellm_params carries the real target, for example model: ollama/<ollama-model-name> for a local server. Several entries sharing one model_name become load-balanced deployments of the same alias, and general_settings.master_key can require every request to carry a key.

Routing is where a gateway earns its keep. The load balancing guide lists the strategies: simple-shuffle, described as “Randomly distributes requests” and the default, plus least-busy (“Routes to deployment with fewest active requests”), usage-based-routing (“Routes to deployment with lowest current usage (RPM/TPM)”), latency-based-routing (“Routes to fastest responding deployment”) and cost-based-routing (“Routes to deployment with lowest cost”). Fallbacks are a separate line, documented in the config reference: litellm_settings.fallbacks sends traffic to a secondary model after retries fail, and context_window_fallbacks provides an alternative when the context limit is exceeded.

Let the chat UI decide: Open WebUI model routers

Open WebUI does the routing in the interface itself, and the GitHub API reported 160,082 stars for the repository. Its router models documentation describes an administrator opening “Settings > Models”, selecting “Router Models” and adding a router. The router appears in the model picker and forwards each message to one of the real models behind it.

Rules are checked in order. Patterns match with regular expressions. The docs describe them as “Regular expressions (not case-sensitive) checked against the conversation. The first pattern that matches wins”, and note that no Decisions API call is made. Conditions are natural-language rules scored by a Decisions API, and the most likely condition wins if it reaches its threshold. Default models catch everything else, with “First” and “Random” as the documented default-model strategies. The whole configuration can also be supplied as a JSON list through the ROUTER_MODELS environment variable.

Separately, Open WebUI can talk to several Ollama instances at once. Its Ollama connection guide puts them under “Manage Ollama API Connections” in “Settings > Connections”, with an optional “Prefix ID” that produces model IDs such as remote.llama3. Two details are easy to miss: Open WebUI “picks one of the servers that has the model at random for every request, so messages in the same chat can go to different servers”, and the parameter size, quantization and file size shown in the model selector “come from the first connection in the list that has the model”.

What each approach gives you

ApproachWhere it runsModels it can serveHow it routesThe catch
Ollama multi-modelInside the Ollama serverEvery tag you have pulled, OLLAMA_MAX_LOADED_MODELS defaults to 3 per GPU or 3 on CPUThe client names the model, no rulesGPU models must fit entirely in VRAM to load together, and the queue returns a 503 past 512 waiting requests
llama.cpp routerInside llama-serverGGUFs from the HF cache, --models-dir or --models-presetLoads on demand, --models-max defaults to 4, 0 means unlimitedThe server needs a restart when a model is added, and --api-key defaults to none
LiteLLM proxySeparate process, port 4000Anything in model_list, local or hostedsimple-shuffle, least-busy, usage-based-routing, latency-based-routing, cost-based-routing, plus fallbacksAnother service to install, secure and keep updated
Open WebUI routersInside the chat UIAny model already connectedRegex patterns, Decisions API conditions, First or Random defaultsSelection among identical model IDs is random, so one chat can hop servers

The catch in every gateway

Two things are worth stating plainly. First, a fallback is a privacy decision. LiteLLM’s fallbacks list can point a failed request at a hosted model, which means the prompt leaves the machine, and the same applies to an Open WebUI router whose default model is a cloud connection. Keeping every fallback on localhost keeps the traffic local. If a hosted fallback is the plan, the arithmetic in When Local AI Beats the API: The Cost Crossover is the part to work through first.

Second, the licences are not the same. LiteLLM is MIT outside its enterprise/ directory, while Open WebUI ships a custom “Open WebUI License” that, according to the LICENSE file, prohibits altering or removing Open WebUI branding except in defined cases, including deployments “where the total number of end users … does not exceed fifty (50) within any rolling thirty (30) day period”, specific prior written permission from the copyright holder, and deployments under an executed enterprise licence. Self-hosting for a family or a small team is inside that exception, which is not the same as permission to rebrand it.

Bottom line

Start with what you already have. Ollama already loads several models at once and needs no extra service, so if the only problem is switching models in one app, that is the cheapest fix. Add llama.cpp’s router mode when you want several GGUFs served from one port with an OpenAI-compatible API. Reach for LiteLLM when the gateway has to front more than one server, route by load, latency or cost, and fall back cleanly. Keep the routing rules in Open WebUI when the decision is about the content of the message, such as sending sensitive material to a local model and everything else to a faster hosted one.

Whichever route you take, the pieces are the same: one base URL for your apps, stable names for your models, and rules that say which model handles which request.

Other GPUs and tasks: Local AI by VRAM · RSS