Auto-discover models from local OpenAI-compatible API endpoints for OpenCode.
- Auto-discovers models from local endpoints (Ollama, LM Studio, LLM proxies)
- Fetches metadata from Models.dev and OpenRouter (context window, capabilities, cost)
- Caches metadata locally (24h TTL)
- Supports multiple endpoints
- API key authentication via config or environment variables
- Model filtering with include/exclude patterns
opencode plugin opencode-autodiscoverOr install globally:
opencode plugin opencode-autodiscover -gThe v2 plugin (OpenCode v2 / beta plugin API) publishes under the
nextnpm tag:opencode plugin opencode-autodiscover@next. Thelatesttag still tracks the v1 plugin for stable OpenCode.
opencode plugin opencode-autodiscover # Install to project config
opencode plugin opencode-autodiscover -g # Install to global config
opencode plugin opencode-autodiscover -f # Force update existing plugin
opencode plugin opencode-autodiscover --pure # Run without external plugins
- On startup, the plugin reads
options.endpointsfrom its plugin config - Fetches available models from each endpoint (
/v1/models) - Looks up metadata from Models.dev and OpenRouter (context window, cost, capabilities)
- Registers the discovered providers and models in the OpenCode catalog via a catalog transform
- Models appear in the
/modelsUI natively; therefresh-local-modelstool replays the transform live
Metadata lookups are cached to keep startup fast:
- OpenRouter catalog — written to
openrouter.jsonunder~/.cache/opencode-autodiscover/(24h TTL). Override the location with theOPENCODE_AUTODISCOVER_CACHE_DIRenvironment variable. - Models.dev — loaded in memory per process from the bundled
models-dev-dbpackage; rebuilt on each startup.
Use the refresh-local-models tool to clear both caches and re-fetch — the catalog is updated immediately, no restart needed.
Add the plugin to the plugins array in your opencode.jsonc, listing each local endpoint under options.endpoints:
Each endpoint supports:
id(required) — provider id used in the catalog (e.g.local-ollama)baseURL(required) — base URL of the OpenAI-compatible APIname— display name for the providerapiKey— API key sent to the endpointheaders— extra HTTP headers sent with requestsinclude/exclude— model filtering patterns (see below)
API keys can be set via environment variables instead of apiKey:
export OPENCODE_LOCAL_MY_PROXY_API_KEY=sk-your-keyThe variable name is derived from the endpoint id: OPENCODE_LOCAL_ + the id uppercased with - replaced by _.
Control which models are discovered using include and exclude glob patterns on an endpoint:
{
"$schema": "https://opencode.ai/config.json",
"plugins": [
{
"package": "opencode-autodiscover",
"options": {
"endpoints": [
{
"id": "local-ollama",
"baseURL": "http://localhost:11434/v1",
"include": ["qwen/*"],
"exclude": ["*embedding*", "*test*"],
},
],
},
},
],
}include— if set, only models matching at least one pattern are discoveredexclude— models matching any pattern are skipped (applied afterinclude)*matches anything (including/)- Matching is case-insensitive
- Special characters (
.,[,], etc.) are treated as literals
Models are auto-discovered at startup and appear in /models natively.
To refresh models, use the refresh-local-models tool in OpenCode — the catalog is replayed immediately, no restart needed.
npm install
npm test
npm run buildMIT
{ "$schema": "https://opencode.ai/config.json", "plugins": [ { "package": "opencode-autodiscover", "options": { "endpoints": [ { "id": "local-ollama", "name": "Ollama", "baseURL": "http://localhost:11434/v1", }, { "id": "local-lmstudio", "name": "LM Studio", "baseURL": "http://localhost:1234/v1", }, ], }, }, ], }