Skip to content
FossShelf
Home / Categories / For AI Engineers

llama-swap

Hot-swap AI models on your local inference server

Replaces Lm Studio

6.26K starsMITreviewed 4 Sept 2026last commit 15 Nov 2026
Screenshot of llama-swap

Who it's for

AI developers iterating across multiple local models

A developer might use a small coding model for inline suggestions, a larger chat model for reasoning tasks, and an embedding model for RAG. llama-swap lets all three share the same API endpoint and GPU, swapping between them on request rather than requiring manual process management.

If you only ever use one model at a time with no plans to switch, the overhead of a proxy layer adds no value. A direct connection to the inference server is simpler.

Teams building privacy-sensitive AI applications

Organizations that cannot send data to cloud inference APIs due to compliance requirements, confidentiality agreements, or internal policy use llama-swap to run model serving entirely on their own infrastructure. The OpenAI-compatible API means existing tooling connects without modification.

If your use case allows cloud inference and you need managed uptime, dedicated hosted services handle scaling and reliability in ways a self-hosted proxy does not.

Researchers comparing model variants on the same prompts

Research workflows often involve running the same prompt across several checkpoint variants or model families to compare outputs. llama-swap's profile switching and per-model aliases let researchers swap between variants via config, with model IDs remapped through the `aliases` field.

If your inference workload requires simultaneous parallel evaluation of many models, the default single-model-at-a-time mode will not fit. The `matrix` feature extends this, but it requires adequate hardware resources for all loaded models.

Home lab users consolidating AI tooling behind one endpoint

A home server running llama.cpp, stable-diffusion.cpp, and a Whisper-based transcription server can be unified behind a single API endpoint with llama-swap. TTL-based auto-unloading means GPU memory is freed when models are idle, which matters on machines with limited VRAM.

If your machine has enough GPU memory to run all models simultaneously without swapping, a simple reverse proxy over multiple model servers may be easier to maintain than a dedicated model manager.

The problem

Running more than one local AI model on a single machine requires managing separate server processes, separate ports, and separate startup sequences. llama.cpp, vllm, stable-diffusion.cpp, and similar inference engines each need their own process lifecycle. Switching models means stopping one server, waiting for it to shut down cleanly, and starting another. For developers iterating across a coding assistant, a chat model, and an embedding model in the same session, this back-and-forth is a constant interruption. The deeper issue is memory. Most local inference servers load model weights into GPU or system memory when they start. Running two simultaneously means doubling the memory footprint, which most consumer hardware cannot sustain. The only practical option has been to pick one model per session and stick with it, which limits what local AI workflows can accomplish.

How it works

On-demand model swapping

llama-swap reads the `model` field in every incoming API request and starts the matching inference server automatically if it is not already running. When a new model is requested, it stops the current server and starts the correct one. No client-side configuration change is needed: the same API call that works with a managed service works unchanged.

OpenAI and Anthropic API compatibility

Exposes the full OpenAI v1 endpoint set including chat completions, completions, embeddings, audio speech, audio transcriptions, image generation, and image editing. Also supports Anthropic's messages API and token-counting endpoint. Any client that speaks either API connects to llama-swap without modification.

Web UI with playground and live metrics

A built-in browser interface provides a model playground for testing prompts, real-time token metrics, request and response inspection, and live log streaming. Models can be loaded and unloaded manually from the UI. The Playground also includes a Docs tab backed by an MCP endpoint that answers configuration questions using the local knowledge base.

Multi-backend support

Works with llama.cpp, vllm, stable-diffusion.cpp, ComfyUI, audio.cpp, and any other OpenAI-compatible server. The `cmd` field in the config file defines how each model's server starts, which means any inference engine with a compatible API is supported without code changes to llama-swap itself.

Concurrent models via matrix DSL

A `matrix` configuration block lets you define which models can run simultaneously and how they share GPU resources. The default is one model at a time; the matrix adds a custom swap logic layer for workloads that need more than one model loaded concurrently.

TTL-based auto-unloading and request filters

Setting a `ttl` on any model causes llama-swap to unload its server after the specified idle period, freeing GPU memory automatically. The `stripParams`, `setParams`, and `setParamsByID` filter options rewrite parts of requests before forwarding them upstream, letting you normalize inference parameters across backends.

Features

  • On-demand model swapping
  • OpenAI and Anthropic API compatibility
  • Web UI with playground and live metrics
  • Multi-backend support
  • Concurrent models via matrix DSL
  • TTL-based auto-unloading and request filters

