llm-host/README.md
Neil Bantoc 1121c3f908 README: what to pick up on an NVIDIA box
All of this branch was written on Apple Silicon. Write down which parts are
unverified on vLLM (the second --served-model-name, which would stop the server
starting if vLLM rejects it), which are deliberately not wired there and why
(the reasoning chooser and the per-request table both depend on the MLX proxy,
and there is no proxy in front of vLLM), and which should just work but have
never run on that hardware.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-03 02:58:04 -08:00

15 KiB
Raw Blame History

llm-host

Turn a machine with a decent GPU into a local LLM server for coding agents like opencode. llm-host detects the hardware, picks the models (and the right build of each) that fit, installs the inference backend, and runs it as a background service with a web dashboard.

  • Linux + NVIDIA → vLLM
  • macOS on Apple Silicon → MLX, behind a small proxy that adds API keys

Either way you get the same OpenAI-compatible API (with an API key) on port 1134 and a dashboard on port 11340. Everything installs into your home directory; no sudo, Docker or system CUDA toolkit needed.

Install

On the machine that will run the models:

/bin/bash -c "$(curl -fsSL https://git.neilbantoc.dev/pub/llm-host/raw/branch/main/install.sh)"

It shows the plan (which models fit, which build, how much context) and asks before installing. Pass setup options after --:

/bin/bash -c "$(curl -fsSL https://git.neilbantoc.dev/pub/llm-host/raw/branch/main/install.sh)" -- --yes --default ornith-1.5-35b

Ports: the API defaults to 1134 and the dashboard to 11340. On a first install a busy default moves to the next free port; after that the ports are saved and never move on their own (clients are configured with them). Change them with llmhost setup --api-port <port> --web-port <port>. On a Mac, MLX also uses the API port + 1.

Preview what a machine would get without installing anything (needs only Python 3.11+):

git clone https://git.neilbantoc.dev/pub/llm-host.git && cd llm-host
PYTHONPATH=. python3 -P -m llmhost plan                       # this machine
PYTHONPATH=. python3 -P -m llmhost plan --simulate nvidia:24:8.9   # an RTX 4090
PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64        # a 64 GB Mac

Use

Command
llmhost status service state and URLs
llmhost models models that fit this machine (* = active)
llmhost switch <model> serve a different model (downloads it first if needed)
llmhost download <model> download ahead of time
llmhost watch download and loading progress, until the model is ready
llmhost logs -f follow the model server log
llmhost start / stop / restart control the model server (stop frees the GPU)
llmhost key print the API key
llmhost opencode-setup install opencode here if needed and connect it to this server
llmhost opencode-config print what to add to opencode on another machine
llmhost opencode-remove take llm-host back out of this machine's opencode config (--host for a retired remote server, --all for every one)
llmhost update pull the latest llm-host and re-plan (--backend also upgrades vLLM/MLX)
llmhost uninstall [--purge] [--models] [--keep-key] remove services, backends and this machine's opencode provider; asks before deleting downloaded models (--models deletes without asking). --purge --keep-key keeps the API key so a reinstall reuses it

