Skip to content

llama-swap Guide: Hot-Swap Local Models Behind One OpenAI Endpoint

6–9 minutes
Excited woman with a messy bun in a cobalt blue shirt on a neon city street at night holding a card reading LLAMA-SWAP, with the text Swap Models One Endpoint

If you run local models with llama-server or vLLM, you’ve probably hit the same problem: each model needs its own server, and your apps can only talk to one at a time. llama-swap fixes that.

It’s a small proxy that sits in front of your model servers and gives your apps one OpenAI-compatible address. When a request asks for a model, llama-swap starts the right server, stops the old one if needed, and passes the request through.

This guide shows how to install llama-swap, write a working config.yaml, connect apps like Open WebUI, run several models at once with groups, use Docker, and fix common errors. It follows the official llama-swap README and example config as of November 2026.

TL;DR

  • What: a free, MIT-licensed Go proxy that hot-swaps local models behind one OpenAI-compatible endpoint.
  • Install: brew tap mostlygeek/llama-swap && brew install llama-swap, a release binary, or Docker.
  • Run: llama-swap --config config.yaml --listen localhost:8080 (default port 8080).
  • Config: one entry per model with a cmd that uses ${PORT}.
  • Web UI: http://localhost:8080/ui shows models, logs and running servers.
  • Works with: llama-server, vLLM and any OpenAI-compatible server.

What llama-swap Does

  • One address for all models: apps send requests to llama-swap, not to each model server.
  • Automatic swapping: it reads the model field in each request and starts the matching server.
  • Any backend: llama.cpp’s llama-server, vLLM or any server with an OpenAI or Anthropic style API.
  • No dependencies: a single Go binary for Linux, macOS, Windows and FreeBSD.
  • Auto-unload: optional timeouts free your VRAM when a model sits idle.

It’s the missing piece if you like llama.cpp’s speed and control but want Ollama-style model switching. New to llama-server? Start with our llama-server guide.

Install llama-swap

Method Command or source
Homebrew (macOS and Linux, official) brew tap mostlygeek/llama-swap && brew install llama-swap
Release binary Download from the GitHub releases page (Linux, Mac, Windows, FreeBSD)
WinGet (community) winget install llama-swap
MacPorts (community) sudo port install llama-swap
Docker ghcr.io/mostlygeek/llama-swap
From source Go plus Node.js, then make

Releases use plain numbers such as v267 rather than version names, and new ones arrive often. You also need llama-server (or another backend) installed separately, unless you use the unified Docker images.

Write Your First config.yaml

The smallest working config from the README looks like this:

models:
  model1:
    cmd: llama-server --port ${PORT} --model /path/to/model.gguf

Here’s a more practical version with two models and an idle timeout:

healthCheckTimeout: 300

models:
  qwen-8b:
    cmd: llama-server --port ${PORT} -m /models/qwen3-8b-Q4_K_M.gguf -ngl 99 -c 16384
    ttl: 600
    aliases:
      - chat
  coder:
    cmd: llama-server --port ${PORT} -m /models/qwen3-coder-Q4_K_M.gguf -ngl 99 -c 32768
    ttl: 600
  1. Give each model a name. That name is what apps put in the model field.
  2. Use ${PORT} in every cmd. llama-swap hands out a free port, starting at 5800 by default.
  3. Add ttl (seconds) so idle models unload automatically.
  4. Add aliases if apps expect a different name, like “chat” or “gpt-4o-mini”.
  5. Raise healthCheckTimeout for big models that take a while to load (default 120 seconds).

Need GGUF files? See how to download models from Hugging Face.

Run It and Test the Endpoint

  1. Start llama-swap:
    llama-swap --config config.yaml --listen localhost:8080
  2. List models:
    curl http://localhost:8080/v1/models
  3. Send a chat request (this loads qwen-8b on first use):
    curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"qwen-8b","messages":[{"role":"user","content":"Hi"}]}'
  4. Ask for the other model. Change "model" to "coder" and llama-swap swaps servers for you.
  5. Open the web UI at http://localhost:8080/ui to watch it happen.

Add --watch-config to reload automatically when you edit the file (off by default for the binary). Use --validate to check a config without starting anything.

Useful Config Options

