{"id":17222339,"url":"https://github.com/mostlygeek/llama-swap","last_synced_at":"2026-05-16T01:06:45.966Z","repository":{"id":257826603,"uuid":"867433720","full_name":"mostlygeek/llama-swap","owner":"mostlygeek","description":"Model swapping for llama.cpp (or any local OpenAPI compatible server)","archived":false,"fork":false,"pushed_at":"2025-04-07T19:37:18.000Z","size":552,"stargazers_count":507,"open_issues_count":5,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-11T23:19:14.020Z","etag":null,"topics":["golang","llama","llamacpp","localllama","localllm","openai","openai-api","vllm"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mostlygeek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-04T04:06:01.000Z","updated_at":"2025-04-11T09:57:58.000Z","dependencies_parsed_at":"2024-10-31T19:19:45.783Z","dependency_job_id":"d90ad8bb-f11b-4c5e-9456-46ac274cb752","html_url":"https://github.com/mostlygeek/llama-swap","commit_stats":{"total_commits":36,"total_committers":1,"mean_commits":36.0,"dds":0.0,"last_synced_commit":"5944a86e8656334611c7e75fd428004c10f3a1d7"},"previous_names":["mostlygeek/llama-swap"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mostlygeek%2Fllama-swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mostlygeek%2Fllama-swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mostlygeek%2Fllama-swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mostlygeek%2Fllama-swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mostlygeek","download_url":"https://codeload.github.com/mostlygeek/llama-swap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492886,"owners_count":21113163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","llama","llamacpp","localllama","localllm","openai","openai-api","vllm"],"created_at":"2024-10-15T04:01:55.228Z","updated_at":"2026-05-16T01:06:45.959Z","avatar_url":"https://github.com/mostlygeek.png","language":"Go","funding_links":[],"categories":["\u003cimg src=\"./assets/satellite.svg\" width=\"16\" height=\"16\" style=\"vertical-align: middle;\"\u003e Satellites","Go","golang","openai","Langchain","Agentic AI ![](https://img.shields.io/badge/_-AGENTIC-22d3ee?style=flat-square\u0026logo=openai\u0026logoColor=white)","12. Miscellaneous","Tools","Inference Runtimes \u0026 Backends","3. Inference Engines \u0026 Serving","A01_文本生成_文本对话"],"sub_categories":["Local LLM runtimes","Data \u0026 Alignment Tools","Models","大语言对话模型及数据"],"readme":"![llama-swap header image](docs/assets/hero3.webp)\n![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/mostlygeek/llama-swap/total)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mostlygeek/llama-swap/go-ci.yml)\n![GitHub Repo stars](https://img.shields.io/github/stars/mostlygeek/llama-swap)\n\n# llama-swap\n\nRun multiple generative AI models on your machine and hot-swap between them on demand. llama-swap works with any OpenAI and Anthropic API compatible server and is used by thousands of people to power their local AI workflows.\n\nBuilt in Go for performance and simplicity, llama-swap has zero dependencies and is incredibly easy to set up. Get started in minutes - just one binary and one configuration file.\n\n## Features:\n\n- ✅ Easy to deploy and configure: one binary, one configuration file. no external dependencies\n- ✅ On-demand model switching\n- ✅ Use any local OpenAI compatible server (llama.cpp, vllm, tabbyAPI, stable-diffusion.cpp, etc.)\n  - future proof, upgrade your inference servers at any time.\n- ✅ OpenAI API supported endpoints:\n  - `v1/completions`\n  - `v1/chat/completions`\n  - `v1/responses`\n  - `v1/embeddings`\n  - `v1/models` - list available models\n  - `v1/audio/speech` ([#36](https://github.com/mostlygeek/llama-swap/issues/36))\n  - `v1/audio/transcriptions` ([docs](https://github.com/mostlygeek/llama-swap/issues/41#issuecomment-2722637867))\n  - `v1/audio/voices`\n  - `v1/images/generations`\n  - `v1/images/edits`\n- ✅ Anthropic API supported endpoints:\n  - `v1/messages`\n  - `v1/messages/count_tokens`\n- ✅ llama-server (llama.cpp) supported endpoints\n  - `v1/rerank`, `v1/reranking`, `/rerank`\n  - `/infill` - for code infilling\n  - `/completion` - for completion endpoint\n- ✅ SDAPI via [stable-diffusion.cpp's server](https://github.com/leejet/stable-diffusion.cpp/tree/master/examples/server)\n  - `/sdapi/v1/txt2img`\n  - `/sdapi/v1/img2img`\n  - `/sdapi/v1/loras` - requires `model` in request body to fetch the correct loras\n- ✅ llama-swap API\n  - `/ui` - web UI\n  - `/upstream/:model_id` - direct access to upstream server ([demo](https://github.com/mostlygeek/llama-swap/pull/31))\n  - `/running` - list currently running models ([#61](https://github.com/mostlygeek/llama-swap/issues/61))\n  - `POST /api/models/unload` - manually unload all running models ([#58](https://github.com/mostlygeek/llama-swap/issues/58))\n  - `POST /api/models/unload/:model_id` - unload a specific model\n  - `/logs` - remote log monitoring\n    - `GET /logs` returns buffered plain text logs.\n      - If `Accept: text/html` is sent, `/logs` redirects to `/ui/`.\n    - `GET /logs/stream` keeps the connection open for live log streaming.\n      - Stream endpoints send buffered history first by default; add `?no-history` to stream only new lines.\n    - `GET /logs/stream/proxy` streams proxy logs only.\n    - `GET /logs/stream/upstream` streams upstream process logs only.\n    - `GET /logs/stream/{model_id}` streams logs for one model (including IDs with slashes, like `author/model`).\n  - `/health` - just returns \"OK\"\n  - `/metrics` - system and GPU metrics for prometheus\n- ✅ API Key support - define keys to restrict access to API endpoints\n- ✅ Customizable\n  - Run concurrent models with a custom DSL swap matrix ([#643](https://github.com/mostlygeek/llama-swap/issues/643))\n  - Automatic unloading of models after timeout by setting a `ttl`\n  - Docker and Podman support using `cmd` and `cmdStop` together\n  - Preload models on startup with `hooks` ([#235](https://github.com/mostlygeek/llama-swap/pull/235))\n  - Apply filters to requests to control inference with `stripParams`, `setParams` and `setParamsByID`\n\n### Web UI\n\nllama-swap includes a real time web interface with a playground for testing out all sorts of local models:\n\n\u003cimg width=\"1125\" height=\"876\" alt=\"image\" src=\"https://github.com/user-attachments/assets/8ee41947-97af-463d-b0f0-8e9c478fac07\" /\u003e\n\nView detailed token metrics:\n\n\u003cimg width=\"1111\" height=\"515\" alt=\"image\" src=\"https://github.com/user-attachments/assets/64bfb280-d7a3-4126-971a-a128fd40410c\" /\u003e\n\nInspect request and responses:\n\n\u003cimg width=\"1111\" height=\"720\" alt=\"image\" src=\"https://github.com/user-attachments/assets/24fe4aca-1448-4d7c-b9e8-a967589bda6c\" /\u003e\n\nManually load and unload models:\n\n\u003cimg width=\"1109\" height=\"719\" alt=\"image\" src=\"https://github.com/user-attachments/assets/02b1e1f2-abd0-4050-84ae-facd66ff01c4\" /\u003e\n\nReal time log streaming:\n\n\u003cimg width=\"1107\" height=\"559\" alt=\"image\" src=\"https://github.com/user-attachments/assets/39669a10-cff2-409e-836a-5bad8bd0140c\" /\u003e\n\n## Installation\n\nllama-swap can be installed in multiple ways\n\n1. Docker\n2. Homebrew (OSX and Linux)\n3. WinGet\n4. From release binaries\n5. From source\n\n### Docker Install ([download images](https://github.com/mostlygeek/llama-swap/pkgs/container/llama-swap))\n\nTwo types of container images are built nightly for llama-swap:\n\n1. A unified container with llama-server, ik-llama-server, stable-diffusion.cpp, whisper.cpp and llama-swap built from source. This is only available for cuda and vulkan but has more capabilities. This one is recommended for use.\n2. A legacy image that is based on llama.cpp's images and llama-swap copied into the container. Use this one if you prefer to stay close to llama.cpp's container images.\n\n#### Unified container (Recommended)\n\n```shell\n$ docker pull ghcr.io/mostlygeek/llama-swap:unified-cuda\n\n# run with a custom configuration and models directory\n$ docker run -it --rm --runtime nvidia -p 9292:8080 \\\n -v /path/to/models:/models \\\n -v /path/to/custom/config.yaml:/etc/llama-swap/config/config.yaml \\\n ghcr.io/mostlygeek/llama-swap:unified-cuda\n```\n\n#### Legacy container\n\n```shell\n$ docker pull ghcr.io/mostlygeek/llama-swap:cuda\n\n# run with a custom configuration and models directory\n$ docker run -it --rm --runtime nvidia -p 9292:8080 \\\n -v /path/to/models:/models \\\n -v /path/to/custom/config.yaml:/app/config.yaml \\\n ghcr.io/mostlygeek/llama-swap:cuda\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\nmore examples\n\u003c/summary\u003e\n\n```shell\n# pull latest images per platform\ndocker pull ghcr.io/mostlygeek/llama-swap:cpu\ndocker pull ghcr.io/mostlygeek/llama-swap:cuda\ndocker pull ghcr.io/mostlygeek/llama-swap:vulkan\ndocker pull ghcr.io/mostlygeek/llama-swap:intel\ndocker pull ghcr.io/mostlygeek/llama-swap:musa\n\n# tagged llama-swap, platform and llama-server version images\ndocker pull ghcr.io/mostlygeek/llama-swap:v166-cuda-b6795\n\n# non-root cuda\ndocker pull ghcr.io/mostlygeek/llama-swap:cuda-non-root\n\n```\n\n\u003c/details\u003e\n\n### Homebrew Install (macOS/Linux)\n\n```shell\nbrew tap mostlygeek/llama-swap\nbrew install llama-swap\nllama-swap --config path/to/config.yaml --listen localhost:8080\n```\n\n### WinGet Install (Windows)\n\n\u003e [!NOTE]\n\u003e WinGet is maintained by community contributor [Dvd-Znf](https://github.com/Dvd-Znf) ([#327](https://github.com/mostlygeek/llama-swap/issues/327)). It is not an official part of llama-swap.\n\n```shell\n# install\nC:\\\u003e winget install llama-swap\n\n# upgrade\nC:\\\u003e winget upgrade llama-swap\n```\n\n### Pre-built Binaries\n\nBinaries are available on the [release](https://github.com/mostlygeek/llama-swap/releases) page for Linux, Mac, Windows and FreeBSD.\n\n### Building from source\n\n1. Building requires Go and Node.js (for UI).\n1. `git clone https://github.com/mostlygeek/llama-swap.git`\n1. `make clean all`\n1. look in the `build/` subdirectory for the llama-swap binary\n\n## Configuration\n\n```yaml\n# minimum viable config.yaml\n\nmodels:\n  model1:\n    cmd: llama-server --port ${PORT} --model /path/to/model.gguf\n```\n\nThat's all you need to get started:\n\n1. `models` - holds all model configurations\n2. `model1` - the ID used in API calls\n3. `cmd` - the command to run to start the server.\n4. `${PORT}` - an automatically assigned port number\n\nAlmost all configuration settings are optional and can be added one step at a time:\n\n- Advanced features\n  - `matrix` to run concurrent models with a custom swap logic DSL\n  - `hooks` to run things on startup\n  - `macros` reusable snippets\n- Model customization\n  - `ttl` to automatically unload models\n  - `aliases` to use familiar model names (e.g., \"gpt-4o-mini\")\n  - `env` to pass custom environment variables to inference servers\n  - `cmdStop` gracefully stop Docker/Podman containers\n  - `useModelName` to override model names sent to upstream servers\n  - `${PORT}` automatic port variables for dynamic port assignment\n  - `filters` rewrite parts of requests before sending to the upstream server\n\nSee the [configuration documentation](docs/configuration.md) for all options.\n\n## How does llama-swap work?\n\nWhen a request is made to an OpenAI compatible endpoint, llama-swap will extract the `model` value and load the appropriate server configuration to serve it. If the wrong upstream server is running, it will be replaced with the correct one. This is where the \"swap\" part comes in. The upstream server is automatically swapped to handle the request correctly.\n\nIn the most basic configuration llama-swap handles one model at a time. For more advanced use cases, using a `matrix` allows multiple models to be loaded at the same time. You have complete control over how your system resources are used.\n\n## Reverse Proxy Configuration (nginx)\n\nIf you deploy llama-swap behind nginx, disable response buffering for streaming endpoints. By default, nginx buffers responses which breaks Server‑Sent Events (SSE) and streaming chat completion. ([#236](https://github.com/mostlygeek/llama-swap/issues/236))\n\nRecommended nginx configuration snippets:\n\n```nginx\n# SSE for UI events/logs\nlocation /api/events {\n    proxy_pass http://your-llama-swap-backend;\n    proxy_buffering off;\n    proxy_cache off;\n}\n\n# Streaming chat completions (stream=true)\nlocation /v1/chat/completions {\n    proxy_pass http://your-llama-swap-backend;\n    proxy_buffering off;\n    proxy_cache off;\n}\n```\n\nAs a safeguard, llama-swap also sets `X-Accel-Buffering: no` on SSE responses. However, explicitly disabling `proxy_buffering` at your reverse proxy is still recommended for reliable streaming behavior.\n\n## Monitoring Logs on the CLI\n\n```sh\n# sends up to the last 10KB of logs\n$ curl http://host/logs\n\n# streams combined logs\ncurl -Ns http://host/logs/stream\n\n# stream llama-swap's proxy status logs\ncurl -Ns http://host/logs/stream/proxy\n\n# stream logs from upstream processes that llama-swap loads\ncurl -Ns http://host/logs/stream/upstream\n\n# stream logs only from a specific model\ncurl -Ns http://host/logs/stream/{model_id}\n\n# stream and filter logs with linux pipes\ncurl -Ns http://host/logs/stream | grep 'eval time'\n\n# appending ?no-history will disable sending buffered history first\ncurl -Ns 'http://host/logs/stream?no-history'\n```\n\n## Do I need to use llama.cpp's server (llama-server)?\n\nAny OpenAI compatible server would work. llama-swap was originally designed for llama-server and it is the best supported.\n\nFor Python based inference servers like vllm or tabbyAPI it is recommended to run them via podman or docker. This provides clean environment isolation as well as responding correctly to `SIGTERM` signals for proper shutdown.\n\n## Star History\n\n\u003e [!NOTE]\n\u003e Thank you to everyone who has given this project a ⭐️!\n\n[![Star History Chart](https://api.star-history.com/svg?repos=mostlygeek/llama-swap\u0026type=Date)](https://www.star-history.com/#mostlygeek/llama-swap\u0026Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmostlygeek%2Fllama-swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmostlygeek%2Fllama-swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmostlygeek%2Fllama-swap/lists"}