The dashboard (http://<host>.local:11340) shows the active model, throughput, KV cache, GPU utilization, temperature and power with 10-minute charts, the server log, and buttons to switch models or stop the server.

Connecting opencode

On the server itself, setup handles it: if opencode isn't installed it offers to install it (official installer, into ~/.opencode/bin), then adds an llmhost provider to ~/.config/opencode/opencode.json pointing at http://localhost:<api port>/v1 and reading the key straight from llm-host's key file. It shows up in opencode as LLMHost (Local). Other providers and your default model are left alone; the first change backs the file up as opencode.json.before-llmhost. llmhost update keeps the provider's port and model list in sync. Run it on demand with llmhost opencode-setup (--yes to install without asking); skip it during setup with --no-opencode, or install without asking with --opencode. A config with comments (.jsonc) is never rewritten, since that would drop them; setup prints the block to paste instead.

On another machine, run llmhost opencode-config on the server. It prints a provider block and a one-liner that copies the API key over. That block is named LLMHost (<the server's hostname>) — e.g. LLMHost (popos.local) — under the provider id llmhost-<shorthost>.

One opencode, several servers

The two paths use different provider ids, so a single opencode config can point at a local server and any number of remote ones at once, each named after the machine it reaches:

provider id shows up as API key
local llmhost LLMHost (Local) read straight from ~/.config/llm-host/api_key
remote llmhost-<shorthost> LLMHost (<host>) copied to ~/.config/opencode/llmhost-<shorthost>.key

Each provider offers a single model, default, rather than every model that fits. One model is loaded at a time, so a list of them would be a menu of one entry that works and the rest answering 404 model_not_found — and naming the loaded model would break the client's saved default on the next llmhost switch. default is a name the API also answers to, so llmhost/default keeps working across switches: vLLM takes it as a second --served-model-name (and still reports the real slug, being the first), and on a Mac the proxy accepts it as an alias. The local entry is labelled with whatever is loaded — Default model · Qwen3.8 27B (Local) — and llmhost switch, the dashboard and llmhost update keep that label current. A config that still points at a specific model (llmhost/qwen3.8-27b) is migrated to llmhost/default the next time llm-host writes the block.

To serve a different model, switch the server: llmhost switch <name> or the dashboard. Clients don't choose.

Which block belongs to this machine is decided by the key-file reference it carries, not by its name. So the provider is still recognised after you rename it, a remote provider that happens to sit under the llmhost id is never overwritten (setup takes llmhost-local instead and says so), and uninstall removes only the local provider — remote ones, and providers llm-host didn't create, are left in place. If a provider's default model goes away with it, model is repointed at a surviving llm-host provider, and dropped only if there is none.

Retiring a server is the one thing the servers can't do for each other: uninstalling on popos can't reach the clients pointing at it. On each client, run llmhost opencode-remove --host popos.local (or delete the block by hand if llm-host isn't installed there).

If opencode keeps asking for the API key

opencode caches a provider's key in its own credential store, ~/.local/share/opencode/auth.json, and that copy wins over opencode.json: when it is stale, opencode fails auth without even sending a request and asks for the key interactively. llm-host mints a fresh key whenever the config dir is purged, so a cached copy goes stale on every uninstall --purge + reinstall.

Setup therefore deletes the cached entry for its own provider each time it runs, leaving the {file:...} reference in opencode.json authoritative — that tracks the key file, so it can't go stale. Other providers' credentials in that file are never touched. If you hit this on a client machine, delete the provider's entry from auth.json and let it read the key file again.

To avoid invalidating remote clients in the first place, purge with --keep-key:

llmhost uninstall --purge --keep-key    # keeps ~/.config/llm-host/api_key; a reinstall reuses it

Reasoning effort

Reasoning effort is not a backend flag — it's a chat-template argument, read per request, and what it accepts differs per model. Qwen3.8 27B's template takes enable_thinking plus reasoning_effort in low/medium/xhigh (note: no high) and raises on anything else; Ornith 1.5 9B takes only enable_thinking. So the dashboard builds the chooser from the loaded model's own template, with the level names from catalog.json ("effort": {"levels": [...]}) — a level the template doesn't know is never offered or sent.

The setting is a default for requests that don't ask for anything: the proxy adds it to chat completions, and a chat_template_kwargs key the client sets itself always wins. Changing it takes effect on the next request with no reload, so the model stays in memory.

On Linux + NVIDIA there's no chooser: vLLM runs without a proxy in front, so nothing is in the path to add the argument. Clients can still pass chat_template_kwargs themselves.

How models are chosen

llmhost/catalog.json lists each model with every build of it (FP8, BF16, NVFP4, AWQ, MLX 8/6/4-bit), its size, and its KV-cache cost per token (measured on real hardware). For each model, llm-host tries builds in preference order and keeps the first that fits:

weights + ~3 GiB overhead + KV cache for 32k tokens  ≤  usable GPU memory
  • NVIDIA: usable = VRAM × 0.90 (0.95 if needed), summed over GPUs with tensor parallelism. Builds are filtered by compute capability (NVFP4 needs Blackwell; FP8 and BF16 need Ampere or newer). vLLM then sizes the context window to the memory that's actually left (--max-model-len -1).
  • Apple Silicon: usable = the GPU's share of unified memory (macOS allows ~67–75% by default, or iogpu.wired_limit_mb if you've raised it). MLX keeps an fp16 KV cache, so it's counted double.

--prefer changes the order: balanced (default: FP8 on NVIDIA, 6-bit on Mac), quality (BF16 / 8-bit), or speed (NVFP4 / 4-bit).

To add a model: add an entry to catalog.json (copy an existing one; vLLM flags such as the tool-call and reasoning parsers come from the model card or the vLLM recipes), then run python3 tools/refresh_catalog.py --write to fill in sizes, and llmhost update on each server.

What setup does on Linux + NVIDIA

These avoid problems that come up on a fresh desktop install without sudo:

  • vLLM goes in its own venv built on uv's Python (distro Pythons often lack the headers Triton needs).
  • vLLM compiles some GPU kernels at startup and needs nvcc. Setup installs the CUDA compiler from pip, pinned to the CUDA version torch was built for, and assembles a CUDA toolkit directory from the pip wheels.
  • Kernel builds are limited to one compile job per ~12 GB of RAM (unlimited builds can exhaust memory).
  • loginctl enable-linger keeps the services running when you're logged out (and starts them at boot).

Tests

Stdlib only, no test dependencies, and nothing touches a real install — every suite redirects LLMHOST_HOME, LLMHOST_CONFIG and XDG_* into a temp dir, and tests/harness.py aborts the run if any path llmhost could write to resolves outside it.

python3 tests/run.py              # every suite
python3 tests/run.py proxy        # just the ones matching "proxy"
python3 tests/test_opencode.py    # or run one directly
tests/test_opencode.py provider naming and ownership, removal, the credential cache
tests/test_proxy.py the API refusing a model that isn't loaded, against a fake mlx_lm
tests/test_dashboard.py KV parsing, per-run summaries, log collapsing
tests/test_reasoning.py effort options matching the real chat templates

Continuing on an NVIDIA box

Everything in this branch was written and tested on Apple Silicon + MLX. The parts below are either unverified on vLLM or deliberately not wired there, so start here when you check the repo out on the Linux machine. python3 tests/run.py passes on either platform (the suites are hermetic and don't need a GPU), so run that first to confirm nothing is broken.

Verify first — it can stop the server from starting:

  • --served-model-name <slug> default (plan.vllm_args). vLLM documents multiple names ("the server will respond to any of them", with the first reported back), and the CLI form is one flag with several tokens. Not run against a real vLLM, though, so confirm vllm serve accepts it and that curl -H "Authorization: Bearer $(llmhost key)" .../v1/chat/completions -d '{"model":"default",...}' answers. Until that's confirmed, the llmhost-<host>/default block that llmhost opencode-config prints can't work from a client.
  • /v1/models should still report the real slug, not default. If it reports default, the dashboard's readiness check (active in served) will sit on "loading" forever.

Not wired on vLLM, by design — each needs a decision, not a bug fix:

  • Reasoning chooser. The setting is injected per request by the MLX proxy, and llm-host runs vLLM with nothing in front of it, so there's nowhere to inject. Either put a proxy on Linux too (it would also bring the per-request table and the API-key handling into one place) or find a vLLM flag for default chat-template kwargs. The dashboard hides the panel rather than offer a control that does nothing.
  • Completed-requests table. Same reason: the per-request timings come from the proxy. vLLM exposes histograms on /metrics rather than per-request rows, so this would be a different implementation, not a port.
  • 404 model_not_found for a model that isn't loaded. That's the proxy. On vLLM the two served names both answer and anything else gets vLLM's own 404, which is the same outcome by a different route — worth confirming the message is clear enough.

Should work, but has never run on this hardware:

  • GPU temperature and power come from nvidia-smi, so the charts the dashboard hides on a Mac should appear here. Check that the hasTP test in index.html doesn't hide them wrongly.
  • KV cache on vLLM comes from vllm:kv_cache_usage_perc and predates this branch; the new log-parsing path is MLX-only.
  • llmhost opencode-remove, the opencode credential-cache clearing, and uninstall --purge --keep-key are all platform-independent, but worth one smoke test each.

Files

Path
~/.local/bin/llmhost launcher
~/.local/share/llm-host/ this repo (src/), backend venvs, the assembled CUDA toolkit
~/.config/llm-host/config.json the plan: backend, fitting models, active model, ports
~/.config/llm-host/api_key API key (mode 600)
~/.cache/huggingface/hub/ downloaded models
Linux: ~/.config/systemd/user/llm-host-{model,web}.service services (journalctl --user -u llm-host-model)
macOS: ~/Library/LaunchAgents/dev.llm-host.{model,web}.plist services; logs in ~/Library/Logs/llm-host/

On macOS the services are launchd agents, so they run while you're logged in.

Limitations

  • One model loaded at a time. Asking the API for a different one returns 404 model_not_found naming the loaded model, rather than answering with it.
  • AMD (ROCm), Intel and CPU-only machines aren't supported yet.
  • The API and dashboard use plain HTTP and are meant for a trusted LAN. Don't expose them to the internet.