How to install

Install llama-swap with Homebrew on macOS or Linux, then point it at a config file.

brew tap mostlygeek/llama-swap
brew install llama-swap
llama-swap --config config.yaml --listen localhost:8080

Recommended for this setup

Strengths

  • Single binary, zero external dependencies: The entire proxy ships as a pre-compiled Go binary. There is no runtime to install, no language environment to configure, and no package manager to satisfy. Download the binary, write a YAML config file with a single required key, and run. This is the lowest-friction self-hosted infrastructure setup in the local LLM ecosystem.
  • MIT license with no commercial restrictions: MIT means you can run llama-swap in commercial products, modify it, and redistribute it without paying licensing fees or agreeing to usage-based terms. Unlike some LLMOps tools that carry AGPL or proprietary licenses, llama-swap imposes no constraints on how you build on top of it.
  • Drop-in API compatibility for any OpenAI client: Because llama-swap presents a standard OpenAI/Anthropic API surface, every downstream tool (IDE plugins, chatbot UIs, code assistants, RAG frameworks) connects without modification. Switching the underlying model or inference engine is an infrastructure change only; client code does not need to change.
  • Docker and Podman support with clean process lifecycle: Python-based inference servers like vllm and tabbyAPI benefit from container-based process management. llama-swap's `cmdStop` flag sends the correct signal to stop Docker or Podman containers cleanly, which avoids orphaned processes and GPU memory leaks between model swaps.

Trade-offs

  • Manual configuration required for every model: Every model must be declared in the YAML config file with the full command to start its server. There is no auto-discovery of models from a directory, no GUI to add models, and no connection to model registries. Teams with large model libraries need to maintain config file entries manually as they add or update models.
  • No built-in persistence or chat history: llama-swap is a proxy, not a frontend. It routes API requests and manages server processes but does not store conversation history, manage sessions, or provide a production chat interface. Users who need those features must add a separate layer (such as Open WebUI or Lobe Chat) on top of the proxy.
  • 87 open issues; edge cases may have known bugs: The project has accumulated bug reports and feature requests faster than they are resolved. Active maintenance is evident (last push within 24 hours of this writing), but less-common backends and advanced configurations may have known issues that have not yet been addressed. Check open issues before depending on a specific backend.

Tech stack

Languages
Go, Svelte, TypeScript, Shell, Python, CSS, Dockerfile, HTML, Makefile, Go Template, JavaScript
Frameworks
Svelte
Databases
—
Tooling
—

FAQ

Does llama-swap require llama.cpp specifically?

No. llama-swap works with any inference server that exposes an OpenAI or Anthropic-compatible API, including vllm, stable-diffusion.cpp, ComfyUI, and audio.cpp. llama.cpp (via llama-server) is the most tested backend, but the README explicitly states that "any OpenAI compatible server would work." The architecture is backend-agnostic by design.

How does llama-swap handle GPU memory when swapping models?

llama-swap stops the current inference server before starting the next one, which releases GPU memory from the first model before the second loads. The `ttl` config setting automates this: after a model goes idle for a specified duration, llama-swap unloads it automatically. The `matrix` feature allows keeping multiple models loaded simultaneously, but that requires enough GPU memory for all of them.

Can I use llama-swap with Docker containers?

Yes. The `cmd` config field accepts any shell command, including `docker run` or `podman run`. The `cmdStop` field handles graceful shutdown by sending the correct signal to the container. The project also publishes its own Docker images via GitHub Container Registry, including a unified image with llama-server, stable-diffusion.cpp, and Whisper pre-built, available in CPU, CUDA, Vulkan, and Intel variants.

Is llama-swap suitable for production use?

llama-swap is MIT licensed and described in the README as used by thousands of people. It ships as a binary with no external runtime dependencies, which simplifies deployment. However, it does not provide managed uptime, horizontal scaling, or load balancing across multiple machines. Teams running it in production typically pair it with a reverse proxy like nginx (the README includes nginx config snippets for streaming endpoints) and a process supervisor.

Does llama-swap support the Anthropic API format?

Yes. llama-swap proxies the Anthropic `v1/messages` and `v1/messages/count_tokens` endpoints to backends that support the Anthropic API format. The upstream server must accept Anthropic-format requests; llama-swap is format-transparent on those routes and does not translate between OpenAI and Anthropic formats.

Similar tools

More in AI Engineers