Key Level What it does
cmd Model Command that starts the server (required)
proxy Model Where to forward requests (default http://localhost:${PORT})
checkEndpoint Model Health check path (default /health)
ttl Model Idle seconds before unloading
aliases Model Extra names for the same model
env Model Environment variables, e.g. CUDA_VISIBLE_DEVICES=1
cmdStop Model Custom stop command, e.g. docker stop ${MODEL_ID}
unlisted Model Hide from /v1/models
healthCheckTimeout Global Seconds to wait for a model to be ready (default 120)
startPort Global First port handed out by ${PORT} (default 5800)
globalTTL Global Default idle timeout (0 = never)
macros Global Reusable snippets, including ${env.VAR}
apiKeys Global Require keys from clients

Macros keep long configs tidy: define your llama-server path and common flags once, then reuse them in every model.

Run Several Models at Once (Groups)

By default, llama-swap runs one model at a time. Groups let you keep some models loaded together, for example a small embedding model next to your chat model.

  • members: the models in the group.
  • swap: whether members replace each other or run side by side.
  • exclusive: whether loading this group unloads other groups.
  • persistent: keep the group running when other groups load.

In the current example config, groups live under routing.router.settings.groups. Check the config.example.yaml in the repo for the exact layout of your version, since this area has changed recently. With two GPUs, use env to pin each member to its own card. Picking hardware? See the best GPU for local LLMs.

Run llama-swap in Docker

Image tag For
unified-cuda13 NVIDIA Turing to Blackwell (CUDA 13), amd64 and arm64
unified-cuda NVIDIA Pascal to Ada (CUDA 12), amd64
unified-vulkan AMD and other Vulkan GPUs
cpu, intel, musa Older single-backend images
docker run -it --rm --runtime nvidia -p 9292:8080 \
  -v /path/to/models:/models \
  -v /path/to/config.yaml:/app/config.yaml \
  ghcr.io/mostlygeek/llama-swap:unified-cuda13

The unified images bundle the backends and turn on config watching. They also read LLAMA_SWAP_* environment variables, such as LLAMA_SWAP_LISTEN=0.0.0.0:8080. Check the README for the exact config path inside the container for your tag. Already running Ollama in containers? Our Ollama Docker guide covers GPU setup.

Connect Open WebUI and Other Apps

  1. Find the base URL: http://localhost:8080/v1 (or your Docker port).
  2. In Open WebUI, add an OpenAI-compatible connection with that URL. Use any API key text unless you set apiKeys.
  3. Pick a model from the list. Each config entry appears by name.
  4. In code, point the OpenAI SDK at the same base URL and set model to a config name.

Setting up Open WebUI first? See our Open WebUI setup guide. Coding agents that accept an OpenAI endpoint work the same way.

Endpoints and the Web UI

Endpoint Purpose
/ui Web interface: models, logs, running servers
/v1/models List configured models
/v1/chat/completions, /v1/completions, /v1/embeddings OpenAI-style inference
/v1/messages Anthropic-style inference
/running Which models are loaded
POST /api/models/unload Unload all models (or add /:model_id for one)
/logs, /logs/stream Proxy and upstream logs
/health, /metrics Health and metrics

Example: Chat, Coding and Embeddings on One GPU

A common home setup is one GPU shared by a chat model, a coding model and a small embedding model for RAG.

  1. Add three entries to config.yaml: a chat model, a coder model and an embedding model, each with its own llama-server command.
  2. Let chat and coder swap, since both are large and only one fits in VRAM at a time.
  3. Keep the embedding model loaded alongside them with a non-swapping group, because it’s small.
  4. Point Open WebUI at llama-swap for chat and embeddings, and your coding agent at the same URL with the coder model name.

Now each app just asks for the model it needs, and llama-swap handles the loading in the background.

Troubleshooting

Problem Likely cause Fix
Model times out while loading Big model, slow disk Raise healthCheckTimeout
“Connection refused” in Docker Listening on localhost inside the container Set LLAMA_SWAP_LISTEN=0.0.0.0:8080
Upstream never becomes healthy Missing ${PORT} in cmd Make every cmd use --port ${PORT}
Model not found Name doesn’t match config Use the exact config name or add an alias
Out of VRAM when switching Two models in a non-swapping group Enable swap in the group or lower context size
Config edits ignored Watching is off Restart, or start with --watch-config
llama-server crashes Bad flags or model path Check /logs or the UI for the upstream error

Memory errors on load? See our CUDA out of memory fix and how much RAM you need for local AI.

FAQ

What is llama-swap?

A free proxy that gives local model servers one OpenAI-compatible address and starts or stops each server when a request asks for its model.

What port does llama-swap use?

8080 by default. Change it with –listen.

Does llama-swap work with vLLM?

Yes. Any OpenAI-compatible server works as an upstream, including vLLM in Docker.

Can llama-swap run two models at once?

Yes, with groups. Members of a non-swapping group stay loaded together.

Is llama-swap better than Ollama?

It’s different. Ollama is simpler. llama-swap gives you llama.cpp’s full flags and the newest builds while keeping easy model switching.

How do I unload all models?

Send POST /api/models/unload, use the web UI, or set ttl so idle models unload.

Does llama-swap run on Windows?

Yes. There’s a Windows release binary, and WinGet has a community package.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Excited woman with a messy bun in a cobalt blue shirt on a neon city street at night holding a card reading LLAMA-SWAP, with the text Swap Models One Endpoint