opencode: clear the cached key, and let --purge keep the API key

opencode caches a provider's key in ~/.local/share/opencode/auth.json and that
copy wins over opencode.json: with a stale entry it fails auth without sending
a request at all and asks for the key interactively. Verified by A/B on a live
install -- correct entry works, wrong entry never reaches the server, absent
entry works and reads the key file.

llm-host mints a fresh key whenever the config dir is purged, so the cached
copy went stale on every reinstall. configure() now drops the entry for its own
provider, leaving the {file:...} reference authoritative; it tracks the key file
and cannot go stale. remove() takes the cached key with the provider. Other
providers' credentials are never touched, and an unreadable store is left alone
rather than repaired.

Add `uninstall --purge --keep-key` so the key survives a purge and a reinstall
reuses it -- clients elsewhere then keep working. Warn about the new key when
it doesn't. Factor the purge into purge() so it can be tested without touching
a real install.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 00:19:54 -08:00
parent 13a7def080
commit 8c6615dbb4
3 changed files with 101 additions and 11 deletions

View file

@ -54,7 +54,7 @@ PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64 # a 64 GB Mac
| `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]` | remove services, backends and this machine's opencode provider; asks before deleting downloaded models (`--models` deletes without asking) |
| `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.
@ -95,6 +95,24 @@ Retiring a server is the one thing the servers can't do for each other: uninstal
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`:
```bash
llmhost uninstall --purge --keep-key # keeps ~/.config/llm-host/api_key; a reinstall reuses it
```
## How models are chosen
`llmhost/catalog.json` lists each model with every build of it (FP8, BF16, NVFP4, AWQ, MLX 8/6/4-bit),